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