blob: 9e0fb121be6520f4ba25cc00c2c87b2cdd750c01 [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 Reckebd52612014-12-10 16:47:36 -080019#include "AssetAtlas.h"
John Reck3b202512014-06-23 13:13:08 -070020#include "Caches.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080021#include "Glop.h"
Chris Craik5854b342015-10-26 15:49:56 -070022#include "renderstate/Blend.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080023#include "renderstate/MeshState.h"
Chris Craik9fded232015-11-11 16:42:34 -080024#include "renderstate/OffscreenBufferPool.h"
Chris Craik96a5c4c2015-01-27 15:46:35 -080025#include "renderstate/PixelBufferState.h"
26#include "renderstate/Scissor.h"
27#include "renderstate/Stencil.h"
John Reck3b202512014-06-23 13:13:08 -070028#include "utils/Macros.h"
29
Chris Craik5854b342015-10-26 15:49:56 -070030#include <set>
31#include <GLES2/gl2.h>
32#include <GLES2/gl2ext.h>
33#include <ui/Region.h>
34#include <utils/Mutex.h>
35#include <utils/Functor.h>
36#include <utils/RefBase.h>
37#include <private/hwui/DrawGlInfo.h>
38
John Reck3b202512014-06-23 13:13:08 -070039namespace android {
40namespace uirenderer {
41
Tom Hudson2dc236b2014-10-15 15:46:42 -040042class Caches;
43class Layer;
44
John Reck3b202512014-06-23 13:13:08 -070045namespace renderthread {
John Reck443a7142014-09-04 17:40:05 -070046class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070047class RenderThread;
48}
49
50// TODO: Replace Cache's GL state tracking with this. For now it's more a thin
51// wrapper of Caches for users to migrate to.
52class RenderState {
53 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070054 friend class renderthread::RenderThread;
55 friend class Caches;
John Reck3b202512014-06-23 13:13:08 -070056public:
57 void onGLContextCreated();
Chris Craik1d477422014-08-26 17:30:15 -070058 void onGLContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070059
Chris Craik9fded232015-11-11 16:42:34 -080060 void flush(Caches::FlushMode flushMode);
61
John Reck3b202512014-06-23 13:13:08 -070062 void setViewport(GLsizei width, GLsizei height);
63 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
64
65 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070066 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080067 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070068 void deleteFramebuffer(GLuint fbo);
69
John Reck3b202512014-06-23 13:13:08 -070070 void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info);
71
72 void debugOverdraw(bool enable, bool clear);
73
John Reck49bc4ac2015-01-29 12:53:38 -080074 void registerLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070075 mActiveLayers.insert(layer);
76 }
John Reck49bc4ac2015-01-29 12:53:38 -080077 void unregisterLayer(Layer* layer) {
Chris Craik1d477422014-08-26 17:30:15 -070078 mActiveLayers.erase(layer);
79 }
80
John Reck443a7142014-09-04 17:40:05 -070081 void registerCanvasContext(renderthread::CanvasContext* context) {
82 mRegisteredContexts.insert(context);
83 }
84
85 void unregisterCanvasContext(renderthread::CanvasContext* context) {
86 mRegisteredContexts.erase(context);
87 }
88
John Reck0e89e2b2014-10-31 14:49:06 -070089 // TODO: This system is a little clunky feeling, this could use some
90 // more thinking...
91 void postDecStrong(VirtualLightRefBase* object);
92
Chris Craik12efe642015-09-28 15:52:12 -070093 void render(const Glop& glop, const Matrix4& orthoMatrix);
Chris Craik6c15ffa2015-02-02 13:50:55 -080094
John Reckebd52612014-12-10 16:47:36 -080095 AssetAtlas& assetAtlas() { return mAssetAtlas; }
Chris Craik44eb2c02015-01-29 09:45:09 -080096 Blend& blend() { return *mBlend; }
Chris Craik96a5c4c2015-01-27 15:46:35 -080097 MeshState& meshState() { return *mMeshState; }
98 Scissor& scissor() { return *mScissor; }
99 Stencil& stencil() { return *mStencil; }
Chris Craik117bdbc2015-02-05 10:12:38 -0800100
Chris Craik9fded232015-11-11 16:42:34 -0800101 OffscreenBufferPool& layerPool() { return mLayerPool; }
102
Chris Craik117bdbc2015-02-05 10:12:38 -0800103 void dump();
John Reck3b202512014-06-23 13:13:08 -0700104
Chris Craik5854b342015-10-26 15:49:56 -0700105private:
John Reck3b202512014-06-23 13:13:08 -0700106 void interruptForFunctorInvoke();
107 void resumeFromFunctorInvoke();
108
Chih-Hung Hsiehf35c9392016-08-10 14:08:35 -0700109 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -0700110 ~RenderState();
111
Chris Craik65fe5ee2015-01-26 18:06:29 -0800112
John Reck0e89e2b2014-10-31 14:49:06 -0700113 renderthread::RenderThread& mRenderThread;
Chris Craik44eb2c02015-01-29 09:45:09 -0800114 Caches* mCaches = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800115
Chris Craik44eb2c02015-01-29 09:45:09 -0800116 Blend* mBlend = nullptr;
117 MeshState* mMeshState = nullptr;
118 Scissor* mScissor = nullptr;
119 Stencil* mStencil = nullptr;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800120
Chris Craik9fded232015-11-11 16:42:34 -0800121 OffscreenBufferPool mLayerPool;
122
John Reckebd52612014-12-10 16:47:36 -0800123 AssetAtlas mAssetAtlas;
John Reck49bc4ac2015-01-29 12:53:38 -0800124 std::set<Layer*> mActiveLayers;
John Reck443a7142014-09-04 17:40:05 -0700125 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700126
127 GLsizei mViewportWidth;
128 GLsizei mViewportHeight;
129 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700130
131 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700132};
133
134} /* namespace uirenderer */
135} /* namespace android */
136
137#endif /* RENDERSTATE_H */