CanvasContext.h revision fc53ef27793a39e9effd829e9cae02a9ca14147e
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 <utils/Functor.h> 23 24#include "RenderTask.h" 25 26#define FUNCTOR_PROCESS_DELAY 4 27 28namespace android { 29namespace uirenderer { 30 31class DisplayList; 32class OpenGLRenderer; 33class Rect; 34 35namespace renderthread { 36 37class GlobalContext; 38class CanvasContext; 39class RenderThread; 40 41class InvokeFunctorsTask : public RenderTask { 42public: 43 InvokeFunctorsTask(CanvasContext* context) 44 : mContext(context) {} 45 46 virtual void run(); 47 48private: 49 CanvasContext* mContext; 50}; 51 52// This per-renderer class manages the bridge between the global EGL context 53// and the render surface. 54class CanvasContext { 55public: 56 CanvasContext(bool translucent); 57 ~CanvasContext(); 58 59 bool initialize(EGLNativeWindowType window); 60 void updateSurface(EGLNativeWindowType window); 61 void setup(int width, int height); 62 void drawDisplayList(DisplayList* displayList, Rect* dirty); 63 void destroyCanvas(); 64 65 void attachFunctor(Functor* functor); 66 void detachFunctor(Functor* functor); 67 68 void runWithGlContext(RenderTask* task); 69 70private: 71 void setSurface(EGLNativeWindowType window); 72 void swapBuffers(); 73 void makeCurrent(); 74 75 friend class InvokeFunctorsTask; 76 void invokeFunctors(); 77 void handleFunctorStatus(int status, const Rect& redrawClip); 78 void removeFunctorsTask(); 79 void queueFunctorsTask(int delayMs = FUNCTOR_PROCESS_DELAY); 80 81 GlobalContext* mGlobalContext; 82 RenderThread& mRenderThread; 83 EGLSurface mEglSurface; 84 bool mDirtyRegionsEnabled; 85 86 bool mOpaque; 87 OpenGLRenderer* mCanvas; 88 bool mHaveNewSurface; 89 90 bool mInvokeFunctorsPending; 91 InvokeFunctorsTask mInvokeFunctorsTask; 92 93}; 94 95} /* namespace renderthread */ 96} /* namespace uirenderer */ 97} /* namespace android */ 98#endif /* CANVASCONTEXT_H_ */ 99