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 | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 32 | #include "DrawFrameTask.h" |
| 33 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 34 | namespace android { |
| 35 | namespace uirenderer { |
| 36 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 37 | class DeferredLayerUpdater; |
John Reck | e18264b | 2014-03-12 13:56:30 -0700 | [diff] [blame] | 38 | class RenderNode; |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 39 | class DisplayListData; |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 40 | class Layer; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 41 | class Rect; |
| 42 | |
| 43 | namespace renderthread { |
| 44 | |
| 45 | class CanvasContext; |
| 46 | class ErrorChannel; |
| 47 | class RenderThread; |
| 48 | class RenderProxyBridge; |
| 49 | |
| 50 | /* |
| 51 | * RenderProxy is strictly single threaded. All methods must be invoked on the owning |
| 52 | * thread. It is important to note that RenderProxy may be deleted while it has |
| 53 | * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not |
| 54 | * reference RenderProxy or any of its fields. The exception here is that postAndWait() |
| 55 | * references RenderProxy fields. This is safe as RenderProxy cannot |
| 56 | * be deleted if it is blocked inside a call. |
| 57 | */ |
| 58 | class ANDROID_API RenderProxy { |
| 59 | public: |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 60 | ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 61 | ANDROID_API virtual ~RenderProxy(); |
| 62 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame^] | 63 | ANDROID_API void setFrameInterval(nsecs_t frameIntervalNanos); |
| 64 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 65 | ANDROID_API bool initialize(const sp<ANativeWindow>& window); |
| 66 | ANDROID_API void updateSurface(const sp<ANativeWindow>& window); |
| 67 | ANDROID_API void pauseSurface(const sp<ANativeWindow>& window); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 68 | ANDROID_API void setup(int width, int height); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame^] | 69 | ANDROID_API void syncAndDrawFrame(nsecs_t frameTimeNanos, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 70 | int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom); |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 71 | ANDROID_API void destroyCanvasAndSurface(); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 72 | |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 73 | ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 74 | |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 75 | ANDROID_API void runWithGlContext(RenderTask* task); |
| 76 | |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 77 | ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height); |
| 78 | ANDROID_API DeferredLayerUpdater* createTextureLayer(); |
| 79 | ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); |
| 80 | ANDROID_API void destroyLayer(DeferredLayerUpdater* layer); |
| 81 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 82 | ANDROID_API void fence(); |
| 83 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 84 | private: |
| 85 | RenderThread& mRenderThread; |
| 86 | CanvasContext* mContext; |
| 87 | |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 88 | DrawFrameTask mDrawFrameTask; |
| 89 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 90 | Mutex mSyncMutex; |
| 91 | Condition mSyncCondition; |
| 92 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 93 | void destroyContext(); |
| 94 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 95 | void post(RenderTask* task); |
| 96 | void* postAndWait(MethodInvokeRenderTask* task); |
| 97 | |
| 98 | // Friend class to help with bridging |
| 99 | friend class RenderProxyBridge; |
| 100 | }; |
| 101 | |
| 102 | } /* namespace renderthread */ |
| 103 | } /* namespace uirenderer */ |
| 104 | } /* namespace android */ |
| 105 | #endif /* RENDERPROXY_H_ */ |