John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 1 | /* |
| 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 Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 20 | #include <SkBitmap.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 21 | #include <cutils/compiler.h> |
John Reck | f8441e6 | 2017-10-23 13:10:41 -0700 | [diff] [blame] | 22 | #include <gui/Surface.h> |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 23 | #include <utils/Functor.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 24 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 25 | #include "../FrameMetricsObserver.h" |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 26 | #include "../IContextFactory.h" |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 27 | #include "DrawFrameTask.h" |
John Reck | f8441e6 | 2017-10-23 13:10:41 -0700 | [diff] [blame] | 28 | #include "SwapBehavior.h" |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 29 | #include "hwui/Bitmap.h" |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 30 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 31 | namespace android { |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 32 | class GraphicBuffer; |
| 33 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 34 | namespace uirenderer { |
| 35 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 36 | class DeferredLayerUpdater; |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 37 | class RenderNode; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 38 | class Rect; |
| 39 | |
| 40 | namespace renderthread { |
| 41 | |
John Reck | f8441e6 | 2017-10-23 13:10:41 -0700 | [diff] [blame] | 42 | class CanvasContext; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 43 | class RenderThread; |
| 44 | class RenderProxyBridge; |
| 45 | |
John Reck | a41f244 | 2016-04-07 16:36:57 -0700 | [diff] [blame] | 46 | namespace DumpFlags { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 47 | enum { |
| 48 | FrameStats = 1 << 0, |
| 49 | Reset = 1 << 1, |
| 50 | JankStats = 1 << 2, |
| 51 | }; |
John Reck | a41f244 | 2016-04-07 16:36:57 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 54 | /* |
| 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 | */ |
| 62 | class ANDROID_API RenderProxy { |
| 63 | public: |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 64 | ANDROID_API RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 65 | ANDROID_API virtual ~RenderProxy(); |
| 66 | |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 67 | // Won't take effect until next EGLSurface creation |
| 68 | ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior); |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 69 | ANDROID_API bool loadSystemProperties(); |
John Reck | b36016c | 2015-03-11 08:50:53 -0700 | [diff] [blame] | 70 | ANDROID_API void setName(const char* name); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 71 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 72 | ANDROID_API void initialize(const sp<Surface>& surface); |
| 73 | ANDROID_API void updateSurface(const sp<Surface>& surface); |
| 74 | ANDROID_API bool pauseSurface(const sp<Surface>& surface); |
John Reck | 8afcc76 | 2016-04-13 10:24:06 -0700 | [diff] [blame] | 75 | ANDROID_API void setStopped(bool stopped); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 76 | ANDROID_API void setup(float lightRadius, uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); |
Alan Viverette | 50210d9 | 2015-05-14 18:05:36 -0700 | [diff] [blame] | 77 | ANDROID_API void setLightCenter(const Vector3& lightCenter); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 78 | ANDROID_API void setOpaque(bool opaque); |
Romain Guy | 26a2b97 | 2017-04-17 09:39:51 -0700 | [diff] [blame] | 79 | ANDROID_API void setWideGamut(bool wideGamut); |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 80 | ANDROID_API int64_t* frameInfo(); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 81 | ANDROID_API int syncAndDrawFrame(); |
| 82 | ANDROID_API void destroy(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 83 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 84 | ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 85 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 86 | ANDROID_API DeferredLayerUpdater* createTextureLayer(); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 87 | ANDROID_API void buildLayer(RenderNode* node); |
John Reck | 3731dc2 | 2015-04-13 15:20:29 -0700 | [diff] [blame] | 88 | ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap); |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 89 | ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer); |
| 90 | ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer); |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 91 | ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 92 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 93 | ANDROID_API void destroyHardwareResources(); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 94 | ANDROID_API static void trimMemory(int level); |
Chris Craik | 2507c34 | 2015-05-04 14:36:49 -0700 | [diff] [blame] | 95 | ANDROID_API static void overrideProperty(const char* name, const char* value); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 96 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 97 | ANDROID_API void fence(); |
Thomas Buhot | c0a0e1a | 2016-01-18 10:31:58 +0100 | [diff] [blame] | 98 | ANDROID_API static void staticFence(); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 99 | ANDROID_API void stopDrawing(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 100 | ANDROID_API void notifyFramePending(); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 101 | |
John Reck | ba6adf6 | 2015-02-19 14:36:50 -0800 | [diff] [blame] | 102 | ANDROID_API void dumpProfileInfo(int fd, int dumpFlags); |
John Reck | 7f2e5e3 | 2015-05-05 11:00:53 -0700 | [diff] [blame] | 103 | // Not exported, only used for testing |
| 104 | void resetProfileInfo(); |
John Reck | f148076 | 2016-07-03 18:28:25 -0700 | [diff] [blame] | 105 | uint32_t frameTimePercentile(int p); |
Chris Craik | 2ae0733 | 2015-01-21 14:22:39 -0800 | [diff] [blame] | 106 | ANDROID_API static void dumpGraphicsMemory(int fd); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 107 | |
John Reck | df1742e | 2017-01-19 15:56:21 -0800 | [diff] [blame] | 108 | ANDROID_API static void rotateProcessStatsBuffer(); |
| 109 | ANDROID_API static void setProcessStatsBuffer(int fd); |
Tim Murray | 33eb07f | 2016-06-10 10:03:20 -0700 | [diff] [blame] | 110 | ANDROID_API int getRenderThreadTid(); |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 111 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 112 | ANDROID_API void serializeDisplayListTree(); |
| 113 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 114 | ANDROID_API void addRenderNode(RenderNode* node, bool placeFront); |
| 115 | ANDROID_API void removeRenderNode(RenderNode* node); |
| 116 | ANDROID_API void drawRenderNode(RenderNode* node); |
Skuhne | b816087 | 2015-09-22 09:51:39 -0700 | [diff] [blame] | 117 | ANDROID_API void setContentDrawBounds(int left, int top, int right, int bottom); |
Mihai Popa | 9568800 | 2018-02-23 16:10:11 +0000 | [diff] [blame] | 118 | ANDROID_API void setFrameCallback(std::function<void(int64_t)>&& callback); |
John Reck | 5b02c62 | 2018-05-17 10:44:00 -0700 | [diff] [blame] | 119 | ANDROID_API void setFrameCompleteCallback(std::function<void(int64_t)>&& callback); |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 120 | |
Andres Morales | 910beb8 | 2016-02-02 16:19:40 -0800 | [diff] [blame] | 121 | ANDROID_API void addFrameMetricsObserver(FrameMetricsObserver* observer); |
| 122 | ANDROID_API void removeFrameMetricsObserver(FrameMetricsObserver* observer); |
Andres Morales | 06f5bc7 | 2015-12-15 15:21:31 -0800 | [diff] [blame] | 123 | ANDROID_API long getDroppedFrameReportCount(); |
| 124 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 125 | ANDROID_API static int copySurfaceInto(sp<Surface>& surface, int left, int top, int right, |
| 126 | int bottom, SkBitmap* bitmap); |
sergeyv | ec4a4b1 | 2016-10-20 18:39:04 -0700 | [diff] [blame] | 127 | ANDROID_API static void prepareToDraw(Bitmap& bitmap); |
John Reck | 10dd058 | 2016-03-31 16:36:16 -0700 | [diff] [blame] | 128 | |
sergeyv | 694d499 | 2016-10-27 10:23:13 -0700 | [diff] [blame] | 129 | static sk_sp<Bitmap> allocateHardwareBitmap(SkBitmap& bitmap); |
sergeyv | 59eecb52 | 2016-11-17 17:54:57 -0800 | [diff] [blame] | 130 | |
| 131 | static int copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap); |
John Reck | 9a81487 | 2017-05-22 15:04:21 -0700 | [diff] [blame] | 132 | |
| 133 | static void onBitmapDestroyed(uint32_t pixelRefId); |
John Reck | a896306 | 2017-06-14 10:47:50 -0700 | [diff] [blame] | 134 | |
| 135 | ANDROID_API static void disableVsync(); |
Stan Iliev | 3310fb1 | 2017-03-23 16:56:51 -0400 | [diff] [blame] | 136 | |
| 137 | static void repackVectorDrawableAtlas(); |
| 138 | |
Stan Iliev | 6b894d7 | 2017-08-23 12:41:41 -0400 | [diff] [blame] | 139 | static void releaseVDAtlasEntries(); |
| 140 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 141 | private: |
| 142 | RenderThread& mRenderThread; |
| 143 | CanvasContext* mContext; |
| 144 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 145 | DrawFrameTask mDrawFrameTask; |
| 146 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 147 | void destroyContext(); |
| 148 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 149 | // Friend class to help with bridging |
| 150 | friend class RenderProxyBridge; |
| 151 | }; |
| 152 | |
| 153 | } /* namespace renderthread */ |
| 154 | } /* namespace uirenderer */ |
| 155 | } /* namespace android */ |
| 156 | #endif /* RENDERPROXY_H_ */ |