blob: ada15919a26066ff1efa22d2c4ddab9268ab4987 [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>
Tom Hudson2dc236b2014-10-15 15:46:42 -040023#include <utils/Functor.h>
John Reck3b202512014-06-23 13:13:08 -070024
25#include <private/hwui/DrawGlInfo.h>
26
John Reck3b202512014-06-23 13:13:08 -070027#include "utils/Macros.h"
28
29namespace android {
30namespace uirenderer {
31
Tom Hudson2dc236b2014-10-15 15:46:42 -040032class Caches;
33class Layer;
34
John Reck3b202512014-06-23 13:13:08 -070035namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070036class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070037class RenderThread;
38}
39
40// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
41// wrapper of Caches for users to migrate to.
42class RenderState {
43 PREVENT_COPY_AND_ASSIGN(RenderState);
44public:
45 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070046 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070047
48 void setViewport(GLsizei width, GLsizei height);
49 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
50
51 void bindFramebuffer(GLuint fbo);
52 GLint getFramebuffer() { return mFramebuffer; }
53
54 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
55
56 void debugOverdraw(bool enable, bool clear);
57
Chris Craik1d477422014-08-26 17:30:15 -070058 void registerLayer(const Layer* layer) {
59 mActiveLayers.insert(layer);
60 }
61 void unregisterLayer(const Layer* layer) {
62 mActiveLayers.erase(layer);
63 }
64
John Reck443a7142014-09-04 17:40:05 -070065 void registerCanvasContext(renderthread::CanvasContext* context) {
66 mRegisteredContexts.insert(context);
67 }
68
69 void unregisterCanvasContext(renderthread::CanvasContext* context) {
70 mRegisteredContexts.erase(context);
71 }
72
John Reck0e89e2b2014-10-31 14:49:06 -070073 void requireGLContext();
74
75 // TODO: This system is a little clunky feeling, this could use some
76 // more thinking...
77 void postDecStrong(VirtualLightRefBase* object);
78
John Reck3b202512014-06-23 13:13:08 -070079private:
80 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070081 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070082
83 void interruptForFunctorInvoke();
84 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070085 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070086
John Reck0e89e2b2014-10-31 14:49:06 -070087 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070088 ~RenderState();
89
John Reck0e89e2b2014-10-31 14:49:06 -070090 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -070091 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070092 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -070093 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -070094
95 GLsizei mViewportWidth;
96 GLsizei mViewportHeight;
97 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -070098
99 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700100};
101
102} /* namespace uirenderer */
103} /* namespace android */
104
105#endif /* RENDERSTATE_H */