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