CanvasContext.h revision 4f02bf4eef6af47f35c70c4dda5b7b9523d89ca0
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
68private:
69    void setSurface(EGLNativeWindowType window);
70    void swapBuffers();
71    void makeCurrent();
72
73    friend class InvokeFunctorsTask;
74    void invokeFunctors();
75    void handleFunctorStatus(int status, const Rect& redrawClip);
76    void removeFunctorsTask();
77    void queueFunctorsTask(int delayMs = FUNCTOR_PROCESS_DELAY);
78
79    GlobalContext* mGlobalContext;
80    RenderThread& mRenderThread;
81    EGLSurface mEglSurface;
82    bool mDirtyRegionsEnabled;
83
84    bool mOpaque;
85    OpenGLRenderer* mCanvas;
86    bool mHaveNewSurface;
87
88    bool mInvokeFunctorsPending;
89    InvokeFunctorsTask mInvokeFunctorsTask;
90
91};
92
93} /* namespace renderthread */
94} /* namespace uirenderer */
95} /* namespace android */
96#endif /* CANVASCONTEXT_H_ */
97