blob: 3197df3afa47f099e817c053eaf9641dd133444f [file] [log] [blame]
John Reck23b797a2014-01-03 18:08:34 -08001/*
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>
John Reck4f02bf42014-01-03 18:09:17 -080022#include <utils/Functor.h>
23
24#include "RenderTask.h"
25
26#define FUNCTOR_PROCESS_DELAY 4
John Reck23b797a2014-01-03 18:08:34 -080027
28namespace android {
29namespace uirenderer {
John Reck4f02bf42014-01-03 18:09:17 -080030
31class DisplayList;
32class OpenGLRenderer;
33class Rect;
34
John Reck23b797a2014-01-03 18:08:34 -080035namespace renderthread {
36
37class GlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080038class 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};
John Reck23b797a2014-01-03 18:08:34 -080051
52// This per-renderer class manages the bridge between the global EGL context
53// and the render surface.
54class CanvasContext {
55public:
John Reck4f02bf42014-01-03 18:09:17 -080056 CanvasContext(bool translucent);
57 ~CanvasContext();
John Reck23b797a2014-01-03 18:08:34 -080058
John Reck4f02bf42014-01-03 18:09:17 -080059 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();
John Reck23b797a2014-01-03 18:08:34 -080064
John Reck4f02bf42014-01-03 18:09:17 -080065 void attachFunctor(Functor* functor);
66 void detachFunctor(Functor* functor);
John Reck23b797a2014-01-03 18:08:34 -080067
John Reckfc53ef272014-02-11 10:40:25 -080068 void runWithGlContext(RenderTask* task);
69
John Reck23b797a2014-01-03 18:08:34 -080070private:
John Reck4f02bf42014-01-03 18:09:17 -080071 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);
John Reck23b797a2014-01-03 18:08:34 -080080
81 GlobalContext* mGlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080082 RenderThread& mRenderThread;
John Reck23b797a2014-01-03 18:08:34 -080083 EGLSurface mEglSurface;
84 bool mDirtyRegionsEnabled;
John Reck4f02bf42014-01-03 18:09:17 -080085
86 bool mOpaque;
87 OpenGLRenderer* mCanvas;
88 bool mHaveNewSurface;
89
90 bool mInvokeFunctorsPending;
91 InvokeFunctorsTask mInvokeFunctorsTask;
92
John Reck23b797a2014-01-03 18:08:34 -080093};
94
95} /* namespace renderthread */
96} /* namespace uirenderer */
97} /* namespace android */
98#endif /* CANVASCONTEXT_H_ */