summaryrefslogtreecommitdiffstats
path: root/libs/hwui/renderthread/RenderProxy.h
blob: 113c5a85650c9c78eb6a75682ffc21feb96a8891 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef RENDERPROXY_H_
#define RENDERPROXY_H_

#include "RenderTask.h"

#include <cutils/compiler.h>
#include <EGL/egl.h>
#include <utils/Condition.h>
#include <utils/Functor.h>
#include <utils/Mutex.h>
#include <utils/StrongPointer.h>

namespace android {
namespace uirenderer {

class DisplayList;
class Rect;

namespace renderthread {

class CanvasContext;
class ErrorChannel;
class RenderThread;
class RenderProxyBridge;

/*
 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
 * thread. It is important to note that RenderProxy may be deleted while it has
 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
 * references RenderProxy fields. This is safe as RenderProxy cannot
 * be deleted if it is blocked inside a call.
 */
class ANDROID_API RenderProxy {
public:
    ANDROID_API RenderProxy(bool translucent);
    ANDROID_API virtual ~RenderProxy();

    ANDROID_API bool initialize(EGLNativeWindowType window);
    ANDROID_API void updateSurface(EGLNativeWindowType window);
    ANDROID_API void setup(int width, int height);
    ANDROID_API void drawDisplayList(DisplayList* displayList,
            int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
    ANDROID_API void destroyCanvas();

    ANDROID_API void attachFunctor(Functor* functor);
    ANDROID_API void detachFunctor(Functor* functor);

private:
    RenderThread& mRenderThread;
    CanvasContext* mContext;

    Mutex mSyncMutex;
    Condition mSyncCondition;

    void destroyContext();

    MethodInvokeRenderTask* createTask(RunnableMethod method);
    void post(RenderTask* task);
    void* postAndWait(MethodInvokeRenderTask* task);

    // Friend class to help with bridging
    friend class RenderProxyBridge;
};

} /* namespace renderthread */
} /* namespace uirenderer */
} /* namespace android */
#endif /* RENDERPROXY_H_ */