blob: 113c5a85650c9c78eb6a75682ffc21feb96a8891 [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
65private:
66 RenderThread& mRenderThread;
67 CanvasContext* mContext;
68
69 Mutex mSyncMutex;
70 Condition mSyncCondition;
71
72 void destroyContext();
73
74 MethodInvokeRenderTask* createTask(RunnableMethod method);
75 void post(RenderTask* task);
76 void* postAndWait(MethodInvokeRenderTask* task);
77
78 // Friend class to help with bridging
79 friend class RenderProxyBridge;
80};
81
82} /* namespace renderthread */
83} /* namespace uirenderer */
84} /* namespace android */
85#endif /* RENDERPROXY_H_ */