blob: a112493ae39a71eac77a2346f930833008d7409b [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
John Reck668f0e32014-03-26 15:10:40 -070031#include "DrawFrameTask.h"
32
John Reck4f02bf42014-01-03 18:09:17 -080033namespace android {
34namespace uirenderer {
35
John Reck19b6bcf2014-02-14 20:03:38 -080036class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070037class RenderNode;
John Reck44fd8d22014-02-26 11:00:11 -080038class DisplayListData;
John Reck19b6bcf2014-02-14 20:03:38 -080039class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080040class 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
John Reckf7d9c1d2014-04-09 10:01:03 -070062 ANDROID_API bool initialize(const sp<ANativeWindow>& window);
63 ANDROID_API void updateSurface(const sp<ANativeWindow>& window);
64 ANDROID_API void pauseSurface(const sp<ANativeWindow>& window);
John Reck4f02bf42014-01-03 18:09:17 -080065 ANDROID_API void setup(int width, int height);
John Recke18264b2014-03-12 13:56:30 -070066 ANDROID_API void drawDisplayList(RenderNode* displayList,
John Reck4f02bf42014-01-03 18:09:17 -080067 int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
John Reckfae904d2014-04-14 11:01:57 -070068 ANDROID_API void destroyCanvasAndSurface();
John Reck4f02bf42014-01-03 18:09:17 -080069
John Reck0d1f6342014-03-28 20:30:27 -070070 ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck4f02bf42014-01-03 18:09:17 -080071
John Reckfc53ef272014-02-11 10:40:25 -080072 ANDROID_API void runWithGlContext(RenderTask* task);
73
John Reck19b6bcf2014-02-14 20:03:38 -080074 ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height);
75 ANDROID_API DeferredLayerUpdater* createTextureLayer();
76 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
77 ANDROID_API void destroyLayer(DeferredLayerUpdater* layer);
78
John Reck28ad7b52014-04-07 16:59:25 -070079 ANDROID_API void fence();
80
John Reck4f02bf42014-01-03 18:09:17 -080081private:
82 RenderThread& mRenderThread;
83 CanvasContext* mContext;
84
John Reck668f0e32014-03-26 15:10:40 -070085 DrawFrameTask mDrawFrameTask;
86
John Reck4f02bf42014-01-03 18:09:17 -080087 Mutex mSyncMutex;
88 Condition mSyncCondition;
89
John Reck4f02bf42014-01-03 18:09:17 -080090 void destroyContext();
91
John Reck4f02bf42014-01-03 18:09:17 -080092 void post(RenderTask* task);
93 void* postAndWait(MethodInvokeRenderTask* task);
94
95 // Friend class to help with bridging
96 friend class RenderProxyBridge;
97};
98
99} /* namespace renderthread */
100} /* namespace uirenderer */
101} /* namespace android */
102#endif /* RENDERPROXY_H_ */