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