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