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