blob: 8aeb264e15d0a6b4f67c44eb422912ee59e820fe [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>
John Reck18f16e62014-05-02 16:46:41 -070028#include <utils/Timers.h>
John Reck4f02bf42014-01-03 18:09:17 -080029#include <utils/StrongPointer.h>
John Reck19b6bcf2014-02-14 20:03:38 -080030#include <utils/Vector.h>
John Reck4f02bf42014-01-03 18:09:17 -080031
John Reck668f0e32014-03-26 15:10:40 -070032#include "DrawFrameTask.h"
33
John Reck4f02bf42014-01-03 18:09:17 -080034namespace android {
35namespace uirenderer {
36
John Reck19b6bcf2014-02-14 20:03:38 -080037class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070038class RenderNode;
John Reck44fd8d22014-02-26 11:00:11 -080039class DisplayListData;
John Reck19b6bcf2014-02-14 20:03:38 -080040class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080041class Rect;
42
43namespace renderthread {
44
45class CanvasContext;
46class ErrorChannel;
47class RenderThread;
48class RenderProxyBridge;
49
50/*
51 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
52 * thread. It is important to note that RenderProxy may be deleted while it has
53 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
54 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
55 * references RenderProxy fields. This is safe as RenderProxy cannot
56 * be deleted if it is blocked inside a call.
57 */
58class ANDROID_API RenderProxy {
59public:
John Recke45b1fd2014-04-15 09:50:16 -070060 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode);
John Reck4f02bf42014-01-03 18:09:17 -080061 ANDROID_API virtual ~RenderProxy();
62
John Reck18f16e62014-05-02 16:46:41 -070063 ANDROID_API void setFrameInterval(nsecs_t frameIntervalNanos);
John Recke4280ba2014-05-05 16:39:37 -070064 ANDROID_API bool loadSystemProperties();
John Reck18f16e62014-05-02 16:46:41 -070065
John Reckf7d9c1d2014-04-09 10:01:03 -070066 ANDROID_API bool initialize(const sp<ANativeWindow>& window);
67 ANDROID_API void updateSurface(const sp<ANativeWindow>& window);
68 ANDROID_API void pauseSurface(const sp<ANativeWindow>& window);
Chris Craik797b95b22014-05-20 18:10:25 -070069 ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius);
John Reck63a06672014-05-07 13:45:54 -070070 ANDROID_API void setOpaque(bool opaque);
John Reckf9be7792014-05-02 18:21:16 -070071 ANDROID_API int syncAndDrawFrame(nsecs_t frameTimeNanos,
John Reck4f02bf42014-01-03 18:09:17 -080072 int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom);
John Reckfae904d2014-04-14 11:01:57 -070073 ANDROID_API void destroyCanvasAndSurface();
John Reck4f02bf42014-01-03 18:09:17 -080074
John Reck0d1f6342014-03-28 20:30:27 -070075 ANDROID_API void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck4f02bf42014-01-03 18:09:17 -080076
John Reckfc53ef272014-02-11 10:40:25 -080077 ANDROID_API void runWithGlContext(RenderTask* task);
78
John Reck19b6bcf2014-02-14 20:03:38 -080079 ANDROID_API DeferredLayerUpdater* createDisplayListLayer(int width, int height);
80 ANDROID_API DeferredLayerUpdater* createTextureLayer();
81 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
82 ANDROID_API void destroyLayer(DeferredLayerUpdater* layer);
83
John Reck28ad7b52014-04-07 16:59:25 -070084 ANDROID_API void fence();
John Recka5dda642014-05-22 15:43:54 -070085 ANDROID_API void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -070086
John Reck4f02bf42014-01-03 18:09:17 -080087private:
88 RenderThread& mRenderThread;
89 CanvasContext* mContext;
90
John Reck668f0e32014-03-26 15:10:40 -070091 DrawFrameTask mDrawFrameTask;
92
John Reck4f02bf42014-01-03 18:09:17 -080093 Mutex mSyncMutex;
94 Condition mSyncCondition;
95
John Reck4f02bf42014-01-03 18:09:17 -080096 void destroyContext();
97
John Reck4f02bf42014-01-03 18:09:17 -080098 void post(RenderTask* task);
99 void* postAndWait(MethodInvokeRenderTask* task);
100
101 // Friend class to help with bridging
102 friend class RenderProxyBridge;
103};
104
105} /* namespace renderthread */
106} /* namespace uirenderer */
107} /* namespace android */
108#endif /* RENDERPROXY_H_ */