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 | |
| 20 | #include "RenderTask.h" |
| 21 | |
| 22 | #include <cutils/compiler.h> |
| 23 | #include <EGL/egl.h> |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 24 | #include <SkBitmap.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 25 | #include <utils/Condition.h> |
| 26 | #include <utils/Functor.h> |
| 27 | #include <utils/Mutex.h> |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 28 | #include <utils/Timers.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 29 | #include <utils/StrongPointer.h> |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 30 | #include <utils/Vector.h> |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 31 | |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 32 | #include "../Caches.h" |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 33 | #include "../IContextFactory.h" |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 34 | #include "CanvasContext.h" |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 35 | #include "DrawFrameTask.h" |
| 36 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | namespace uirenderer { |
| 39 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 40 | class DeferredLayerUpdater; |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 41 | class RenderNode; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 42 | class DisplayListData; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 43 | class Layer; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 44 | class Rect; |
| 45 | |
| 46 | namespace renderthread { |
| 47 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 48 | class ErrorChannel; |
| 49 | class RenderThread; |
| 50 | class RenderProxyBridge; |
| 51 | |
| 52 | /* |
| 53 | * RenderProxy is strictly single threaded. All methods must be invoked on the owning |
| 54 | * thread. It is important to note that RenderProxy may be deleted while it has |
| 55 | * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not |
| 56 | * reference RenderProxy or any of its fields. The exception here is that postAndWait() |
| 57 | * references RenderProxy fields. This is safe as RenderProxy cannot |
| 58 | * be deleted if it is blocked inside a call. |
| 59 | */ |
| 60 | class ANDROID_API RenderProxy { |
| 61 | public: |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 62 | ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode, IContextFactory* contextFactory); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 63 | ANDROID_API virtual ~RenderProxy(); |
| 64 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 65 | ANDROID_API void setFrameInterval(nsecs_t frameIntervalNanos); |
John Reck | 1125d1f | 2014-10-23 11:02:19 -0700 | [diff] [blame] | 66 | // Won't take effect until next EGLSurface creation |
| 67 | ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior); |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 68 | ANDROID_API bool loadSystemProperties(); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 69 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 70 | ANDROID_API bool initialize(const sp<ANativeWindow>& window); |
| 71 | ANDROID_API void updateSurface(const sp<ANativeWindow>& window); |
John Reck | 01a5ea3 | 2014-12-03 13:01:07 -0800 | [diff] [blame] | 72 | ANDROID_API bool pauseSurface(const sp<ANativeWindow>& window); |
Chris Craik | 058fc64 | 2014-07-23 18:19:28 -0700 | [diff] [blame] | 73 | ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius, |
| 74 | uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 75 | ANDROID_API void setOpaque(bool opaque); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 76 | ANDROID_API int syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 77 | float density); |
John Reck | 17035b0 | 2014-09-03 07:39:53 -0700 | [diff] [blame] | 78 | ANDROID_API void destroy(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 79 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 80 | ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 81 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 82 | ANDROID_API void runWithGlContext(RenderTask* task); |
| 83 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 84 | ANDROID_API DeferredLayerUpdater* createTextureLayer(); |
John Reck | 3e82495 | 2014-08-20 10:08:39 -0700 | [diff] [blame] | 85 | ANDROID_API void buildLayer(RenderNode* node); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 86 | ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); |
John Reck | d72e0a3 | 2014-05-29 18:56:11 -0700 | [diff] [blame] | 87 | ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer); |
| 88 | ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer); |
John Reck | 918ad52 | 2014-06-27 14:45:25 -0700 | [diff] [blame] | 89 | ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 90 | |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 91 | ANDROID_API void destroyHardwareResources(); |
| 92 | ANDROID_API static void trimMemory(int level); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 93 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 94 | ANDROID_API void fence(); |
John Reck | f47a594 | 2014-06-30 16:20:04 -0700 | [diff] [blame] | 95 | ANDROID_API void stopDrawing(); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 96 | ANDROID_API void notifyFramePending(); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 97 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 98 | ANDROID_API void dumpProfileInfo(int fd); |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 99 | ANDROID_API static void outputLogBuffer(int fd); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 100 | |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 101 | ANDROID_API void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size); |
| 102 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 103 | private: |
| 104 | RenderThread& mRenderThread; |
| 105 | CanvasContext* mContext; |
| 106 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 107 | DrawFrameTask mDrawFrameTask; |
| 108 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 109 | Mutex mSyncMutex; |
| 110 | Condition mSyncCondition; |
| 111 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 112 | void destroyContext(); |
| 113 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 114 | void post(RenderTask* task); |
| 115 | void* postAndWait(MethodInvokeRenderTask* task); |
| 116 | |
John Reck | 0e89e2b | 2014-10-31 14:49:06 -0700 | [diff] [blame] | 117 | static void* staticPostAndWait(MethodInvokeRenderTask* task); |
| 118 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 119 | // Friend class to help with bridging |
| 120 | friend class RenderProxyBridge; |
| 121 | }; |
| 122 | |
| 123 | } /* namespace renderthread */ |
| 124 | } /* namespace uirenderer */ |
| 125 | } /* namespace android */ |
| 126 | #endif /* RENDERPROXY_H_ */ |