RenderProxy.h revision 51f2d606dcbfba3cc5b03dfea37c1304b91c232f
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 31#include "../Caches.h" 32#include "../FrameMetricsObserver.h" 33#include "../IContextFactory.h" 34#include "CanvasContext.h" 35#include "DrawFrameTask.h" 36 37namespace android { 38namespace uirenderer { 39 40class DeferredLayerUpdater; 41class RenderNode; 42class DisplayList; 43class Layer; 44class Rect; 45class TreeObserver; 46 47namespace renderthread { 48 49class ErrorChannel; 50class RenderThread; 51class RenderProxyBridge; 52 53/* 54 * RenderProxy is strictly single threaded. All methods must be invoked on the owning 55 * thread. It is important to note that RenderProxy may be deleted while it has 56 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not 57 * reference RenderProxy or any of its fields. The exception here is that postAndWait() 58 * references RenderProxy fields. This is safe as RenderProxy cannot 59 * be deleted if it is blocked inside a call. 60 */ 61class ANDROID_API RenderProxy { 62public: 63 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode, IContextFactory* contextFactory); 64 ANDROID_API virtual ~RenderProxy(); 65 66 // Won't take effect until next EGLSurface creation 67 ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior); 68 ANDROID_API bool loadSystemProperties(); 69 ANDROID_API void setName(const char* name); 70 71 ANDROID_API void initialize(const sp<Surface>& surface); 72 ANDROID_API void updateSurface(const sp<Surface>& surface); 73 ANDROID_API bool pauseSurface(const sp<Surface>& surface); 74 ANDROID_API void setup(int width, int height, float lightRadius, 75 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha); 76 ANDROID_API void setLightCenter(const Vector3& lightCenter); 77 ANDROID_API void setOpaque(bool opaque); 78 ANDROID_API int64_t* frameInfo(); 79 ANDROID_API int syncAndDrawFrame(TreeObserver* observer); 80 ANDROID_API void destroy(TreeObserver* observer); 81 82 ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion); 83 84 ANDROID_API void runWithGlContext(RenderTask* task); 85 86 ANDROID_API DeferredLayerUpdater* createTextureLayer(); 87 ANDROID_API void buildLayer(RenderNode* node, TreeObserver* observer); 88 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap); 89 ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer); 90 ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer); 91 ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer); 92 93 ANDROID_API void destroyHardwareResources(TreeObserver* observer); 94 ANDROID_API static void trimMemory(int level); 95 ANDROID_API static void overrideProperty(const char* name, const char* value); 96 97 ANDROID_API void fence(); 98 ANDROID_API static void staticFence(); 99 ANDROID_API void stopDrawing(); 100 ANDROID_API void notifyFramePending(); 101 102 ANDROID_API void dumpProfileInfo(int fd, int dumpFlags); 103 // Not exported, only used for testing 104 void resetProfileInfo(); 105 ANDROID_API static void dumpGraphicsMemory(int fd); 106 107 ANDROID_API void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size); 108 ANDROID_API void setProcessStatsBuffer(int fd); 109 110 ANDROID_API void serializeDisplayListTree(); 111 112 ANDROID_API void addRenderNode(RenderNode* node, bool placeFront); 113 ANDROID_API void removeRenderNode(RenderNode* node); 114 ANDROID_API void drawRenderNode(RenderNode* node); 115 ANDROID_API void setContentDrawBounds(int left, int top, int right, int bottom); 116 117 ANDROID_API void addFrameMetricsObserver(FrameMetricsObserver* observer); 118 ANDROID_API void removeFrameMetricsObserver(FrameMetricsObserver* observer); 119 ANDROID_API long getDroppedFrameReportCount(); 120 121private: 122 RenderThread& mRenderThread; 123 CanvasContext* mContext; 124 125 DrawFrameTask mDrawFrameTask; 126 127 Mutex mSyncMutex; 128 Condition mSyncCondition; 129 130 void destroyContext(); 131 132 void post(RenderTask* task); 133 void* postAndWait(MethodInvokeRenderTask* task); 134 135 static void* staticPostAndWait(MethodInvokeRenderTask* task); 136 137 // Friend class to help with bridging 138 friend class RenderProxyBridge; 139}; 140 141} /* namespace renderthread */ 142} /* namespace uirenderer */ 143} /* namespace android */ 144#endif /* RENDERPROXY_H_ */ 145