blob: 44a5a147b6da05d6e18b42835f24edf842c0f7f5 [file] [log] [blame]
John Reck4f02bf42014-01-03 18:09:17 -08001/*
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 "RenderTask.h"
21
22#include <cutils/compiler.h>
23#include <EGL/egl.h>
John Reck19b6bcf2014-02-14 20:03:38 -080024#include <SkBitmap.h>
John Reck4f02bf42014-01-03 18:09:17 -080025#include <utils/Condition.h>
26#include <utils/Functor.h>
27#include <utils/Mutex.h>
John Reck18f16e62014-05-02 16:46:41 -070028#include <utils/Timers.h>
John Reck4f02bf42014-01-03 18:09:17 -080029#include <utils/StrongPointer.h>
30
John Recke1628b72014-05-23 15:11:19 -070031#include "../Caches.h"
Andres Morales910beb82016-02-02 16:19:40 -080032#include "../FrameMetricsObserver.h"
John Reck119907c2014-08-14 09:02:01 -070033#include "../IContextFactory.h"
John Reck1125d1f2014-10-23 11:02:19 -070034#include "CanvasContext.h"
John Reck668f0e32014-03-26 15:10:40 -070035#include "DrawFrameTask.h"
36
John Reck4f02bf42014-01-03 18:09:17 -080037namespace android {
sergeyv59eecb522016-11-17 17:54:57 -080038class GraphicBuffer;
39
John Reck4f02bf42014-01-03 18:09:17 -080040namespace uirenderer {
41
John Reck19b6bcf2014-02-14 20:03:38 -080042class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070043class RenderNode;
Chris Craik003cc3d2015-10-16 10:24:55 -070044class DisplayList;
John Reck19b6bcf2014-02-14 20:03:38 -080045class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080046class Rect;
John Reck51f2d602016-04-06 07:50:47 -070047class TreeObserver;
John Reck4f02bf42014-01-03 18:09:17 -080048
49namespace renderthread {
50
John Reck4f02bf42014-01-03 18:09:17 -080051class ErrorChannel;
52class RenderThread;
53class RenderProxyBridge;
54
John Recka41f2442016-04-07 16:36:57 -070055namespace DumpFlags {
56 enum {
57 FrameStats = 1 << 0,
58 Reset = 1 << 1,
59 JankStats = 1 << 2,
60 };
61};
62
John Reck4f02bf42014-01-03 18:09:17 -080063/*
64 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
65 * thread. It is important to note that RenderProxy may be deleted while it has
66 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
67 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
68 * references RenderProxy fields. This is safe as RenderProxy cannot
69 * be deleted if it is blocked inside a call.
70 */
71class ANDROID_API RenderProxy {
72public:
John Reck119907c2014-08-14 09:02:01 -070073 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode, IContextFactory* contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080074 ANDROID_API virtual ~RenderProxy();
75
John Reck1125d1f2014-10-23 11:02:19 -070076 // Won't take effect until next EGLSurface creation
77 ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior);
John Recke4280ba2014-05-05 16:39:37 -070078 ANDROID_API bool loadSystemProperties();
John Reckb36016c2015-03-11 08:50:53 -070079 ANDROID_API void setName(const char* name);
John Reck18f16e62014-05-02 16:46:41 -070080
John Reckf6481082016-02-02 15:18:23 -080081 ANDROID_API void initialize(const sp<Surface>& surface);
82 ANDROID_API void updateSurface(const sp<Surface>& surface);
83 ANDROID_API bool pauseSurface(const sp<Surface>& surface);
John Reck8afcc762016-04-13 10:24:06 -070084 ANDROID_API void setStopped(bool stopped);
John Reckab1080c2016-06-21 16:24:20 -070085 ANDROID_API void setup(float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -070086 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
Alan Viverette50210d92015-05-14 18:05:36 -070087 ANDROID_API void setLightCenter(const Vector3& lightCenter);
John Reck63a06672014-05-07 13:45:54 -070088 ANDROID_API void setOpaque(bool opaque);
John Reckba6adf62015-02-19 14:36:50 -080089 ANDROID_API int64_t* frameInfo();
John Reck51f2d602016-04-06 07:50:47 -070090 ANDROID_API int syncAndDrawFrame(TreeObserver* observer);
91 ANDROID_API void destroy(TreeObserver* observer);
John Reck4f02bf42014-01-03 18:09:17 -080092
John Reck3b202512014-06-23 13:13:08 -070093 ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck4f02bf42014-01-03 18:09:17 -080094
John Reck19b6bcf2014-02-14 20:03:38 -080095 ANDROID_API DeferredLayerUpdater* createTextureLayer();
John Reck51f2d602016-04-06 07:50:47 -070096 ANDROID_API void buildLayer(RenderNode* node, TreeObserver* observer);
John Reck3731dc22015-04-13 15:20:29 -070097 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
John Reckd72e0a32014-05-29 18:56:11 -070098 ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
99 ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
John Reck918ad522014-06-27 14:45:25 -0700100 ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800101
John Reck51f2d602016-04-06 07:50:47 -0700102 ANDROID_API void destroyHardwareResources(TreeObserver* observer);
John Reckf47a5942014-06-30 16:20:04 -0700103 ANDROID_API static void trimMemory(int level);
Chris Craik2507c342015-05-04 14:36:49 -0700104 ANDROID_API static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -0700105
John Reck28ad7b52014-04-07 16:59:25 -0700106 ANDROID_API void fence();
Thomas Buhotc0a0e1a2016-01-18 10:31:58 +0100107 ANDROID_API static void staticFence();
John Reckf47a5942014-06-30 16:20:04 -0700108 ANDROID_API void stopDrawing();
John Recka5dda642014-05-22 15:43:54 -0700109 ANDROID_API void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -0700110
John Reckba6adf62015-02-19 14:36:50 -0800111 ANDROID_API void dumpProfileInfo(int fd, int dumpFlags);
John Reck7f2e5e32015-05-05 11:00:53 -0700112 // Not exported, only used for testing
113 void resetProfileInfo();
John Reckf1480762016-07-03 18:28:25 -0700114 uint32_t frameTimePercentile(int p);
Chris Craik2ae07332015-01-21 14:22:39 -0800115 ANDROID_API static void dumpGraphicsMemory(int fd);
John Reckfe5e7b72014-05-23 17:42:28 -0700116
John Reckedc524c2015-03-18 15:24:33 -0700117 ANDROID_API void setProcessStatsBuffer(int fd);
Tim Murray33eb07f2016-06-10 10:03:20 -0700118 ANDROID_API int getRenderThreadTid();
John Reck3b202512014-06-23 13:13:08 -0700119
John Recke248bd12015-08-05 13:53:53 -0700120 ANDROID_API void serializeDisplayListTree();
121
Skuhneea7a7fb2015-08-28 07:10:31 -0700122 ANDROID_API void addRenderNode(RenderNode* node, bool placeFront);
123 ANDROID_API void removeRenderNode(RenderNode* node);
124 ANDROID_API void drawRenderNode(RenderNode* node);
Skuhneb8160872015-09-22 09:51:39 -0700125 ANDROID_API void setContentDrawBounds(int left, int top, int right, int bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700126
Andres Morales910beb82016-02-02 16:19:40 -0800127 ANDROID_API void addFrameMetricsObserver(FrameMetricsObserver* observer);
128 ANDROID_API void removeFrameMetricsObserver(FrameMetricsObserver* observer);
Andres Morales06f5bc72015-12-15 15:21:31 -0800129 ANDROID_API long getDroppedFrameReportCount();
130
John Reck95801462016-09-01 09:44:09 -0700131 ANDROID_API static int copySurfaceInto(sp<Surface>& surface,
132 int left, int top, int right, int bottom, SkBitmap* bitmap);
sergeyvec4a4b12016-10-20 18:39:04 -0700133 ANDROID_API static void prepareToDraw(Bitmap& bitmap);
John Reck10dd0582016-03-31 16:36:16 -0700134
sergeyv694d4992016-10-27 10:23:13 -0700135 static sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& bitmap);
sergeyv59eecb522016-11-17 17:54:57 -0800136
137 static int copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap);
John Reck4f02bf42014-01-03 18:09:17 -0800138private:
139 RenderThread& mRenderThread;
140 CanvasContext* mContext;
141
John Reck668f0e32014-03-26 15:10:40 -0700142 DrawFrameTask mDrawFrameTask;
143
John Reckcba287b2015-11-10 12:52:44 -0800144 Mutex mSyncMutex;
145 Condition mSyncCondition;
146
John Reck4f02bf42014-01-03 18:09:17 -0800147 void destroyContext();
148
John Reck4f02bf42014-01-03 18:09:17 -0800149 void post(RenderTask* task);
150 void* postAndWait(MethodInvokeRenderTask* task);
151
John Reck0e89e2b2014-10-31 14:49:06 -0700152 static void* staticPostAndWait(MethodInvokeRenderTask* task);
153
John Reck4f02bf42014-01-03 18:09:17 -0800154 // Friend class to help with bridging
155 friend class RenderProxyBridge;
156};
157
158} /* namespace renderthread */
159} /* namespace uirenderer */
160} /* namespace android */
161#endif /* RENDERPROXY_H_ */