blob: c7ab197c4fb250df8778133382a634ef425b4a40 [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>
22
23#include <private/hwui/DrawGlInfo.h>
24
25#include "Caches.h"
26#include "utils/Macros.h"
27
28namespace android {
29namespace uirenderer {
30
31namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070032class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070033class RenderThread;
34}
35
36// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
37// wrapper of Caches for users to migrate to.
38class RenderState {
39 PREVENT_COPY_AND_ASSIGN(RenderState);
40public:
41 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070042 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070043
44 void setViewport(GLsizei width, GLsizei height);
45 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
46
47 void bindFramebuffer(GLuint fbo);
48 GLint getFramebuffer() { return mFramebuffer; }
49
50 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
51
52 void debugOverdraw(bool enable, bool clear);
53
Chris Craik1d477422014-08-26 17:30:15 -070054 void registerLayer(const Layer* layer) {
55 mActiveLayers.insert(layer);
56 }
57 void unregisterLayer(const Layer* layer) {
58 mActiveLayers.erase(layer);
59 }
60
John Reck443a7142014-09-04 17:40:05 -070061 void registerCanvasContext(renderthread::CanvasContext* context) {
62 mRegisteredContexts.insert(context);
63 }
64
65 void unregisterCanvasContext(renderthread::CanvasContext* context) {
66 mRegisteredContexts.erase(context);
67 }
68
John Reck3b202512014-06-23 13:13:08 -070069private:
70 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070071 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070072
73 void interruptForFunctorInvoke();
74 void resumeFromFunctorInvoke();
75
76 RenderState();
77 ~RenderState();
78
79 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070080 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -070081 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -070082
83 GLsizei mViewportWidth;
84 GLsizei mViewportHeight;
85 GLuint mFramebuffer;
86};
87
88} /* namespace uirenderer */
89} /* namespace android */
90
91#endif /* RENDERSTATE_H */