blob: afeef950d5cd080cebe9363e044b15b772b999b1 [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef RENDERSTATE_H
17#define RENDERSTATE_H
18
Chris Craik1d477422014-08-26 17:30:15 -070019#include <set>
John Reck3b202512014-06-23 13:13:08 -070020#include <GLES2/gl2.h>
21#include <GLES2/gl2ext.h>
Chris Craik599e2542014-09-05 15:17:11 -070022#include <utils/Mutex.h>
John Reck3b202512014-06-23 13:13:08 -070023
24#include <private/hwui/DrawGlInfo.h>
25
26#include "Caches.h"
27#include "utils/Macros.h"
28
29namespace android {
30namespace uirenderer {
31
32namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070033class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070034class RenderThread;
35}
36
37// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
38// wrapper of Caches for users to migrate to.
39class RenderState {
40 PREVENT_COPY_AND_ASSIGN(RenderState);
41public:
42 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070043 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070044
45 void setViewport(GLsizei width, GLsizei height);
46 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
47
48 void bindFramebuffer(GLuint fbo);
49 GLint getFramebuffer() { return mFramebuffer; }
50
51 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
52
53 void debugOverdraw(bool enable, bool clear);
54
Chris Craik1d477422014-08-26 17:30:15 -070055 void registerLayer(const Layer* layer) {
56 mActiveLayers.insert(layer);
57 }
58 void unregisterLayer(const Layer* layer) {
59 mActiveLayers.erase(layer);
60 }
61
John Reck443a7142014-09-04 17:40:05 -070062 void registerCanvasContext(renderthread::CanvasContext* context) {
63 mRegisteredContexts.insert(context);
64 }
65
66 void unregisterCanvasContext(renderthread::CanvasContext* context) {
67 mRegisteredContexts.erase(context);
68 }
69
John Reck0e89e2b2014-10-31 14:49:06 -070070 void requireGLContext();
71
72 // TODO: This system is a little clunky feeling, this could use some
73 // more thinking...
74 void postDecStrong(VirtualLightRefBase* object);
75
John Reck3b202512014-06-23 13:13:08 -070076private:
77 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070078 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070079
80 void interruptForFunctorInvoke();
81 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070082 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070083
John Reck0e89e2b2014-10-31 14:49:06 -070084 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070085 ~RenderState();
86
John Reck0e89e2b2014-10-31 14:49:06 -070087 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -070088 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070089 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -070090 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -070091
92 GLsizei mViewportWidth;
93 GLsizei mViewportHeight;
94 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -070095
96 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -070097};
98
99} /* namespace uirenderer */
100} /* namespace android */
101
102#endif /* RENDERSTATE_H */