blob: 1ecfb1cf7c6c957fd6403d16d151d056080056e4 [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>
John Reck3b202512014-06-23 13:13:08 -070023
24#include <private/hwui/DrawGlInfo.h>
25
John Reckebd52612014-12-10 16:47:36 -080026#include "AssetAtlas.h"
John Reck3b202512014-06-23 13:13:08 -070027#include "Caches.h"
28#include "utils/Macros.h"
29
30namespace android {
31namespace uirenderer {
32
33namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070034class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070035class RenderThread;
36}
37
38// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
39// wrapper of Caches for users to migrate to.
40class RenderState {
41 PREVENT_COPY_AND_ASSIGN(RenderState);
42public:
43 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070044 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070045
46 void setViewport(GLsizei width, GLsizei height);
47 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
48
49 void bindFramebuffer(GLuint fbo);
50 GLint getFramebuffer() { return mFramebuffer; }
51
52 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
53
54 void debugOverdraw(bool enable, bool clear);
55
Chris Craik1d477422014-08-26 17:30:15 -070056 void registerLayer(const Layer* layer) {
57 mActiveLayers.insert(layer);
58 }
59 void unregisterLayer(const Layer* layer) {
60 mActiveLayers.erase(layer);
61 }
62
John Reck443a7142014-09-04 17:40:05 -070063 void registerCanvasContext(renderthread::CanvasContext* context) {
64 mRegisteredContexts.insert(context);
65 }
66
67 void unregisterCanvasContext(renderthread::CanvasContext* context) {
68 mRegisteredContexts.erase(context);
69 }
70
John Reck0e89e2b2014-10-31 14:49:06 -070071 void requireGLContext();
72
73 // TODO: This system is a little clunky feeling, this could use some
74 // more thinking...
75 void postDecStrong(VirtualLightRefBase* object);
76
John Reckebd52612014-12-10 16:47:36 -080077 AssetAtlas& assetAtlas() { return mAssetAtlas; }
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;
John Reckebd52612014-12-10 16:47:36 -080092 AssetAtlas mAssetAtlas;
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 */