• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2013 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 
17 #ifndef RENDERPROXY_H_
18 #define RENDERPROXY_H_
19 
20 #include <SkBitmap.h>
21 #include <android/native_window.h>
22 #include <cutils/compiler.h>
23 #include <android/surface_control.h>
24 #include <utils/Functor.h>
25 
26 #include "../FrameMetricsObserver.h"
27 #include "../IContextFactory.h"
28 #include "ColorMode.h"
29 #include "DrawFrameTask.h"
30 #include "SwapBehavior.h"
31 #include "hwui/Bitmap.h"
32 
33 namespace android {
34 class GraphicBuffer;
35 class Surface;
36 
37 namespace uirenderer {
38 
39 class DeferredLayerUpdater;
40 class RenderNode;
41 class Rect;
42 
43 namespace renderthread {
44 
45 class CanvasContext;
46 class RenderThread;
47 class RenderProxyBridge;
48 
49 namespace DumpFlags {
50 enum {
51     FrameStats = 1 << 0,
52     Reset = 1 << 1,
53     JankStats = 1 << 2,
54 };
55 }
56 
57 /*
58  * RenderProxy is strictly single threaded. All methods must be invoked on the owning
59  * thread. It is important to note that RenderProxy may be deleted while it has
60  * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
61  * reference RenderProxy or any of its fields. The exception here is that postAndWait()
62  * references RenderProxy fields. This is safe as RenderProxy cannot
63  * be deleted if it is blocked inside a call.
64  */
65 class RenderProxy {
66 public:
67     RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
68     virtual ~RenderProxy();
69 
70     // Won't take effect until next EGLSurface creation
71     void setSwapBehavior(SwapBehavior swapBehavior);
72     bool loadSystemProperties();
73     void setName(const char* name);
74 
75     void setSurface(ANativeWindow* window, bool enableTimeout = true);
76     void setSurfaceControl(ASurfaceControl* surfaceControl);
77     void allocateBuffers();
78     bool pause();
79     void setStopped(bool stopped);
80     void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
81     void setLightGeometry(const Vector3& lightCenter, float lightRadius);
82     void setOpaque(bool opaque);
83     void setColorMode(ColorMode mode);
84     int64_t* frameInfo();
85     void forceDrawNextFrame();
86     int syncAndDrawFrame();
87     void destroy();
88 
89     static void destroyFunctor(int functor);
90 
91     DeferredLayerUpdater* createTextureLayer();
92     void buildLayer(RenderNode* node);
93     bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
94     void pushLayerUpdate(DeferredLayerUpdater* layer);
95     void cancelLayerUpdate(DeferredLayerUpdater* layer);
96     void detachSurfaceTexture(DeferredLayerUpdater* layer);
97 
98     void destroyHardwareResources();
99     static void trimMemory(int level);
100     static void purgeCaches();
101     static void overrideProperty(const char* name, const char* value);
102 
103     void fence();
104     static int maxTextureSize();
105     void stopDrawing();
106     void notifyFramePending();
107 
108     void dumpProfileInfo(int fd, int dumpFlags);
109     // Not exported, only used for testing
110     void resetProfileInfo();
111     uint32_t frameTimePercentile(int p);
112     static void dumpGraphicsMemory(int fd, bool includeProfileData = true,
113                                    bool resetProfile = false);
114     static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
115 
116     static void rotateProcessStatsBuffer();
117     static void setProcessStatsBuffer(int fd);
118     int getRenderThreadTid();
119 
120     void addRenderNode(RenderNode* node, bool placeFront);
121     void removeRenderNode(RenderNode* node);
122     void drawRenderNode(RenderNode* node);
123     void setContentDrawBounds(int left, int top, int right, int bottom);
124     void setPictureCapturedCallback(const std::function<void(sk_sp<SkPicture>&&)>& callback);
125     void setASurfaceTransactionCallback(
126             const std::function<bool(int64_t, int64_t, int64_t)>& callback);
127     void setPrepareSurfaceControlForWebviewCallback(const std::function<void()>& callback);
128     void setFrameCallback(std::function<std::function<void(bool)>(int32_t, int64_t)>&& callback);
129     void setFrameCommitCallback(std::function<void(bool)>&& callback);
130     void setFrameCompleteCallback(std::function<void()>&& callback);
131 
132     void addFrameMetricsObserver(FrameMetricsObserver* observer);
133     void removeFrameMetricsObserver(FrameMetricsObserver* observer);
134     void setForceDark(bool enable);
135 
136     static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
137                                            int bottom, SkBitmap* bitmap);
138     static void prepareToDraw(Bitmap& bitmap);
139 
140     static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
141     static int copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap);
142 
143     static void disableVsync();
144 
145     static void preload();
146 
147     static void setRtAnimationsEnabled(bool enabled);
148 
149 private:
150     RenderThread& mRenderThread;
151     CanvasContext* mContext;
152 
153     DrawFrameTask mDrawFrameTask;
154 
155     void destroyContext();
156 
157     // Friend class to help with bridging
158     friend class RenderProxyBridge;
159 };
160 
161 } /* namespace renderthread */
162 } /* namespace uirenderer */
163 } /* namespace android */
164 #endif /* RENDERPROXY_H_ */
165