RenderProxy.h revision f47a594f5250b1914c36423ee6b371f0b8db09d0
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 "../Caches.h" 33#include "DrawFrameTask.h" 34 35namespace android { 36namespace uirenderer { 37 38class DeferredLayerUpdater; 39class RenderNode; 40class DisplayListData; 41class Layer; 42class Rect; 43 44namespace renderthread { 45 46class CanvasContext; 47class ErrorChannel; 48class RenderThread; 49class RenderProxyBridge; 50 51/* 52 * RenderProxy is strictly single threaded. All methods must be invoked on the owning 53 * thread. It is important to note that RenderProxy may be deleted while it has 54 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not 55 * reference RenderProxy or any of its fields. The exception here is that postAndWait() 56 * references RenderProxy fields. This is safe as RenderProxy cannot 57 * be deleted if it is blocked inside a call. 58 */ 59class ANDROID_API RenderProxy { 60public: 61 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode); 62 ANDROID_API virtual ~RenderProxy(); 63 64 ANDROID_API void setFrameInterval(nsecs_t frameIntervalNanos); 65 ANDROID_API bool loadSystemProperties(); 66 67 ANDROID_API bool initialize(const sp<ANativeWindow>& window); 68 ANDROID_API void updateSurface(const sp<ANativeWindow>& window); 69 ANDROID_API void pauseSurface(const sp<ANativeWindow>& window); 70 ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius); 71 ANDROID_API void setOpaque(bool opaque); 72 ANDROID_API int syncAndDrawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos, 73 float density); 74 ANDROID_API void destroyCanvasAndSurface(); 75 76 ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion); 77 78 ANDROID_API void runWithGlContext(RenderTask* task); 79 80 static void enqueueDestroyLayer(Layer* layer); 81 ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height); 82 ANDROID_API DeferredLayerUpdater* createTextureLayer(); 83 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 84 ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer); 85 ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer); 86 ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer); 87 88 ANDROID_API void destroyHardwareResources(); 89 ANDROID_API static void trimMemory(int level); 90 91 ANDROID_API void fence(); 92 ANDROID_API void stopDrawing(); 93 ANDROID_API void notifyFramePending(); 94 95 ANDROID_API void dumpProfileInfo(int fd); 96 97 ANDROID_API void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size); 98 99private: 100 RenderThread& mRenderThread; 101 CanvasContext* mContext; 102 103 DrawFrameTask mDrawFrameTask; 104 105 Mutex mSyncMutex; 106 Condition mSyncCondition; 107 108 void destroyContext(); 109 110 void post(RenderTask* task); 111 void* postAndWait(MethodInvokeRenderTask* task); 112 113 // Friend class to help with bridging 114 friend class RenderProxyBridge; 115}; 116 117} /* namespace renderthread */ 118} /* namespace uirenderer */ 119} /* namespace android */ 120#endif /* RENDERPROXY_H_ */ 121