blob: 3d119dc9e2904cb21c8a0b40834195327e1e15b7 [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
John Reck3b202512014-06-23 13:13:08 -070019#include "Caches.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080020#include "Glop.h"
Chris Craik5854b342015-10-26 15:49:56 -070021#include "renderstate/Blend.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080022#include "renderstate/MeshState.h"
Chris Craik9fded232015-11-11 16:42:34 -080023#include "renderstate/OffscreenBufferPool.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080024#include "renderstate/PixelBufferState.h"
25#include "renderstate/Scissor.h"
26#include "renderstate/Stencil.h"
John Reck3b202512014-06-23 13:13:08 -070027#include "utils/Macros.h"
28
Chris Craik5854b342015-10-26 15:49:56 -070029#include <set>
30#include <GLES2/gl2.h>
31#include <GLES2/gl2ext.h>
32#include <ui/Region.h>
33#include <utils/Mutex.h>
34#include <utils/Functor.h>
35#include <utils/RefBase.h>
36#include <private/hwui/DrawGlInfo.h>
37
John Reck3b202512014-06-23 13:13:08 -070038namespace android {
39namespace uirenderer {
40
Tom Hudson2dc236b2014-10-15 15:46:42 -040041class Caches;
42class Layer;
43
John Reck3b202512014-06-23 13:13:08 -070044namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070045class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070046class RenderThread;
47}
48
49// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
50// wrapper of Caches for users to migrate to.
51class RenderState {
52 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070053 friend class renderthread::RenderThread;
54 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070055public:
56 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070057 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070058
Chris Craik9fded232015-11-11 16:42:34 -080059 void flush(Caches::FlushMode flushMode);
60
John Reck3b202512014-06-23 13:13:08 -070061 void setViewport(GLsizei width, GLsizei height);
62 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
63
64 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070065 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080066 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070067 void deleteFramebuffer(GLuint fbo);
68
John Reck3b202512014-06-23 13:13:08 -070069 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
70
71 void debugOverdraw(bool enable, bool clear);
72
John Reck49bc4ac2015-01-29 12:53:38 -080073 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070074 mActiveLayers.insert(layer);
75 }
John Reck49bc4ac2015-01-29 12:53:38 -080076 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070077 mActiveLayers.erase(layer);
78 }
79
John Reck443a7142014-09-04 17:40:05 -070080 void registerCanvasContext(renderthread::CanvasContext* context) {
81 mRegisteredContexts.insert(context);
82 }
83
84 void unregisterCanvasContext(renderthread::CanvasContext* context) {
85 mRegisteredContexts.erase(context);
86 }
87
John Reck0e89e2b2014-10-31 14:49:06 -070088 // TODO: This system is a little clunky feeling, this could use some
89 // more thinking...
90 void postDecStrong(VirtualLightRefBase* object);
91
Chris Craik12efe642015-09-28 15:52:12 -070092 void render(const Glop& glop, const Matrix4& orthoMatrix);
Chris Craik6c15ffa2015-02-02 13:50:55 -080093
Chris Craik44eb2c02015-01-29 09:45:09 -080094 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -080095 MeshState& meshState() { return *mMeshState; }
96 Scissor& scissor() { return *mScissor; }
97 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -080098
Chris Craik9fded232015-11-11 16:42:34 -080099 OffscreenBufferPool& layerPool() { return mLayerPool; }
100
Chris Craik117bdbc2015-02-05 10:12:38 -0800101 void dump();
John Reck3b202512014-06-23 13:13:08 -0700102
Chris Craik5854b342015-10-26 15:49:56 -0700103private:
John Reck3b202512014-06-23 13:13:08 -0700104 void interruptForFunctorInvoke();
105 void resumeFromFunctorInvoke();
106
Chih-Hung Hsieh49796452016-08-10 14:08:35 -0700107 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700108 ~RenderState();
109
Chris Craik65fe5ee2015-01-26 18:06:29 -0800110
John Reck0e89e2b2014-10-31 14:49:06 -0700111 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800112 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800113
Chris Craik44eb2c02015-01-29 09:45:09 -0800114 Blend* mBlend = nullptr;
115 MeshState* mMeshState = nullptr;
116 Scissor* mScissor = nullptr;
117 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800118
Chris Craik9fded232015-11-11 16:42:34 -0800119 OffscreenBufferPool mLayerPool;
120
John Reck49bc4ac2015-01-29 12:53:38 -0800121 std::set<Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700122 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700123
124 GLsizei mViewportWidth;
125 GLsizei mViewportHeight;
126 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700127
128 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700129};
130
131} /* namespace uirenderer */
132} /* namespace android */
133
134#endif /* RENDERSTATE_H */