blob: 501d76f1fe583d219ff904c1e0b2f10c9960b761 [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"
Chris Craik96a5c4c2015-01-27 15:46:35 -080030#include "renderstate/MeshState.h"
31#include "renderstate/PixelBufferState.h"
32#include "renderstate/Scissor.h"
33#include "renderstate/Stencil.h"
John Reck3b202512014-06-23 13:13:08 -070034#include "utils/Macros.h"
35
36namespace android {
37namespace uirenderer {
38
Tom Hudson2dc236b2014-10-15 15:46:42 -040039class Caches;
40class Layer;
41
John Reck3b202512014-06-23 13:13:08 -070042namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070043class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070044class RenderThread;
45}
46
47// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
48// wrapper of Caches for users to migrate to.
49class RenderState {
50 PREVENT_COPY_AND_ASSIGN(RenderState);
51public:
52 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070053 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070054
55 void setViewport(GLsizei width, GLsizei height);
56 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
57
58 void bindFramebuffer(GLuint fbo);
59 GLint getFramebuffer() { return mFramebuffer; }
60
61 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
62
63 void debugOverdraw(bool enable, bool clear);
64
Chris Craik1d477422014-08-26 17:30:15 -070065 void registerLayer(const Layer* layer) {
66 mActiveLayers.insert(layer);
67 }
68 void unregisterLayer(const Layer* layer) {
69 mActiveLayers.erase(layer);
70 }
71
John Reck443a7142014-09-04 17:40:05 -070072 void registerCanvasContext(renderthread::CanvasContext* context) {
73 mRegisteredContexts.insert(context);
74 }
75
76 void unregisterCanvasContext(renderthread::CanvasContext* context) {
77 mRegisteredContexts.erase(context);
78 }
79
John Reck0e89e2b2014-10-31 14:49:06 -070080 void requireGLContext();
81
82 // TODO: This system is a little clunky feeling, this could use some
83 // more thinking...
84 void postDecStrong(VirtualLightRefBase* object);
85
John Reckebd52612014-12-10 16:47:36 -080086 AssetAtlas& assetAtlas() { return mAssetAtlas; }
Chris Craik96a5c4c2015-01-27 15:46:35 -080087 MeshState& meshState() { return *mMeshState; }
88 Scissor& scissor() { return *mScissor; }
89 Stencil& stencil() { return *mStencil; }
John Reck3b202512014-06-23 13:13:08 -070090private:
91 friend class renderthread::RenderThread;
John Reck17035b02014-09-03 07:39:53 -070092 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070093
94 void interruptForFunctorInvoke();
95 void resumeFromFunctorInvoke();
John Reck0e89e2b2014-10-31 14:49:06 -070096 void assertOnGLThread();
John Reck3b202512014-06-23 13:13:08 -070097
John Reck0e89e2b2014-10-31 14:49:06 -070098 RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070099 ~RenderState();
100
Chris Craik65fe5ee2015-01-26 18:06:29 -0800101
John Reck0e89e2b2014-10-31 14:49:06 -0700102 renderthread::RenderThread& mRenderThread;
John Reck3b202512014-06-23 13:13:08 -0700103 Caches* mCaches;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800104
105 MeshState* mMeshState;
106 Scissor* mScissor;
107 Stencil* mStencil;
108
John Reckebd52612014-12-10 16:47:36 -0800109 AssetAtlas mAssetAtlas;
Chris Craik1d477422014-08-26 17:30:15 -0700110 std::set<const Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700111 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700112
113 GLsizei mViewportWidth;
114 GLsizei mViewportHeight;
115 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700116
117 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700118};
119
120} /* namespace uirenderer */
121} /* namespace android */
122
123#endif /* RENDERSTATE_H */