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