• 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     int syncAndDrawFrame();
86     void destroy();
87 
88     static void destroyFunctor(int functor);
89 
90     DeferredLayerUpdater* createTextureLayer();
91     void buildLayer(RenderNode* node);
92     bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
93     void pushLayerUpdate(DeferredLayerUpdater* layer);
94     void cancelLayerUpdate(DeferredLayerUpdater* layer);
95     void detachSurfaceTexture(DeferredLayerUpdater* layer);
96 
97     void destroyHardwareResources();
98     static void trimMemory(int level);
99     static void purgeCaches();
100     static void overrideProperty(const char* name, const char* value);
101 
102     void fence();
103     static int maxTextureSize();
104     void stopDrawing();
105     void notifyFramePending();
106 
107     void dumpProfileInfo(int fd, int dumpFlags);
108     // Not exported, only used for testing
109     void resetProfileInfo();
110     uint32_t frameTimePercentile(int p);
111     static void dumpGraphicsMemory(int fd, bool includeProfileData = true);
112     static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
113 
114     static void rotateProcessStatsBuffer();
115     static void setProcessStatsBuffer(int fd);
116     int getRenderThreadTid();
117 
118     void addRenderNode(RenderNode* node, bool placeFront);
119     void removeRenderNode(RenderNode* node);
120     void drawRenderNode(RenderNode* node);
121     void setContentDrawBounds(int left, int top, int right, int bottom);
122     void setPictureCapturedCallback(const std::function<void(sk_sp<SkPicture>&&)>& callback);
123     void setASurfaceTransactionCallback(
124             const std::function<bool(int64_t, int64_t, int64_t)>& callback);
125     void setPrepareSurfaceControlForWebviewCallback(const std::function<void()>& callback);
126     void setFrameCallback(std::function<void(int64_t)>&& callback);
127     void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
128 
129     void addFrameMetricsObserver(FrameMetricsObserver* observer);
130     void removeFrameMetricsObserver(FrameMetricsObserver* observer);
131     void setForceDark(bool enable);
132 
133     static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
134                                            int bottom, SkBitmap* bitmap);
135     static void prepareToDraw(Bitmap& bitmap);
136 
137     static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
138     static int copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap);
139 
140     static void disableVsync();
141 
142     static void preload();
143 
144 private:
145     RenderThread& mRenderThread;
146     CanvasContext* mContext;
147 
148     DrawFrameTask mDrawFrameTask;
149 
150     void destroyContext();
151 
152     // Friend class to help with bridging
153     friend class RenderProxyBridge;
154 };
155 
156 } /* namespace renderthread */
157 } /* namespace uirenderer */
158 } /* namespace android */
159 #endif /* RENDERPROXY_H_ */
160