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 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 19 | #include "Caches.h" |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 20 | #include "renderstate/PixelBufferState.h" |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 21 | #include "utils/Macros.h" |
| 22 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 23 | #include <GLES2/gl2.h> |
| 24 | #include <GLES2/gl2ext.h> |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 25 | #include <private/hwui/DrawGlInfo.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 26 | #include <ui/Region.h> |
| 27 | #include <utils/Functor.h> |
| 28 | #include <utils/Mutex.h> |
| 29 | #include <utils/RefBase.h> |
| 30 | #include <set> |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 31 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 32 | class GrContext; |
| 33 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | namespace uirenderer { |
| 36 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 37 | class Caches; |
| 38 | class Layer; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 39 | class DeferredLayerUpdater; |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 40 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 41 | namespace renderthread { |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 42 | class CacheManager; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 43 | class CanvasContext; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 44 | class RenderThread; |
| 45 | } |
| 46 | |
| 47 | // TODO: Replace Cache's GL state tracking with this. For now it's more a thin |
| 48 | // wrapper of Caches for users to migrate to. |
| 49 | class RenderState { |
| 50 | PREVENT_COPY_AND_ASSIGN(RenderState); |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 51 | friend class renderthread::RenderThread; |
| 52 | friend class Caches; |
Derek Sollenberger | f9e45d1 | 2017-06-01 13:07:39 -0400 | [diff] [blame] | 53 | friend class renderthread::CacheManager; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 54 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 55 | public: |
| 56 | void onGLContextCreated(); |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 57 | void onGLContextDestroyed(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 58 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 59 | void onVkContextCreated(); |
| 60 | void onVkContextDestroyed(); |
| 61 | |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 62 | void flush(Caches::FlushMode flushMode); |
John Reck | 9a81487 | 2017-05-22 15:04:21 -0700 | [diff] [blame] | 63 | void onBitmapDestroyed(uint32_t pixelRefId); |
Chris Craik | 9fded23 | 2015-11-11 16:42:34 -0800 | [diff] [blame] | 64 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 65 | void setViewport(GLsizei width, GLsizei height); |
| 66 | void getViewport(GLsizei* outWidth, GLsizei* outHeight); |
| 67 | |
| 68 | void bindFramebuffer(GLuint fbo); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 69 | GLuint getFramebuffer() { return mFramebuffer; } |
John Reck | 0b8d067 | 2016-01-29 14:18:22 -0800 | [diff] [blame] | 70 | GLuint createFramebuffer(); |
Chris Craik | 818c9fb | 2015-10-23 14:33:42 -0700 | [diff] [blame] | 71 | void deleteFramebuffer(GLuint fbo); |
| 72 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 73 | void invokeFunctor(Functor* functor, DrawGlInfo::Mode mode, DrawGlInfo* info); |
| 74 | |
| 75 | void debugOverdraw(bool enable, bool clear); |
| 76 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 77 | void registerLayer(Layer* layer) { mActiveLayers.insert(layer); } |
| 78 | void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); } |
Chris Craik | 1d47742 | 2014-08-26 17:30:15 -0700 | [diff] [blame] | 79 | |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 80 | void registerCanvasContext(renderthread::CanvasContext* context) { |
| 81 | mRegisteredContexts.insert(context); |
| 82 | } |
| 83 | |
| 84 | void unregisterCanvasContext(renderthread::CanvasContext* context) { |
| 85 | mRegisteredContexts.erase(context); |
| 86 | } |
| 87 | |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 88 | void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) { |
| 89 | mActiveLayerUpdaters.insert(layerUpdater); |
| 90 | } |
| 91 | |
| 92 | void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) { |
| 93 | mActiveLayerUpdaters.erase(layerUpdater); |
| 94 | } |
| 95 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 96 | // TODO: This system is a little clunky feeling, this could use some |
| 97 | // more thinking... |
| 98 | void postDecStrong(VirtualLightRefBase* object); |
| 99 | |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 100 | GrContext* getGrContext() const; |
| 101 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 102 | void dump(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 103 | |
Chris Craik | 5854b34 | 2015-10-26 15:49:56 -0700 | [diff] [blame] | 104 | private: |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 105 | void interruptForFunctorInvoke(); |
| 106 | void resumeFromFunctorInvoke(); |
sergeyv | c3f1316 | 2017-02-06 11:45:14 -0800 | [diff] [blame] | 107 | void destroyLayersInUpdater(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 108 | |
Chih-Hung Hsieh | 4979645 | 2016-08-10 14:08:35 -0700 | [diff] [blame] | 109 | explicit RenderState(renderthread::RenderThread& thread); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 110 | ~RenderState(); |
| 111 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 112 | renderthread::RenderThread& mRenderThread; |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 113 | Caches* mCaches = nullptr; |
Chris Craik | 96a5c4c | 2015-01-27 15:46:35 -0800 | [diff] [blame] | 114 | |
John Reck | 49bc4ac | 2015-01-29 12:53:38 -0800 | [diff] [blame] | 115 | std::set<Layer*> mActiveLayers; |
sergeyv | 3e9999b | 2017-01-19 15:37:02 -0800 | [diff] [blame] | 116 | std::set<DeferredLayerUpdater*> mActiveLayerUpdaters; |
John Reck | 443a714 | 2014-09-04 17:40:05 -0700 | [diff] [blame] | 117 | std::set<renderthread::CanvasContext*> mRegisteredContexts; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 118 | |
| 119 | GLsizei mViewportWidth; |
| 120 | GLsizei mViewportHeight; |
| 121 | GLuint mFramebuffer; |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 122 | |
| 123 | pthread_t mThreadId; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } /* namespace uirenderer */ |
| 127 | } /* namespace android */ |
| 128 | |
| 129 | #endif /* RENDERSTATE_H */ |