blob: aa39a3ae757bc8da2ae9e775abb9cee4881dff0d [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>
Nick Kralevichbfed8272014-11-01 18:37:39 -070024#include <utils/RefBase.h>
John Reck3b202512014-06-23 13:13:08 -070025
26#include <private/hwui/DrawGlInfo.h>
27
John Reck3b202512014-06-23 13:13:08 -070028#include "utils/Macros.h"
29
30namespace android {
31namespace uirenderer {
32
Tom Hudson2dc236b2014-10-15 15:46:42 -040033class Caches;
34class Layer;
35
John Reck3b202512014-06-23 13:13:08 -070036namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070037class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070038class RenderThread;
39}
40
41// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
42// wrapper of Caches for users to migrate to.
43class RenderState {
44 PREVENT_COPY_AND_ASSIGN(RenderState);
45public:
46 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070047 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070048
49 void setViewport(GLsizei width, GLsizei height);
50 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
51
52 void bindFramebuffer(GLuint fbo);
53 GLint getFramebuffer() { return mFramebuffer; }
54
55 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
56
57 void debugOverdraw(bool enable, bool clear);
58
Chris Craik1d477422014-08-26 17:30:15 -070059 void registerLayer(const Layer* layer) {
60 mActiveLayers.insert(layer);
61 }
62 void unregisterLayer(const Layer* layer) {
63 mActiveLayers.erase(layer);
64 }
65
John Reck443a7142014-09-04 17:40:05 -070066 void registerCanvasContext(renderthread::CanvasContext* context) {
67 mRegisteredContexts.insert(context);
68 }
69
70 void unregisterCanvasContext(renderthread::CanvasContext* context) {
71 mRegisteredContexts.erase(context);
72 }
73
John Reck0e89e2b2014-10-31 14:49:06 -070074 void requireGLContext();
75
76 // TODO: This system is a little clunky feeling, this could use some
77 // more thinking...
78 void postDecStrong(VirtualLightRefBase* object);
79
John Reck3b202512014-06-23 13:13:08 -070080private:
81 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070082 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070083
84 void interruptForFunctorInvoke();
85 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070086 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070087
John Reck0e89e2b2014-10-31 14:49:06 -070088 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070089 ~RenderState();
90
John Reck0e89e2b2014-10-31 14:49:06 -070091 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -070092 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070093 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -070094 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -070095
96 GLsizei mViewportWidth;
97 GLsizei mViewportHeight;
98 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -070099
100 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700101};
102
103} /* namespace uirenderer */
104} /* namespace android */
105
106#endif /* RENDERSTATE_H */