blob: f39aa4b96547de980a65b0652f4ce8ece97b077d [file] [log] [blame]
John Reck3b202512014-06-23 13:13:08 -07001/*
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 Reck3b202512014-06-23 13:13:08 -070019#include "utils/Macros.h"
20
Chris Craik5854b342015-10-26 15:49:56 -070021#include <GLES2/gl2.h>
22#include <GLES2/gl2ext.h>
Chris Craik5854b342015-10-26 15:49:56 -070023#include <private/hwui/DrawGlInfo.h>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <ui/Region.h>
25#include <utils/Functor.h>
26#include <utils/Mutex.h>
27#include <utils/RefBase.h>
28#include <set>
Chris Craik5854b342015-10-26 15:49:56 -070029
Greg Daniel45ec62b2017-01-04 14:27:00 -050030class GrContext;
31
John Reck3b202512014-06-23 13:13:08 -070032namespace android {
33namespace uirenderer {
34
Tom Hudson2dc236b2014-10-15 15:46:42 -040035class Layer;
sergeyv3e9999b2017-01-19 15:37:02 -080036class DeferredLayerUpdater;
Tom Hudson2dc236b2014-10-15 15:46:42 -040037
John Reck3b202512014-06-23 13:13:08 -070038namespace renderthread {
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040039class CacheManager;
John Reck443a7142014-09-04 17:40:05 -070040class CanvasContext;
John Reck3b202512014-06-23 13:13:08 -070041class RenderThread;
42}
43
John Reck3b202512014-06-23 13:13:08 -070044// wrapper of Caches for users to migrate to.
45class RenderState {
46 PREVENT_COPY_AND_ASSIGN(RenderState);
Chris Craik5854b342015-10-26 15:49:56 -070047 friend class renderthread::RenderThread;
Derek Sollenbergerf9e45d12017-06-01 13:07:39 -040048 friend class renderthread::CacheManager;
John Reck1bcacfd2017-11-03 10:12:19 -070049
John Reck3b202512014-06-23 13:13:08 -070050public:
Stan Ilievc8e22a62018-08-14 13:30:17 -040051 void onContextCreated();
52 void onContextDestroyed();
John Reck3b202512014-06-23 13:13:08 -070053
John Reck9a814872017-05-22 15:04:21 -070054 void onBitmapDestroyed(uint32_t pixelRefId);
Chris Craik9fded232015-11-11 16:42:34 -080055
John Reck3b202512014-06-23 13:13:08 -070056 void setViewport(GLsizei width, GLsizei height);
57 void getViewport(GLsizei* outWidth, GLsizei* outHeight);
58
59 void bindFramebuffer(GLuint fbo);
Chris Craik818c9fb2015-10-23 14:33:42 -070060 GLuint getFramebuffer() { return mFramebuffer; }
John Reck0b8d0672016-01-29 14:18:22 -080061 GLuint createFramebuffer();
Chris Craik818c9fb2015-10-23 14:33:42 -070062 void deleteFramebuffer(GLuint fbo);
63
John Reck3b202512014-06-23 13:13:08 -070064 void debugOverdraw(bool enable, bool clear);
65
John Reck1bcacfd2017-11-03 10:12:19 -070066 void registerLayer(Layer* layer) { mActiveLayers.insert(layer); }
67 void unregisterLayer(Layer* layer) { mActiveLayers.erase(layer); }
Chris Craik1d477422014-08-26 17:30:15 -070068
John Reck443a7142014-09-04 17:40:05 -070069 void registerCanvasContext(renderthread::CanvasContext* context) {
70 mRegisteredContexts.insert(context);
71 }
72
73 void unregisterCanvasContext(renderthread::CanvasContext* context) {
74 mRegisteredContexts.erase(context);
75 }
76
sergeyv3e9999b2017-01-19 15:37:02 -080077 void registerDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
78 mActiveLayerUpdaters.insert(layerUpdater);
79 }
80
81 void unregisterDeferredLayerUpdater(DeferredLayerUpdater* layerUpdater) {
82 mActiveLayerUpdaters.erase(layerUpdater);
83 }
84
John Reck0e89e2b2014-10-31 14:49:06 -070085 // TODO: This system is a little clunky feeling, this could use some
86 // more thinking...
87 void postDecStrong(VirtualLightRefBase* object);
88
Greg Daniel45ec62b2017-01-04 14:27:00 -050089 GrContext* getGrContext() const;
90
Chris Craik117bdbc2015-02-05 10:12:38 -080091 void dump();
John Reck3b202512014-06-23 13:13:08 -070092
Stan Ilievc8e22a62018-08-14 13:30:17 -040093 renderthread::RenderThread& getRenderThread();
94
Chris Craik5854b342015-10-26 15:49:56 -070095private:
sergeyvc3f13162017-02-06 11:45:14 -080096 void destroyLayersInUpdater();
John Reck3b202512014-06-23 13:13:08 -070097
Chih-Hung Hsieh49796452016-08-10 14:08:35 -070098 explicit RenderState(renderthread::RenderThread& thread);
John Reck3b202512014-06-23 13:13:08 -070099 ~RenderState();
100
John Reck0e89e2b2014-10-31 14:49:06 -0700101 renderthread::RenderThread& mRenderThread;
Chris Craik96a5c4c2015-01-27 15:46:35 -0800102
John Reck49bc4ac2015-01-29 12:53:38 -0800103 std::set<Layer*> mActiveLayers;
sergeyv3e9999b2017-01-19 15:37:02 -0800104 std::set<DeferredLayerUpdater*> mActiveLayerUpdaters;
John Reck443a7142014-09-04 17:40:05 -0700105 std::set<renderthread::CanvasContext*> mRegisteredContexts;
John Reck3b202512014-06-23 13:13:08 -0700106
107 GLsizei mViewportWidth;
108 GLsizei mViewportHeight;
109 GLuint mFramebuffer;
John Reck0e89e2b2014-10-31 14:49:06 -0700110
111 pthread_t mThreadId;
John Reck3b202512014-06-23 13:13:08 -0700112};
113
114} /* namespace uirenderer */
115} /* namespace android */
116
117#endif /* RENDERSTATE_H */