CanvasContext.h revision 8e1f918738abf70a4dc86dbb12b386a9deea37f8
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 "RenderTask.h" 27 28#define FUNCTOR_PROCESS_DELAY 4 29 30namespace android { 31namespace uirenderer { 32 33class DeferredLayerUpdater; 34class RenderNode; 35class DisplayListData; 36class OpenGLRenderer; 37class Rect; 38class Layer; 39 40namespace renderthread { 41 42class GlobalContext; 43class CanvasContext; 44class RenderThread; 45 46class InvokeFunctorsTask : public RenderTask { 47public: 48 InvokeFunctorsTask(CanvasContext* context) 49 : mContext(context) {} 50 51 virtual void run(); 52 53private: 54 CanvasContext* mContext; 55}; 56 57// This per-renderer class manages the bridge between the global EGL context 58// and the render surface. 59class CanvasContext { 60public: 61 CanvasContext(bool translucent); 62 ~CanvasContext(); 63 64 bool initialize(EGLNativeWindowType window); 65 void updateSurface(EGLNativeWindowType window); 66 void pauseSurface(EGLNativeWindowType window); 67 void setup(int width, int height); 68 void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters); 69 void drawDisplayList(RenderNode* displayList, Rect* dirty); 70 void destroyCanvas(); 71 72 bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap); 73 74 void attachFunctor(Functor* functor); 75 void detachFunctor(Functor* functor); 76 void invokeFunctor(Functor* functor); 77 78 void runWithGlContext(RenderTask* task); 79 80 Layer* createRenderLayer(int width, int height); 81 Layer* createTextureLayer(); 82 83private: 84 void setSurface(EGLNativeWindowType window); 85 void swapBuffers(); 86 void requireSurface(); 87 88 friend class InvokeFunctorsTask; 89 void invokeFunctors(); 90 void removeFunctorsTask(); 91 void queueFunctorsTask(int delayMs = FUNCTOR_PROCESS_DELAY); 92 93 void requireGlContext(); 94 95 GlobalContext* mGlobalContext; 96 RenderThread& mRenderThread; 97 EGLSurface mEglSurface; 98 bool mDirtyRegionsEnabled; 99 100 bool mOpaque; 101 OpenGLRenderer* mCanvas; 102 bool mHaveNewSurface; 103 104 bool mInvokeFunctorsPending; 105 InvokeFunctorsTask mInvokeFunctorsTask; 106 107}; 108 109} /* namespace renderthread */ 110} /* namespace uirenderer */ 111} /* namespace android */ 112#endif /* CANVASCONTEXT_H_ */ 113