blob: cd71c732914353e0e27371403331471b1c877c00 [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 {
32class RenderThread;
33}
34
35// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
36// wrapper of Caches for users to migrate to.
37class RenderState {
38 PREVENT_COPY_AND_ASSIGN(RenderState);
39public:
40 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070041 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070042
43 void setViewport(GLsizei width, GLsizei height);
44 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
45
46 void bindFramebuffer(GLuint fbo);
47 GLint getFramebuffer() { return mFramebuffer; }
48
49 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
50
51 void debugOverdraw(bool enable, bool clear);
52
Chris Craik1d477422014-08-26 17:30:15 -070053 void registerLayer(const Layer* layer) {
54 mActiveLayers.insert(layer);
55 }
56 void unregisterLayer(const Layer* layer) {
57 mActiveLayers.erase(layer);
58 }
59
John Reck3b202512014-06-23 13:13:08 -070060private:
61 friend class renderthread::RenderThread;
62
63 void interruptForFunctorInvoke();
64 void resumeFromFunctorInvoke();
65
66 RenderState();
67 ~RenderState();
68
69 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070070 std::set<const Layer*> mActiveLayers;
John Reck3b202512014-06-23 13:13:08 -070071
72 GLsizei mViewportWidth;
73 GLsizei mViewportHeight;
74 GLuint mFramebuffer;
75};
76
77} /* namespace uirenderer */
78} /* namespace android */
79
80#endif /* RENDERSTATE_H */