blob: 629fe0d10b9175ef3a928a4900e05a826d0872e5 [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 Reckebd52612014-12-10 16:47:36 -080028#include "AssetAtlas.h"
John Reck3b202512014-06-23 13:13:08 -070029#include "Caches.h"
30#include "utils/Macros.h"
31
32namespace android {
33namespace uirenderer {
34
Tom Hudson2dc236b2014-10-15 15:46:42 -040035class Caches;
36class Layer;
37
John Reck3b202512014-06-23 13:13:08 -070038namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070039class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070040class RenderThread;
41}
42
43// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
44// wrapper of Caches for users to migrate to.
45class RenderState {
46 PREVENT_COPY_AND_ASSIGN(RenderState);
47public:
48 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070049 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070050
51 void setViewport(GLsizei width, GLsizei height);
52 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
53
54 void bindFramebuffer(GLuint fbo);
55 GLint getFramebuffer() { return mFramebuffer; }
56
57 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
58
59 void debugOverdraw(bool enable, bool clear);
60
Chris Craik1d477422014-08-26 17:30:15 -070061 void registerLayer(const Layer* layer) {
62 mActiveLayers.insert(layer);
63 }
64 void unregisterLayer(const Layer* layer) {
65 mActiveLayers.erase(layer);
66 }
67
John Reck443a7142014-09-04 17:40:05 -070068 void registerCanvasContext(renderthread::CanvasContext* context) {
69 mRegisteredContexts.insert(context);
70 }
71
72 void unregisterCanvasContext(renderthread::CanvasContext* context) {
73 mRegisteredContexts.erase(context);
74 }
75
John Reck0e89e2b2014-10-31 14:49:06 -070076 void requireGLContext();
77
78 // TODO: This system is a little clunky feeling, this could use some
79 // more thinking...
80 void postDecStrong(VirtualLightRefBase* object);
81
John Reckebd52612014-12-10 16:47:36 -080082 AssetAtlas& assetAtlas() { return mAssetAtlas; }
83
John Reck3b202512014-06-23 13:13:08 -070084private:
85 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070086 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070087
88 void interruptForFunctorInvoke();
89 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070090 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070091
John Reck0e89e2b2014-10-31 14:49:06 -070092 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070093 ~RenderState();
94
John Reck0e89e2b2014-10-31 14:49:06 -070095 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -070096 Caches* mCaches;
John Reckebd52612014-12-10 16:47:36 -080097 AssetAtlas mAssetAtlas;
Chris Craik1d477422014-08-26 17:30:15 -070098 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -070099 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700100
101 GLsizei mViewportWidth;
102 GLsizei mViewportHeight;
103 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700104
105 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700106};
107
108} /* namespace uirenderer */
109} /* namespace android */
110
111#endif /* RENDERSTATE_H */