RenderProxy.h revision e4280baaa709c74d86cf6a389a4674ca665f5af6
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/Timers.h> 29#include <utils/StrongPointer.h> 30#include <utils/Vector.h> 31 32#include "DrawFrameTask.h" 33 34namespace android { 35namespace uirenderer { 36 37class DeferredLayerUpdater; 38class RenderNode; 39class DisplayListData; 40class Layer; 41class Rect; 42 43namespace renderthread { 44 45class CanvasContext; 46class ErrorChannel; 47class RenderThread; 48class 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 */ 58class ANDROID_API RenderProxy { 59public: 60 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode); 61 ANDROID_API virtual ~RenderProxy(); 62 63 ANDROID_API void setFrameInterval(nsecs_t frameIntervalNanos); 64 ANDROID_API bool loadSystemProperties(); 65 66 ANDROID_API bool initialize(const sp<ANativeWindow>& window); 67 ANDROID_API void updateSurface(const sp<ANativeWindow>& window); 68 ANDROID_API void pauseSurface(const sp<ANativeWindow>& window); 69 ANDROID_API void setup(int width, int height); 70 ANDROID_API int syncAndDrawFrame(nsecs_t frameTimeNanos, 71 int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom); 72 ANDROID_API void destroyCanvasAndSurface(); 73 74 ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion); 75 76 ANDROID_API void runWithGlContext(RenderTask* task); 77 78 ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height); 79 ANDROID_API DeferredLayerUpdater* createTextureLayer(); 80 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 81 ANDROID_API void destroyLayer(DeferredLayerUpdater* layer); 82 83 ANDROID_API void fence(); 84 85private: 86 RenderThread& mRenderThread; 87 CanvasContext* mContext; 88 89 DrawFrameTask mDrawFrameTask; 90 91 Mutex mSyncMutex; 92 Condition mSyncCondition; 93 94 void destroyContext(); 95 96 void post(RenderTask* task); 97 void* postAndWait(MethodInvokeRenderTask* task); 98 99 // Friend class to help with bridging 100 friend class RenderProxyBridge; 101}; 102 103} /* namespace renderthread */ 104} /* namespace uirenderer */ 105} /* namespace android */ 106#endif /* RENDERPROXY_H_ */ 107