CanvasContext.h revision d3d8dafc2f61fb118c060720b52684c59303f3db
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
46// This per-renderer class manages the bridge between the global EGL context
47// and the render surface.
48class CanvasContext {
49public:
50    CanvasContext(bool translucent);
51    ~CanvasContext();
52
53    bool initialize(EGLNativeWindowType window);
54    void updateSurface(EGLNativeWindowType window);
55    void pauseSurface(EGLNativeWindowType window);
56    void setup(int width, int height);
57    void processLayerUpdates(const Vector<DeferredLayerUpdater*>* layerUpdaters, bool* hasFunctors);
58    void drawDisplayList(RenderNode* displayList, Rect* dirty);
59    void destroyCanvas();
60
61    bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
62
63    void invokeFunctor(Functor* functor);
64
65    void runWithGlContext(RenderTask* task);
66
67    Layer* createRenderLayer(int width, int height);
68    Layer* createTextureLayer();
69
70private:
71    void setSurface(EGLNativeWindowType window);
72    void swapBuffers();
73    void requireSurface();
74
75    void requireGlContext();
76
77    GlobalContext* mGlobalContext;
78    RenderThread& mRenderThread;
79    EGLSurface mEglSurface;
80    bool mDirtyRegionsEnabled;
81
82    bool mOpaque;
83    OpenGLRenderer* mCanvas;
84    bool mHaveNewSurface;
85};
86
87} /* namespace renderthread */
88} /* namespace uirenderer */
89} /* namespace android */
90#endif /* CANVASCONTEXT_H_ */
91