CanvasContext.h revision fe5e7b7346a54537b980796ceeca66bfdbd05561
1/* 2 * Copyright (C) 2014 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 CANVASCONTEXT_H_ 18#define CANVASCONTEXT_H_ 19 20#include <cutils/compiler.h> 21#include <EGL/egl.h> 22#include <SkBitmap.h> 23#include <utils/Functor.h> 24#include <utils/Vector.h> 25 26#include "../DrawProfiler.h" 27#include "../RenderNode.h" 28#include "RenderTask.h" 29#include "RenderThread.h" 30 31#define FUNCTOR_PROCESS_DELAY 4 32 33namespace android { 34namespace uirenderer { 35 36class DeferredLayerUpdater; 37class OpenGLRenderer; 38class Rect; 39class Layer; 40 41namespace renderthread { 42 43class GlobalContext; 44 45// This per-renderer class manages the bridge between the global EGL context 46// and the render surface. 47class CanvasContext : public IFrameCallback { 48public: 49 CanvasContext(bool translucent, RenderNode* rootRenderNode); 50 virtual ~CanvasContext(); 51 52 bool initialize(ANativeWindow* window); 53 void updateSurface(ANativeWindow* window); 54 void pauseSurface(ANativeWindow* window); 55 void setup(int width, int height, const Vector3& lightCenter, float lightRadius); 56 void setOpaque(bool opaque); 57 void makeCurrent(); 58 void prepareDraw(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info); 59 void draw(Rect* dirty); 60 void destroyCanvasAndSurface(); 61 62 // IFrameCallback, Chroreographer-driven frame callback entry point 63 virtual void doFrame(); 64 65 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 66 67 void flushCaches(Caches::FlushMode flushMode); 68 69 void invokeFunctor(Functor* functor); 70 71 void runWithGlContext(RenderTask* task); 72 73 Layer* createRenderLayer(int width, int height); 74 Layer* createTextureLayer(); 75 76 ANDROID_API static void setTextureAtlas(const sp<GraphicBuffer>& buffer, 77 int64_t* map, size_t mapSize); 78 79 void notifyFramePending(); 80 81 DrawProfiler& profiler() { return mProfiler; } 82 83private: 84 friend class RegisterFrameCallbackTask; 85 86 void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters, TreeInfo& info); 87 void prepareTree(TreeInfo& info); 88 89 void setSurface(ANativeWindow* window); 90 void swapBuffers(); 91 void requireSurface(); 92 93 void requireGlContext(); 94 95 GlobalContext* mGlobalContext; 96 RenderThread& mRenderThread; 97 sp<ANativeWindow> mNativeWindow; 98 EGLSurface mEglSurface; 99 bool mDirtyRegionsEnabled; 100 101 bool mOpaque; 102 OpenGLRenderer* mCanvas; 103 bool mHaveNewSurface; 104 105 const sp<RenderNode> mRootRenderNode; 106 107 DrawProfiler mProfiler; 108}; 109 110} /* namespace renderthread */ 111} /* namespace uirenderer */ 112} /* namespace android */ 113#endif /* CANVASCONTEXT_H_ */ 114