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