blob: 3915fb5f3f83f16bd430e4fd15e221d60669e693 [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;
John Reck17035b02014-09-03 07:39:53 -070062 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070063
64 void interruptForFunctorInvoke();
65 void resumeFromFunctorInvoke();
66
67 RenderState();
68 ~RenderState();
69
70 Caches* mCaches;
Chris Craik1d477422014-08-26 17:30:15 -070071 std::set<const Layer*> mActiveLayers;
John Reck3b202512014-06-23 13:13:08 -070072
73 GLsizei mViewportWidth;
74 GLsizei mViewportHeight;
75 GLuint mFramebuffer;
76};
77
78} /* namespace uirenderer */
79} /* namespace android */
80
81#endif /* RENDERSTATE_H */