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 <GLES2/gl2.h> |
| 30 | #include <GLES2/gl2ext.h> |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 31 | #include <private/hwui/DrawGlInfo.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 32 | #include <ui/Region.h> |
| 33 | #include <utils/Functor.h> |
| 34 | #include <utils/Mutex.h> |
| 35 | #include <utils/RefBase.h> |
| 36 | #include <set> |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 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 { |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 48 | class CacheManager; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 49 | class CanvasContext; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 50 | class RenderThread; |
| 51 | } |
| 52 | |
| 53 | // TODO: Replace Cache's GL state tracking with this. For now it's more a thin |
| 54 | // wrapper of Caches for users to migrate to. |
| 55 | class RenderState { |
| 56 | PREVENT_COPY_AND_ASSIGN(RenderState); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 57 | friend class renderthread::RenderThread; |
| 58 | friend class Caches; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 59 | friend class renderthread::CacheManager; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 60 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 61 | public: |
| 62 | void onGLContextCreated(); |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 63 | void onGLContextDestroyed(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 64 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 65 | void onVkContextCreated(); |
| 66 | void onVkContextDestroyed(); |
| 67 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 68 | void flush(Caches::FlushMode flushMode); |
John Reck | 9a81487 | 2017-05-22 15:04:21 -0700 | [diff] [blame] | 69 | void onBitmapDestroyed(uint32_t pixelRefId); |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 70 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 71 | void setViewport(GLsizei width, GLsizei height); |
| 72 | void getViewport(GLsizei* outWidth, GLsizei* outHeight); |
| 73 | |
| 74 | void bindFramebuffer(GLuint fbo); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 75 | GLuint getFramebuffer() { return mFramebuffer; } |
John Reck | 0b8d067 | 2016-01-29 14:18:22 -0800 | [diff] [blame] | 76 | GLuint createFramebuffer(); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 77 | void deleteFramebuffer(GLuint fbo); |
| 78 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 79 | void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info); |
| 80 | |
| 81 | void debugOverdraw(bool enable, bool clear); |
| 82 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame^] | 83 | void registerLayer(Layer* layer) { mActiveLayers.insert(layer); } |
| 84 | void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); } |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 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 | |
Arun | 530a2b4 | 2017-01-23 12:47:57 +0000 | [diff] [blame] | 106 | void render(const Glop& glop, const Matrix4& orthoMatrix, bool overrideDisableBlending); |
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 | |
John Reck | 642ebea | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 113 | OffscreenBufferPool& layerPool() { return *mLayerPool; } |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 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 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 127 | renderthread::RenderThread& mRenderThread; |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 128 | Caches* mCaches = nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 129 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 130 | Blend* mBlend = nullptr; |
| 131 | MeshState* mMeshState = nullptr; |
| 132 | Scissor* mScissor = nullptr; |
| 133 | Stencil* mStencil = nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 134 | |
John Reck | 642ebea | 2017-07-17 09:55:02 -0700 | [diff] [blame] | 135 | OffscreenBufferPool* mLayerPool = nullptr; |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 136 | |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 137 | std::set<Layer*> mActiveLayers; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 138 | std::set<DeferredLayerUpdater*> mActiveLayerUpdaters; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 139 | std::set<renderthread::CanvasContext*> mRegisteredContexts; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 140 | |
| 141 | GLsizei mViewportWidth; |
| 142 | GLsizei mViewportHeight; |
| 143 | GLuint mFramebuffer; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 144 | |
| 145 | pthread_t mThreadId; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } /* namespace uirenderer */ |
| 149 | } /* namespace android */ |
| 150 | |
| 151 | #endif /* RENDERSTATE_H */ |