blob: 969ad00d74436c7a886ad0964a969ae380e6ac84 [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>
John Reck1bcacfd2017-11-03 10:12:19 -070021#include <cutils/compiler.h>
John Reckf8441e62017-10-23 13:10:41 -070022#include <gui/Surface.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;
33
John Reck4f02bf42014-01-03 18:09:17 -080034namespace uirenderer {
35
John Reck19b6bcf2014-02-14 20:03:38 -080036class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070037class RenderNode;
John Reck4f02bf42014-01-03 18:09:17 -080038class Rect;
39
40namespace renderthread {
41
John Reckf8441e62017-10-23 13:10:41 -070042class CanvasContext;
John Reck4f02bf42014-01-03 18:09:17 -080043class RenderThread;
44class RenderProxyBridge;
45
John Recka41f2442016-04-07 16:36:57 -070046namespace DumpFlags {
John Reck1bcacfd2017-11-03 10:12:19 -070047enum {
48 FrameStats = 1 << 0,
49 Reset = 1 << 1,
50 JankStats = 1 << 2,
51};
John Recka41f2442016-04-07 16:36:57 -070052};
53
John Reck4f02bf42014-01-03 18:09:17 -080054/*
55 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
56 * thread. It is important to note that RenderProxy may be deleted while it has
57 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
58 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
59 * references RenderProxy fields. This is safe as RenderProxy cannot
60 * be deleted if it is blocked inside a call.
61 */
62class ANDROID_API RenderProxy {
63public:
Romain Guy26a2b972017-04-17 09:39:51 -070064 ANDROID_API RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080065 ANDROID_API virtual ~RenderProxy();
66
John Reck1125d1f2014-10-23 11:02:19 -070067 // Won't take effect until next EGLSurface creation
68 ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior);
John Recke4280ba2014-05-05 16:39:37 -070069 ANDROID_API bool loadSystemProperties();
John Reckb36016c2015-03-11 08:50:53 -070070 ANDROID_API void setName(const char* name);
John Reck18f16e62014-05-02 16:46:41 -070071
John Reckf6481082016-02-02 15:18:23 -080072 ANDROID_API void initialize(const sp<Surface>& surface);
Jorim Jaggi7823ee72018-07-17 15:24:16 +020073 ANDROID_API void allocateBuffers(const sp<Surface>& surface);
John Reckf6481082016-02-02 15:18:23 -080074 ANDROID_API void updateSurface(const sp<Surface>& surface);
75 ANDROID_API bool pauseSurface(const sp<Surface>& surface);
John Reck8afcc762016-04-13 10:24:06 -070076 ANDROID_API void setStopped(bool stopped);
John Reck1bcacfd2017-11-03 10:12:19 -070077 ANDROID_API void setup(float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
Alan Viverette50210d92015-05-14 18:05:36 -070078 ANDROID_API void setLightCenter(const Vector3& lightCenter);
John Reck63a06672014-05-07 13:45:54 -070079 ANDROID_API void setOpaque(bool opaque);
Romain Guy26a2b972017-04-17 09:39:51 -070080 ANDROID_API void setWideGamut(bool wideGamut);
John Reckba6adf62015-02-19 14:36:50 -080081 ANDROID_API int64_t* frameInfo();
John Reck2de950d2017-01-25 10:58:30 -080082 ANDROID_API int syncAndDrawFrame();
83 ANDROID_API void destroy();
John Reck4f02bf42014-01-03 18:09:17 -080084
John Reck3b202512014-06-23 13:13:08 -070085 ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck4f02bf42014-01-03 18:09:17 -080086
John Reck19b6bcf2014-02-14 20:03:38 -080087 ANDROID_API DeferredLayerUpdater* createTextureLayer();
John Reck2de950d2017-01-25 10:58:30 -080088 ANDROID_API void buildLayer(RenderNode* node);
John Reck3731dc22015-04-13 15:20:29 -070089 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
John Reckd72e0a32014-05-29 18:56:11 -070090 ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
91 ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
John Reck918ad522014-06-27 14:45:25 -070092 ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -080093
John Reck2de950d2017-01-25 10:58:30 -080094 ANDROID_API void destroyHardwareResources();
John Reckf47a5942014-06-30 16:20:04 -070095 ANDROID_API static void trimMemory(int level);
Chris Craik2507c342015-05-04 14:36:49 -070096 ANDROID_API static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -070097
John Reck28ad7b52014-04-07 16:59:25 -070098 ANDROID_API void fence();
John Recke4c1e6c2018-05-24 16:27:35 -070099 ANDROID_API static int maxTextureSize();
John Reckf47a5942014-06-30 16:20:04 -0700100 ANDROID_API void stopDrawing();
John Recka5dda642014-05-22 15:43:54 -0700101 ANDROID_API void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -0700102
John Reckba6adf62015-02-19 14:36:50 -0800103 ANDROID_API void dumpProfileInfo(int fd, int dumpFlags);
John Reck7f2e5e32015-05-05 11:00:53 -0700104 // Not exported, only used for testing
105 void resetProfileInfo();
John Reckf1480762016-07-03 18:28:25 -0700106 uint32_t frameTimePercentile(int p);
Chris Craik2ae07332015-01-21 14:22:39 -0800107 ANDROID_API static void dumpGraphicsMemory(int fd);
John Reckfe5e7b72014-05-23 17:42:28 -0700108
John Reckdf1742e2017-01-19 15:56:21 -0800109 ANDROID_API static void rotateProcessStatsBuffer();
110 ANDROID_API static void setProcessStatsBuffer(int fd);
Tim Murray33eb07f2016-06-10 10:03:20 -0700111 ANDROID_API int getRenderThreadTid();
John Reck3b202512014-06-23 13:13:08 -0700112
Skuhneea7a7fb2015-08-28 07:10:31 -0700113 ANDROID_API void addRenderNode(RenderNode* node, bool placeFront);
114 ANDROID_API void removeRenderNode(RenderNode* node);
115 ANDROID_API void drawRenderNode(RenderNode* node);
Skuhneb8160872015-09-22 09:51:39 -0700116 ANDROID_API void setContentDrawBounds(int left, int top, int right, int bottom);
Mihai Popa95688002018-02-23 16:10:11 +0000117 ANDROID_API void setFrameCallback(std::function<void(int64_t)>&& callback);
John Reckcc2eee82018-05-17 10:44:00 -0700118 ANDROID_API void setFrameCompleteCallback(std::function<void(int64_t)>&& callback);
Skuhneea7a7fb2015-08-28 07:10:31 -0700119
Andres Morales910beb82016-02-02 16:19:40 -0800120 ANDROID_API void addFrameMetricsObserver(FrameMetricsObserver* observer);
121 ANDROID_API void removeFrameMetricsObserver(FrameMetricsObserver* observer);
John Reck1a4a9812018-04-18 16:13:31 -0700122 ANDROID_API long getDroppedFrameReportCount();
Andres Morales06f5bc72015-12-15 15:21:31 -0800123
John Reck1bcacfd2017-11-03 10:12:19 -0700124 ANDROID_API static int copySurfaceInto(sp<Surface>& surface, int left, int top, int right,
125 int bottom, SkBitmap* bitmap);
sergeyvec4a4b12016-10-20 18:39:04 -0700126 ANDROID_API static void prepareToDraw(Bitmap& bitmap);
John Reck10dd0582016-03-31 16:36:16 -0700127
Stan Iliev1a025a72018-09-05 16:35:11 -0400128 static int copyHWBitmapInto(Bitmap* hwBitmap, SkBitmap* bitmap);
John Reck9a814872017-05-22 15:04:21 -0700129
130 static void onBitmapDestroyed(uint32_t pixelRefId);
John Recka8963062017-06-14 10:47:50 -0700131
132 ANDROID_API static void disableVsync();
Stan Iliev3310fb12017-03-23 16:56:51 -0400133
134 static void repackVectorDrawableAtlas();
135
Stan Iliev6b894d72017-08-23 12:41:41 -0400136 static void releaseVDAtlasEntries();
137
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 Reck4f02bf42014-01-03 18:09:17 -0800144 void destroyContext();
145
John Reck4f02bf42014-01-03 18:09:17 -0800146 // Friend class to help with bridging
147 friend class RenderProxyBridge;
148};
149
150} /* namespace renderthread */
151} /* namespace uirenderer */
152} /* namespace android */
153#endif /* RENDERPROXY_H_ */