blob: 1b3dc157dc227a8eefdff66bf35cbdf956b6c332 [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
John Reck19b6bcf2014-02-14 20:03:38 -080020#include <SkBitmap.h>
Alec Mouri43fe6fc2019-12-23 07:46:19 -080021#include <android/native_window.h>
John Reck1bcacfd2017-11-03 10:12:19 -070022#include <cutils/compiler.h>
John Reck1bcacfd2017-11-03 10:12:19 -070023#include <utils/Functor.h>
John Reck4f02bf42014-01-03 18:09:17 -080024
Andres Morales910beb82016-02-02 16:19:40 -080025#include "../FrameMetricsObserver.h"
John Reck119907c2014-08-14 09:02:01 -070026#include "../IContextFactory.h"
John Reck668f0e32014-03-26 15:10:40 -070027#include "DrawFrameTask.h"
John Reckf8441e62017-10-23 13:10:41 -070028#include "SwapBehavior.h"
John Reck1bcacfd2017-11-03 10:12:19 -070029#include "hwui/Bitmap.h"
John Reck668f0e32014-03-26 15:10:40 -070030
John Reck4f02bf42014-01-03 18:09:17 -080031namespace android {
sergeyv59eecb522016-11-17 17:54:57 -080032class GraphicBuffer;
Derek Sollenberger8b994192019-07-16 13:23:29 -040033class Surface;
sergeyv59eecb522016-11-17 17:54:57 -080034
John Reck4f02bf42014-01-03 18:09:17 -080035namespace uirenderer {
36
John Reck19b6bcf2014-02-14 20:03:38 -080037class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070038class RenderNode;
John Reck4f02bf42014-01-03 18:09:17 -080039class Rect;
40
41namespace renderthread {
42
John Reckf8441e62017-10-23 13:10:41 -070043class CanvasContext;
John Reck4f02bf42014-01-03 18:09:17 -080044class RenderThread;
45class RenderProxyBridge;
46
John Recka41f2442016-04-07 16:36:57 -070047namespace DumpFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070048enum {
49 FrameStats = 1 << 0,
50 Reset = 1 << 1,
51 JankStats = 1 << 2,
52};
Chris Blume7b8a8082018-11-30 15:51:58 -080053}
John Recka41f2442016-04-07 16:36:57 -070054
John Reck4f02bf42014-01-03 18:09:17 -080055/*
56 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
57 * thread. It is important to note that RenderProxy may be deleted while it has
58 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
59 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
60 * references RenderProxy fields. This is safe as RenderProxy cannot
61 * be deleted if it is blocked inside a call.
62 */
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050063class RenderProxy {
John Reck4f02bf42014-01-03 18:09:17 -080064public:
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050065 RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
66 virtual ~RenderProxy();
John Reck4f02bf42014-01-03 18:09:17 -080067
John Reck1125d1f2014-10-23 11:02:19 -070068 // Won't take effect until next EGLSurface creation
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050069 void setSwapBehavior(SwapBehavior swapBehavior);
70 bool loadSystemProperties();
71 void setName(const char* name);
John Reck18f16e62014-05-02 16:46:41 -070072
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050073 void setSurface(ANativeWindow* window, bool enableTimeout = true);
74 void allocateBuffers();
75 bool pause();
76 void setStopped(bool stopped);
77 void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
78 void setLightGeometry(const Vector3& lightCenter, float lightRadius);
79 void setOpaque(bool opaque);
80 void setWideGamut(bool wideGamut);
81 int64_t* frameInfo();
82 int syncAndDrawFrame();
83 void destroy();
John Reck4f02bf42014-01-03 18:09:17 -080084
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050085 static void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck283bb462018-12-13 16:40:14 -080086 static void destroyFunctor(int functor);
John Reck4f02bf42014-01-03 18:09:17 -080087
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050088 DeferredLayerUpdater* createTextureLayer();
89 void buildLayer(RenderNode* node);
90 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
91 void pushLayerUpdate(DeferredLayerUpdater* layer);
92 void cancelLayerUpdate(DeferredLayerUpdater* layer);
93 void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -080094
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050095 void destroyHardwareResources();
96 static void trimMemory(int level);
97 static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -070098
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050099 void fence();
100 static int maxTextureSize();
101 void stopDrawing();
102 void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -0700103
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500104 void dumpProfileInfo(int fd, int dumpFlags);
John Reck7f2e5e32015-05-05 11:00:53 -0700105 // Not exported, only used for testing
106 void resetProfileInfo();
John Reckf1480762016-07-03 18:28:25 -0700107 uint32_t frameTimePercentile(int p);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500108 static void dumpGraphicsMemory(int fd);
John Reckfe5e7b72014-05-23 17:42:28 -0700109
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500110 static void rotateProcessStatsBuffer();
111 static void setProcessStatsBuffer(int fd);
112 int getRenderThreadTid();
John Reck3b202512014-06-23 13:13:08 -0700113
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500114 void addRenderNode(RenderNode* node, bool placeFront);
115 void removeRenderNode(RenderNode* node);
116 void drawRenderNode(RenderNode* node);
117 void setContentDrawBounds(int left, int top, int right, int bottom);
118 void setPictureCapturedCallback(const std::function<void(sk_sp<SkPicture>&&)>& callback);
119 void setFrameCallback(std::function<void(int64_t)>&& callback);
120 void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
Skuhneea7a7fb2015-08-28 07:10:31 -0700121
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500122 void addFrameMetricsObserver(FrameMetricsObserver* observer);
123 void removeFrameMetricsObserver(FrameMetricsObserver* observer);
124 void setForceDark(bool enable);
Andres Morales06f5bc72015-12-15 15:21:31 -0800125
John Reck859f98d2019-03-13 16:25:20 -0700126 /**
127 * Sets a render-ahead depth on the backing renderer. This will increase latency by
128 * <swapInterval> * renderAhead and increase memory usage by (3 + renderAhead) * <resolution>.
129 * In return the renderer will be less susceptible to jitter, resulting in a smoother animation.
130 *
131 * Not recommended to use in response to anything touch driven, but for canned animations
132 * where latency is not a concern careful use may be beneficial.
133 *
134 * Note that when increasing this there will be a frame gap of N frames where N is
135 * renderAhead - <current renderAhead>. When decreasing this if there are any pending
136 * frames they will retain their prior renderAhead value, so it will take a few frames
137 * for the decrease to flush through.
138 *
139 * @param renderAhead How far to render ahead, must be in the range [0..2]
140 */
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500141 void setRenderAheadDepth(int renderAhead);
John Reck859f98d2019-03-13 16:25:20 -0700142
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500143 static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
John Reck1bcacfd2017-11-03 10:12:19 -0700144 int bottom, SkBitmap* bitmap);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500145 static void prepareToDraw(Bitmap& bitmap);
John Reck10dd0582016-03-31 16:36:16 -0700146
Stan Iliev1a025a72018-09-05 16:35:11 -0400147 static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
John Reck9a814872017-05-22 15:04:21 -0700148
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500149 static void disableVsync();
Stan Iliev3310fb12017-03-23 16:56:51 -0400150
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500151 static void preload();
Stan Iliev898123b2019-02-14 14:57:44 -0500152
John Reck4f02bf42014-01-03 18:09:17 -0800153private:
154 RenderThread& mRenderThread;
155 CanvasContext* mContext;
156
John Reck668f0e32014-03-26 15:10:40 -0700157 DrawFrameTask mDrawFrameTask;
158
John Reck4f02bf42014-01-03 18:09:17 -0800159 void destroyContext();
160
John Reck4f02bf42014-01-03 18:09:17 -0800161 // Friend class to help with bridging
162 friend class RenderProxyBridge;
163};
164
165} /* namespace renderthread */
166} /* namespace uirenderer */
167} /* namespace android */
168#endif /* RENDERPROXY_H_ */