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