blob: 2daa9051ca1e9805694579d1e5b0f98de481ae1e [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
68private:
John Reck4f02bf42014-01-03 18:09:17 -080069 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);
John Reck23b797a2014-01-03 18:08:34 -080078
79 GlobalContext* mGlobalContext;
John Reck4f02bf42014-01-03 18:09:17 -080080 RenderThread& mRenderThread;
John Reck23b797a2014-01-03 18:08:34 -080081 EGLSurface mEglSurface;
82 bool mDirtyRegionsEnabled;
John Reck4f02bf42014-01-03 18:09:17 -080083
84 bool mOpaque;
85 OpenGLRenderer* mCanvas;
86 bool mHaveNewSurface;
87
88 bool mInvokeFunctorsPending;
89 InvokeFunctorsTask mInvokeFunctorsTask;
90
John Reck23b797a2014-01-03 18:08:34 -080091};
92
93} /* namespace renderthread */
94} /* namespace uirenderer */
95} /* namespace android */
96#endif /* CANVASCONTEXT_H_ */