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