blob: 0934b981db914fcacdb8c93bb40a7ceffd20b42c [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>
John Reck19b6bcf2014-02-14 20:03:38 -080024#include <SkBitmap.h>
John Reck4f02bf42014-01-03 18:09:17 -080025#include <utils/Condition.h>
26#include <utils/Functor.h>
27#include <utils/Mutex.h>
28#include <utils/StrongPointer.h>
John Reck19b6bcf2014-02-14 20:03:38 -080029#include <utils/Vector.h>
John Reck4f02bf42014-01-03 18:09:17 -080030
31namespace android {
32namespace uirenderer {
33
John Reck19b6bcf2014-02-14 20:03:38 -080034class DeferredLayerUpdater;
John Reck4f02bf42014-01-03 18:09:17 -080035class DisplayList;
John Reck44fd8d22014-02-26 11:00:11 -080036class DisplayListData;
John Reck19b6bcf2014-02-14 20:03:38 -080037class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080038class Rect;
39
40namespace renderthread {
41
42class CanvasContext;
43class ErrorChannel;
44class RenderThread;
45class RenderProxyBridge;
46
47/*
48 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
49 * thread. It is important to note that RenderProxy may be deleted while it has
50 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
51 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
52 * references RenderProxy fields. This is safe as RenderProxy cannot
53 * be deleted if it is blocked inside a call.
54 */
55class ANDROID_API RenderProxy {
56public:
57 ANDROID_API RenderProxy(bool translucent);
58 ANDROID_API virtual ~RenderProxy();
59
60 ANDROID_API bool initialize(EGLNativeWindowType window);
61 ANDROID_API void updateSurface(EGLNativeWindowType window);
62 ANDROID_API void setup(int width, int height);
John Reck44fd8d22014-02-26 11:00:11 -080063 ANDROID_API void swapDisplayListData(DisplayList* displayList, DisplayListData* newData);
John Reck4f02bf42014-01-03 18:09:17 -080064 ANDROID_API void drawDisplayList(DisplayList* displayList,
65 int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
66 ANDROID_API void destroyCanvas();
67
68 ANDROID_API void attachFunctor(Functor* functor);
69 ANDROID_API void detachFunctor(Functor* functor);
70
John Reckfc53ef272014-02-11 10:40:25 -080071 ANDROID_API void runWithGlContext(RenderTask* task);
72
John Reck19b6bcf2014-02-14 20:03:38 -080073 ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height);
74 ANDROID_API DeferredLayerUpdater* createTextureLayer();
75 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
76 ANDROID_API void destroyLayer(DeferredLayerUpdater* layer);
77
John Reck4f02bf42014-01-03 18:09:17 -080078private:
79 RenderThread& mRenderThread;
80 CanvasContext* mContext;
81
82 Mutex mSyncMutex;
83 Condition mSyncCondition;
84
John Reck19b6bcf2014-02-14 20:03:38 -080085 Vector<DeferredLayerUpdater*> mLayers;
86
John Reck4f02bf42014-01-03 18:09:17 -080087 void destroyContext();
88
89 MethodInvokeRenderTask* createTask(RunnableMethod method);
90 void post(RenderTask* task);
91 void* postAndWait(MethodInvokeRenderTask* task);
92
93 // Friend class to help with bridging
94 friend class RenderProxyBridge;
95};
96
97} /* namespace renderthread */
98} /* namespace uirenderer */
99} /* namespace android */
100#endif /* RENDERPROXY_H_ */