blob: 0681dc5e16be5e7c0b3d349f9b2e2ec4b42b2967 [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>
Huihong Luo5fdf7b82021-01-15 14:27:06 -080023#include <android/surface_control.h>
John Reck1bcacfd2017-11-03 10:12:19 -070024#include <utils/Functor.h>
John Reck4f02bf42014-01-03 18:09:17 -080025
Andres Morales910beb82016-02-02 16:19:40 -080026#include "../FrameMetricsObserver.h"
John Reck119907c2014-08-14 09:02:01 -070027#include "../IContextFactory.h"
John Reckb36bfdd2020-07-23 13:47:49 -070028#include "ColorMode.h"
John Reck668f0e32014-03-26 15:10:40 -070029#include "DrawFrameTask.h"
John Reckf8441e62017-10-23 13:10:41 -070030#include "SwapBehavior.h"
John Reck1bcacfd2017-11-03 10:12:19 -070031#include "hwui/Bitmap.h"
John Reck668f0e32014-03-26 15:10:40 -070032
John Reck4f02bf42014-01-03 18:09:17 -080033namespace android {
sergeyv59eecb522016-11-17 17:54:57 -080034class GraphicBuffer;
Derek Sollenberger8b994192019-07-16 13:23:29 -040035class Surface;
sergeyv59eecb522016-11-17 17:54:57 -080036
John Reck4f02bf42014-01-03 18:09:17 -080037namespace uirenderer {
38
John Reck19b6bcf2014-02-14 20:03:38 -080039class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070040class RenderNode;
John Reck4f02bf42014-01-03 18:09:17 -080041class Rect;
42
43namespace renderthread {
44
John Reckf8441e62017-10-23 13:10:41 -070045class CanvasContext;
John Reck4f02bf42014-01-03 18:09:17 -080046class RenderThread;
47class RenderProxyBridge;
48
John Recka41f2442016-04-07 16:36:57 -070049namespace DumpFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070050enum {
51 FrameStats = 1 << 0,
52 Reset = 1 << 1,
53 JankStats = 1 << 2,
54};
Chris Blume7b8a8082018-11-30 15:51:58 -080055}
John Recka41f2442016-04-07 16:36:57 -070056
John Reck4f02bf42014-01-03 18:09:17 -080057/*
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 */
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050065class RenderProxy {
John Reck4f02bf42014-01-03 18:09:17 -080066public:
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050067 RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
68 virtual ~RenderProxy();
John Reck4f02bf42014-01-03 18:09:17 -080069
John Reck1125d1f2014-10-23 11:02:19 -070070 // Won't take effect until next EGLSurface creation
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050071 void setSwapBehavior(SwapBehavior swapBehavior);
72 bool loadSystemProperties();
73 void setName(const char* name);
Bo Liu027b2182021-03-18 16:50:38 -040074 void setHintSessionCallbacks(std::function<void(int64_t)> updateTargetWorkDuration,
75 std::function<void(int64_t)> reportActualWorkDuration);
John Reck18f16e62014-05-02 16:46:41 -070076
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050077 void setSurface(ANativeWindow* window, bool enableTimeout = true);
Huihong Luo5fdf7b82021-01-15 14:27:06 -080078 void setSurfaceControl(ASurfaceControl* surfaceControl);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050079 void allocateBuffers();
80 bool pause();
81 void setStopped(bool stopped);
82 void setLightAlpha(uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
83 void setLightGeometry(const Vector3& lightCenter, float lightRadius);
84 void setOpaque(bool opaque);
John Reckb36bfdd2020-07-23 13:47:49 -070085 void setColorMode(ColorMode mode);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050086 int64_t* frameInfo();
87 int syncAndDrawFrame();
88 void destroy();
John Reck4f02bf42014-01-03 18:09:17 -080089
John Reck283bb462018-12-13 16:40:14 -080090 static void destroyFunctor(int functor);
John Reck4f02bf42014-01-03 18:09:17 -080091
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050092 DeferredLayerUpdater* createTextureLayer();
93 void buildLayer(RenderNode* node);
94 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
95 void pushLayerUpdate(DeferredLayerUpdater* layer);
96 void cancelLayerUpdate(DeferredLayerUpdater* layer);
97 void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -080098
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050099 void destroyHardwareResources();
100 static void trimMemory(int level);
John Reck39207682021-05-12 19:10:47 -0400101 static void purgeCaches();
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500102 static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -0700103
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500104 void fence();
105 static int maxTextureSize();
106 void stopDrawing();
107 void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -0700108
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500109 void dumpProfileInfo(int fd, int dumpFlags);
John Reck7f2e5e32015-05-05 11:00:53 -0700110 // Not exported, only used for testing
111 void resetProfileInfo();
John Reckf1480762016-07-03 18:28:25 -0700112 uint32_t frameTimePercentile(int p);
John Reck66e06d42021-05-11 17:04:54 -0400113 static void dumpGraphicsMemory(int fd, bool includeProfileData = true);
John Reck39207682021-05-12 19:10:47 -0400114 static void getMemoryUsage(size_t* cpuUsage, size_t* gpuUsage);
John Reckfe5e7b72014-05-23 17:42:28 -0700115
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500116 static void rotateProcessStatsBuffer();
117 static void setProcessStatsBuffer(int fd);
118 int getRenderThreadTid();
John Reck3b202512014-06-23 13:13:08 -0700119
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500120 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);
Huihong Luo054b8d32021-02-24 18:48:12 -0800125 void setASurfaceTransactionCallback(
126 const std::function<void(int64_t, int64_t, int64_t)>& callback);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500127 void setFrameCallback(std::function<void(int64_t)>&& callback);
128 void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
Skuhneea7a7fb2015-08-28 07:10:31 -0700129
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500130 void addFrameMetricsObserver(FrameMetricsObserver* observer);
131 void removeFrameMetricsObserver(FrameMetricsObserver* observer);
132 void setForceDark(bool enable);
Andres Morales06f5bc72015-12-15 15:21:31 -0800133
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500134 static int copySurfaceInto(ANativeWindow* window, int left, int top, int right,
John Reck1bcacfd2017-11-03 10:12:19 -0700135 int bottom, SkBitmap* bitmap);
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500136 static void prepareToDraw(Bitmap& bitmap);
John Reck10dd0582016-03-31 16:36:16 -0700137
Stan Iliev1a025a72018-09-05 16:35:11 -0400138 static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
John Reck9a814872017-05-22 15:04:21 -0700139
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500140 static void disableVsync();
Stan Iliev3310fb12017-03-23 16:56:51 -0400141
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500142 static void preload();
Stan Iliev898123b2019-02-14 14:57:44 -0500143
John Reck4f02bf42014-01-03 18:09:17 -0800144private:
145 RenderThread& mRenderThread;
146 CanvasContext* mContext;
147
John Reck668f0e32014-03-26 15:10:40 -0700148 DrawFrameTask mDrawFrameTask;
149
John Reck4f02bf42014-01-03 18:09:17 -0800150 void destroyContext();
151
John Reck4f02bf42014-01-03 18:09:17 -0800152 // 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_ */