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 | |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 19 | #include <set> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 20 | #include <GLES2/gl2.h> |
| 21 | #include <GLES2/gl2ext.h> |
Chris Craik | 599e254 | 2014-09-05 15:17:11 -0700 | [diff] [blame] | 22 | #include <utils/Mutex.h> |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 23 | #include <utils/Functor.h> |
Nick Kralevich | bfed827 | 2014-11-01 18:37:39 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 25 | |
| 26 | #include <private/hwui/DrawGlInfo.h> |
| 27 | |
John Reck | ebd5261 | 2014-12-10 16:47:36 -0800 | [diff] [blame] | 28 | #include "AssetAtlas.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 29 | #include "Caches.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 30 | #include "renderstate/MeshState.h" |
| 31 | #include "renderstate/PixelBufferState.h" |
| 32 | #include "renderstate/Scissor.h" |
| 33 | #include "renderstate/Stencil.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 34 | #include "utils/Macros.h" |
| 35 | |
| 36 | namespace android { |
| 37 | namespace uirenderer { |
| 38 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 39 | class Caches; |
| 40 | class Layer; |
| 41 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 42 | namespace renderthread { |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 43 | class CanvasContext; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 44 | class RenderThread; |
| 45 | } |
| 46 | |
| 47 | // TODO: Replace Cache's GL state tracking with this. For now it's more a thin |
| 48 | // wrapper of Caches for users to migrate to. |
| 49 | class RenderState { |
| 50 | PREVENT_COPY_AND_ASSIGN(RenderState); |
| 51 | public: |
| 52 | void onGLContextCreated(); |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 53 | void onGLContextDestroyed(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 54 | |
| 55 | void setViewport(GLsizei width, GLsizei height); |
| 56 | void getViewport(GLsizei* outWidth, GLsizei* outHeight); |
| 57 | |
| 58 | void bindFramebuffer(GLuint fbo); |
| 59 | GLint getFramebuffer() { return mFramebuffer; } |
| 60 | |
| 61 | void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info); |
| 62 | |
| 63 | void debugOverdraw(bool enable, bool clear); |
| 64 | |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 65 | void registerLayer(Layer* layer) { |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 66 | mActiveLayers.insert(layer); |
| 67 | } |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 68 | void unregisterLayer(Layer* layer) { |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 69 | mActiveLayers.erase(layer); |
| 70 | } |
| 71 | |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 72 | void registerCanvasContext(renderthread::CanvasContext* context) { |
| 73 | mRegisteredContexts.insert(context); |
| 74 | } |
| 75 | |
| 76 | void unregisterCanvasContext(renderthread::CanvasContext* context) { |
| 77 | mRegisteredContexts.erase(context); |
| 78 | } |
| 79 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 80 | void requireGLContext(); |
| 81 | |
| 82 | // TODO: This system is a little clunky feeling, this could use some |
| 83 | // more thinking... |
| 84 | void postDecStrong(VirtualLightRefBase* object); |
| 85 | |
John Reck | ebd5261 | 2014-12-10 16:47:36 -0800 | [diff] [blame] | 86 | AssetAtlas& assetAtlas() { return mAssetAtlas; } |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 87 | MeshState& meshState() { return *mMeshState; } |
| 88 | Scissor& scissor() { return *mScissor; } |
| 89 | Stencil& stencil() { return *mStencil; } |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 90 | private: |
| 91 | friend class renderthread::RenderThread; |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 92 | friend class Caches; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 93 | |
| 94 | void interruptForFunctorInvoke(); |
| 95 | void resumeFromFunctorInvoke(); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 96 | void assertOnGLThread(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 97 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 98 | RenderState(renderthread::RenderThread& thread); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 99 | ~RenderState(); |
| 100 | |
Chris Craik | 65fe5ee | 2015-01-26 18:06:29 -0800 | [diff] [blame] | 101 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 102 | renderthread::RenderThread& mRenderThread; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 103 | Caches* mCaches; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 104 | |
| 105 | MeshState* mMeshState; |
| 106 | Scissor* mScissor; |
| 107 | Stencil* mStencil; |
| 108 | |
John Reck | ebd5261 | 2014-12-10 16:47:36 -0800 | [diff] [blame] | 109 | AssetAtlas mAssetAtlas; |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 110 | std::set<Layer*> mActiveLayers; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 111 | std::set<renderthread::CanvasContext*> mRegisteredContexts; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 112 | |
| 113 | GLsizei mViewportWidth; |
| 114 | GLsizei mViewportHeight; |
| 115 | GLuint mFramebuffer; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 116 | |
| 117 | pthread_t mThreadId; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } /* namespace uirenderer */ |
| 121 | } /* namespace android */ |
| 122 | |
| 123 | #endif /* RENDERSTATE_H */ |