John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 1 | /* |
| 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 Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 19 | #include "Caches.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 20 | #include "Glop.h" |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 21 | #include "renderstate/Blend.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 22 | #include "renderstate/MeshState.h" |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 23 | #include "renderstate/OffscreenBufferPool.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 24 | #include "renderstate/PixelBufferState.h" |
| 25 | #include "renderstate/Scissor.h" |
| 26 | #include "renderstate/Stencil.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 27 | #include "utils/Macros.h" |
| 28 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 29 | #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 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 38 | class GrContext; |
| 39 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | namespace uirenderer { |
| 42 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 43 | class Caches; |
| 44 | class Layer; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 45 | class DeferredLayerUpdater; |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 46 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 47 | namespace renderthread { |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 48 | class CanvasContext; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 49 | class RenderThread; |
| 50 | } |
| 51 | |
| 52 | // TODO: Replace Cache's GL state tracking with this. For now it's more a thin |
| 53 | // wrapper of Caches for users to migrate to. |
| 54 | class RenderState { |
| 55 | PREVENT_COPY_AND_ASSIGN(RenderState); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 56 | friend class renderthread::RenderThread; |
| 57 | friend class Caches; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 58 | public: |
| 59 | void onGLContextCreated(); |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 60 | void onGLContextDestroyed(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 61 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 62 | void onVkContextCreated(); |
| 63 | void onVkContextDestroyed(); |
| 64 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 65 | void flush(Caches::FlushMode flushMode); |
| 66 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 67 | void setViewport(GLsizei width, GLsizei height); |
| 68 | void getViewport(GLsizei* outWidth, GLsizei* outHeight); |
| 69 | |
| 70 | void bindFramebuffer(GLuint fbo); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 71 | GLuint getFramebuffer() { return mFramebuffer; } |
John Reck | 0b8d067 | 2016-01-29 14:18:22 -0800 | [diff] [blame] | 72 | GLuint createFramebuffer(); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 73 | void deleteFramebuffer(GLuint fbo); |
| 74 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 75 | void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info); |
| 76 | |
| 77 | void debugOverdraw(bool enable, bool clear); |
| 78 | |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 79 | void registerLayer(Layer* layer) { |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 80 | mActiveLayers.insert(layer); |
| 81 | } |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 82 | void unregisterLayer(Layer* layer) { |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 83 | mActiveLayers.erase(layer); |
| 84 | } |
| 85 | |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 86 | void registerCanvasContext(renderthread::CanvasContext* context) { |
| 87 | mRegisteredContexts.insert(context); |
| 88 | } |
| 89 | |
| 90 | void unregisterCanvasContext(renderthread::CanvasContext* context) { |
| 91 | mRegisteredContexts.erase(context); |
| 92 | } |
| 93 | |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 94 | void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) { |
| 95 | mActiveLayerUpdaters.insert(layerUpdater); |
| 96 | } |
| 97 | |
| 98 | void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) { |
| 99 | mActiveLayerUpdaters.erase(layerUpdater); |
| 100 | } |
| 101 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 102 | // TODO: This system is a little clunky feeling, this could use some |
| 103 | // more thinking... |
| 104 | void postDecStrong(VirtualLightRefBase* object); |
| 105 | |
Chris Craik | 12efe64 | 2015-09-28 15:52:12 -0700 | [diff] [blame] | 106 | void render(const Glop& glop, const Matrix4& orthoMatrix); |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 107 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 108 | Blend& blend() { return *mBlend; } |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 109 | MeshState& meshState() { return *mMeshState; } |
| 110 | Scissor& scissor() { return *mScissor; } |
| 111 | Stencil& stencil() { return *mStencil; } |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 112 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 113 | OffscreenBufferPool& layerPool() { return mLayerPool; } |
| 114 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 115 | GrContext* getGrContext() const; |
| 116 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 117 | void dump(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 118 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 119 | private: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 120 | void interruptForFunctorInvoke(); |
| 121 | void resumeFromFunctorInvoke(); |
sergeyv | c3f1316 | 2017-02-06 11:45:14 -0800 | [diff] [blame^] | 122 | void destroyLayersInUpdater(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 123 | |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 124 | explicit RenderState(renderthread::RenderThread& thread); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 125 | ~RenderState(); |
| 126 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 127 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 128 | renderthread::RenderThread& mRenderThread; |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 129 | Caches* mCaches = nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 130 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 131 | Blend* mBlend = nullptr; |
| 132 | MeshState* mMeshState = nullptr; |
| 133 | Scissor* mScissor = nullptr; |
| 134 | Stencil* mStencil = nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 135 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 136 | OffscreenBufferPool mLayerPool; |
| 137 | |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 138 | std::set<Layer*> mActiveLayers; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 139 | std::set<DeferredLayerUpdater*> mActiveLayerUpdaters; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 140 | std::set<renderthread::CanvasContext*> mRegisteredContexts; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 141 | |
| 142 | GLsizei mViewportWidth; |
| 143 | GLsizei mViewportHeight; |
| 144 | GLuint mFramebuffer; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 145 | |
| 146 | pthread_t mThreadId; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | } /* namespace uirenderer */ |
| 150 | } /* namespace android */ |
| 151 | |
| 152 | #endif /* RENDERSTATE_H */ |