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