blob: 1ad0c2dd7bcaee2f8621ff694d4342d02b5f73ee [file] [log] [blame]
John Reck4f02bf42014-01-03 18:09:17 -08001/*
2 * Copyright (C) 2013 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 RENDERPROXY_H_
18#define RENDERPROXY_H_
19
20#include "RenderTask.h"
21
22#include <cutils/compiler.h>
23#include <EGL/egl.h>
24#include <utils/Condition.h>
25#include <utils/Functor.h>
26#include <utils/Mutex.h>
27#include <utils/StrongPointer.h>
28
29namespace android {
30namespace uirenderer {
31
32class DisplayList;
33class Rect;
34
35namespace renderthread {
36
37class CanvasContext;
38class ErrorChannel;
39class RenderThread;
40class RenderProxyBridge;
41
42/*
43 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
44 * thread. It is important to note that RenderProxy may be deleted while it has
45 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
46 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
47 * references RenderProxy fields. This is safe as RenderProxy cannot
48 * be deleted if it is blocked inside a call.
49 */
50class ANDROID_API RenderProxy {
51public:
52 ANDROID_API RenderProxy(bool translucent);
53 ANDROID_API virtual ~RenderProxy();
54
55 ANDROID_API bool initialize(EGLNativeWindowType window);
56 ANDROID_API void updateSurface(EGLNativeWindowType window);
57 ANDROID_API void setup(int width, int height);
58 ANDROID_API void drawDisplayList(DisplayList* displayList,
59 int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
60 ANDROID_API void destroyCanvas();
61
62 ANDROID_API void attachFunctor(Functor* functor);
63 ANDROID_API void detachFunctor(Functor* functor);
64
John Reckfc53ef272014-02-11 10:40:25 -080065 ANDROID_API void runWithGlContext(RenderTask* task);
66
John Reck4f02bf42014-01-03 18:09:17 -080067private:
68 RenderThread& mRenderThread;
69 CanvasContext* mContext;
70
71 Mutex mSyncMutex;
72 Condition mSyncCondition;
73
74 void destroyContext();
75
76 MethodInvokeRenderTask* createTask(RunnableMethod method);
77 void post(RenderTask* task);
78 void* postAndWait(MethodInvokeRenderTask* task);
79
80 // Friend class to help with bridging
81 friend class RenderProxyBridge;
82};
83
84} /* namespace renderthread */
85} /* namespace uirenderer */
86} /* namespace android */
87#endif /* RENDERPROXY_H_ */