blob: f2d8e94c7bd2aa7e775cba5819cb96019ac59f7f [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
Kevin Lubick1175dc02022-02-28 12:41:27 -050020#include <SkRefCnt.h>
Nader Jawada3521852023-01-30 20:23:46 -080021#include <android/hardware_buffer.h>
Alec Mouri43fe6fc2019-12-23 07:46:19 -080022#include <android/native_window.h>
Huihong Luo5fdf7b82021-01-15 14:27:06 -080023#include <android/surface_control.h>
John Reck4d73cb12022-07-27 10:32:52 -040024#include <cutils/compiler.h>
John Reck1bcacfd2017-11-03 10:12:19 -070025#include <utils/Functor.h>
John Reck4f02bf42014-01-03 18:09:17 -080026
Andres Morales910beb82016-02-02 16:19:40 -080027#include "../FrameMetricsObserver.h"
John Reck119907c2014-08-14 09:02:01 -070028#include "../IContextFactory.h"
John Reckb36bfdd2020-07-23 13:47:49 -070029#include "ColorMode.h"
John Reck4d73cb12022-07-27 10:32:52 -040030#include "CopyRequest.h"
John Reck668f0e32014-03-26 15:10:40 -070031#include "DrawFrameTask.h"
John Reckf8441e62017-10-23 13:10:41 -070032#include "SwapBehavior.h"
John Reck1bcacfd2017-11-03 10:12:19 -070033#include "hwui/Bitmap.h"
Tyler Freeman417accd2023-10-31 02:01:06 +000034#include "utils/ForceDark.h"
John Reck668f0e32014-03-26 15:10:40 -070035
Kevin Lubick1175dc02022-02-28 12:41:27 -050036class SkBitmap;
37class SkPicture;
38class SkImage;
39
John Reck4f02bf42014-01-03 18:09:17 -080040namespace android {
sergeyv59eecb522016-11-17 17:54:57 -080041class GraphicBuffer;
Derek Sollenberger8b994192019-07-16 13:23:29 -040042class Surface;
sergeyv59eecb522016-11-17 17:54:57 -080043
John Reck4f02bf42014-01-03 18:09:17 -080044namespace uirenderer {
45
John Reck19b6bcf2014-02-14 20:03:38 -080046class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070047class RenderNode;
John Reck4f02bf42014-01-03 18:09:17 -080048class Rect;
49
50namespace renderthread {
51
John Reckf8441e62017-10-23 13:10:41 -070052class CanvasContext;
John Reck4f02bf42014-01-03 18:09:17 -080053class RenderThread;
54class RenderProxyBridge;
55
John Recka41f2442016-04-07 16:36:57 -070056namespace DumpFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070057enum {
58 FrameStats = 1 << 0,
59 Reset = 1 << 1,
60 JankStats = 1 << 2,
61};
Chris Blume7b8a8082018-11-30 15:51:58 -080062}
John Recka41f2442016-04-07 16:36:57 -070063
John Reck4f02bf42014-01-03 18:09:17 -080064/*
65 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
66 * thread. It is important to note that RenderProxy may be deleted while it has
67 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
68 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
69 * references RenderProxy fields. This is safe as RenderProxy cannot
70 * be deleted if it is blocked inside a call.
71 */
John Reckf0b69212021-06-25 17:33:33 +000072class RenderProxy {
John Reck4f02bf42014-01-03 18:09:17 -080073public:
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050074 RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
John Reckf0b69212021-06-25 17:33:33 +000075 virtual ~RenderProxy();
John Reck4f02bf42014-01-03 18:09:17 -080076
John Reck1125d1f2014-10-23 11:02:19 -070077 // Won't take effect until next EGLSurface creation
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050078 void setSwapBehavior(SwapBehavior swapBehavior);
79 bool loadSystemProperties();
80 void setName(const char* name);
Nader Jawada3521852023-01-30 20:23:46 -080081 void setHardwareBuffer(AHardwareBuffer* buffer);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050082 void setSurface(ANativeWindow* window, bool enableTimeout = true);
Huihong Luo5fdf7b82021-01-15 14:27:06 -080083 void setSurfaceControl(ASurfaceControl* surfaceControl);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050084 void allocateBuffers();
85 bool pause();
86 void setStopped(bool stopped);
87 void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
88 void setLightGeometry(const Vector3& lightCenter, float lightRadius);
Nader Jawada3521852023-01-30 20:23:46 -080089 void setHardwareBufferRenderParams(const HardwareBufferRenderParams& params);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050090 void setOpaque(bool opaque);
John Reck55887762023-01-25 16:51:18 -050091 float setColorMode(ColorMode mode);
92 void setRenderSdrHdrRatio(float ratio);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050093 int64_t* frameInfo();
chaviwadba0b12022-03-18 17:42:15 -050094 void forceDrawNextFrame();
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050095 int syncAndDrawFrame();
96 void destroy();
John Reck4f02bf42014-01-03 18:09:17 -080097
John Reck283bb462018-12-13 16:40:14 -080098 static void destroyFunctor(int functor);
John Reck4f02bf42014-01-03 18:09:17 -080099
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500100 DeferredLayerUpdater* createTextureLayer();
101 void buildLayer(RenderNode* node);
102 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
103 void pushLayerUpdate(DeferredLayerUpdater* layer);
104 void cancelLayerUpdate(DeferredLayerUpdater* layer);
105 void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -0800106
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500107 void destroyHardwareResources();
108 static void trimMemory(int level);
Jernej Virag44db0402023-05-09 20:24:48 +0200109 static void trimCaches(int level);
John Reck39207682021-05-12 19:10:47 -0400110 static void purgeCaches();
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500111 static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -0700112
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500113 void fence();
114 static int maxTextureSize();
115 void stopDrawing();
116 void notifyFramePending();
Matt Buckleyd98e8052022-10-21 22:13:23 +0000117 void notifyCallbackPending();
Matt Buckleyac5f7552022-12-19 22:03:27 +0000118 void notifyExpensiveFrame();
John Reck28ad7b52014-04-07 16:59:25 -0700119
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500120 void dumpProfileInfo(int fd, int dumpFlags);
John Reck7f2e5e32015-05-05 11:00:53 -0700121 // Not exported, only used for testing
122 void resetProfileInfo();
John Reckf1480762016-07-03 18:28:25 -0700123 uint32_t frameTimePercentile(int p);
John Reck712eae02021-10-01 15:24:27 -0400124 static void dumpGraphicsMemory(int fd, bool includeProfileData = true,
125 bool resetProfile = false);
John Reck39207682021-05-12 19:10:47 -0400126 static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
John Reckfe5e7b72014-05-23 17:42:28 -0700127
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500128 static void rotateProcessStatsBuffer();
129 static void setProcessStatsBuffer(int fd);
130 int getRenderThreadTid();
John Reck3b202512014-06-23 13:13:08 -0700131
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500132 void addRenderNode(RenderNode* node, bool placeFront);
133 void removeRenderNode(RenderNode* node);
134 void drawRenderNode(RenderNode* node);
135 void setContentDrawBounds(int left, int top, int right, int bottom);
136 void setPictureCapturedCallback(const std::function<void(sk_sp<SkPicture>&&)>& callback);
Huihong Luo054b8d32021-02-24 18:48:12 -0800137 void setASurfaceTransactionCallback(
Huihong Luo4df41512021-06-24 10:04:32 -0700138 const std::function<bool(int64_t, int64_t, int64_t)>& callback);
Huihong Luo34f42fd2021-05-03 14:47:36 -0700139 void setPrepareSurfaceControlForWebviewCallback(const std::function<void()>& callback);
chaviwb6803712021-12-13 15:46:29 -0600140 void setFrameCallback(std::function<std::function<void(bool)>(int32_t, int64_t)>&& callback);
chaviw9c137532021-08-20 12:15:48 -0500141 void setFrameCommitCallback(std::function<void(bool)>&& callback);
142 void setFrameCompleteCallback(std::function<void()>&& callback);
Skuhneea7a7fb2015-08-28 07:10:31 -0700143
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500144 void addFrameMetricsObserver(FrameMetricsObserver* observer);
145 void removeFrameMetricsObserver(FrameMetricsObserver* observer);
Tyler Freeman417accd2023-10-31 02:01:06 +0000146 void setForceDark(ForceDarkType type);
Andres Morales06f5bc72015-12-15 15:21:31 -0800147
John Reck4d73cb12022-07-27 10:32:52 -0400148 static void copySurfaceInto(ANativeWindow* window, std::shared_ptr<CopyRequest>&& request);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500149 static void prepareToDraw(Bitmap& bitmap);
John Reck10dd0582016-03-31 16:36:16 -0700150
Stan Iliev1a025a72018-09-05 16:35:11 -0400151 static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
John Reck76005182021-06-09 22:43:05 -0400152 static int copyImageInto(const sk_sp<SkImage>& image, SkBitmap* bitmap);
John Reck9a814872017-05-22 15:04:21 -0700153
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500154 static void disableVsync();
Stan Iliev3310fb12017-03-23 16:56:51 -0400155
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500156 static void preload();
Stan Iliev898123b2019-02-14 14:57:44 -0500157
chaviw01053d432022-03-18 17:54:00 -0500158 static void setRtAnimationsEnabled(bool enabled);
159
John Reck4f02bf42014-01-03 18:09:17 -0800160private:
161 RenderThread& mRenderThread;
162 CanvasContext* mContext;
163
John Reck668f0e32014-03-26 15:10:40 -0700164 DrawFrameTask mDrawFrameTask;
165
John Reck4f02bf42014-01-03 18:09:17 -0800166 void destroyContext();
167
John Reck4f02bf42014-01-03 18:09:17 -0800168 // Friend class to help with bridging
169 friend class RenderProxyBridge;
170};
171
172} /* namespace renderthread */
173} /* namespace uirenderer */
174} /* namespace android */
175#endif /* RENDERPROXY_H_ */