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