RenderProxy.h revision e2c455264351964bf1ae78da2256c17258f0d3ea
1/*
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 <SkBitmap.h>
25#include <utils/Condition.h>
26#include <utils/Functor.h>
27#include <utils/Mutex.h>
28#include <utils/StrongPointer.h>
29#include <utils/Vector.h>
30
31#include "DrawFrameTask.h"
32
33namespace android {
34namespace uirenderer {
35
36class DeferredLayerUpdater;
37class RenderNode;
38class DisplayListData;
39class Layer;
40class Rect;
41
42namespace renderthread {
43
44class CanvasContext;
45class ErrorChannel;
46class RenderThread;
47class RenderProxyBridge;
48
49/*
50 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
51 * thread. It is important to note that RenderProxy may be deleted while it has
52 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
53 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
54 * references RenderProxy fields. This is safe as RenderProxy cannot
55 * be deleted if it is blocked inside a call.
56 */
57class ANDROID_API RenderProxy {
58public:
59    ANDROID_API RenderProxy(bool translucent);
60    ANDROID_API virtual ~RenderProxy();
61
62    ANDROID_API bool initialize(EGLNativeWindowType window);
63    ANDROID_API void updateSurface(EGLNativeWindowType window);
64    ANDROID_API void setup(int width, int height);
65    ANDROID_API void setDisplayListData(RenderNode* renderNode, DisplayListData* newData);
66    ANDROID_API void drawDisplayList(RenderNode* displayList,
67            int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
68    ANDROID_API void destroyCanvas();
69
70    ANDROID_API void attachFunctor(Functor* functor);
71    ANDROID_API void detachFunctor(Functor* functor);
72    ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion);
73
74    ANDROID_API void runWithGlContext(RenderTask* task);
75
76    ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height);
77    ANDROID_API DeferredLayerUpdater* createTextureLayer();
78    ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
79    ANDROID_API void destroyLayer(DeferredLayerUpdater* layer);
80
81    ANDROID_API void fence();
82
83private:
84    RenderThread& mRenderThread;
85    CanvasContext* mContext;
86
87    DrawFrameTask mDrawFrameTask;
88
89    Mutex mSyncMutex;
90    Condition mSyncCondition;
91
92    void destroyContext();
93
94    void post(RenderTask* task);
95    void* postAndWait(MethodInvokeRenderTask* task);
96
97    // Friend class to help with bridging
98    friend class RenderProxyBridge;
99};
100
101} /* namespace renderthread */
102} /* namespace uirenderer */
103} /* namespace android */
104#endif /* RENDERPROXY_H_ */
105