blob: 057fde4d02e4c7478cca01b0f18718950529fb91 [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 Recke1628b72014-05-23 15:11:19 -070032#include "../Caches.h"
John Reck119907c2014-08-14 09:02:01 -070033#include "../IContextFactory.h"
John Reck1125d1f2014-10-23 11:02:19 -070034#include "CanvasContext.h"
John Reck668f0e32014-03-26 15:10:40 -070035#include "DrawFrameTask.h"
36
John Reck4f02bf42014-01-03 18:09:17 -080037namespace android {
38namespace uirenderer {
39
John Reck19b6bcf2014-02-14 20:03:38 -080040class DeferredLayerUpdater;
John Recke18264b2014-03-12 13:56:30 -070041class RenderNode;
John Reck44fd8d22014-02-26 11:00:11 -080042class DisplayListData;
John Reck19b6bcf2014-02-14 20:03:38 -080043class Layer;
John Reck4f02bf42014-01-03 18:09:17 -080044class Rect;
45
46namespace renderthread {
47
John Reck4f02bf42014-01-03 18:09:17 -080048class ErrorChannel;
49class RenderThread;
50class RenderProxyBridge;
51
52/*
53 * RenderProxy is strictly single threaded. All methods must be invoked on the owning
54 * thread. It is important to note that RenderProxy may be deleted while it has
55 * tasks post()'d as a result. Therefore any RenderTask that is post()'d must not
56 * reference RenderProxy or any of its fields. The exception here is that postAndWait()
57 * references RenderProxy fields. This is safe as RenderProxy cannot
58 * be deleted if it is blocked inside a call.
59 */
60class ANDROID_API RenderProxy {
61public:
John Reck119907c2014-08-14 09:02:01 -070062 ANDROID_API RenderProxy(bool translucent, RenderNode* rootNode, IContextFactory* contextFactory);
John Reck4f02bf42014-01-03 18:09:17 -080063 ANDROID_API virtual ~RenderProxy();
64
John Reck1125d1f2014-10-23 11:02:19 -070065 // Won't take effect until next EGLSurface creation
66 ANDROID_API void setSwapBehavior(SwapBehavior swapBehavior);
John Recke4280ba2014-05-05 16:39:37 -070067 ANDROID_API bool loadSystemProperties();
John Reckb36016c2015-03-11 08:50:53 -070068 ANDROID_API void setName(const char* name);
John Reck18f16e62014-05-02 16:46:41 -070069
John Reckf7d9c1d2014-04-09 10:01:03 -070070 ANDROID_API bool initialize(const sp<ANativeWindow>& window);
71 ANDROID_API void updateSurface(const sp<ANativeWindow>& window);
John Reck01a5ea32014-12-03 13:01:07 -080072 ANDROID_API bool pauseSurface(const sp<ANativeWindow>& window);
Chris Craik058fc642014-07-23 18:19:28 -070073 ANDROID_API void setup(int width, int height, const Vector3& lightCenter, float lightRadius,
John Reckb36016c2015-03-11 08:50:53 -070074 uint8_t ambientShadowAlpha, uint8_t spotShadowAlpha);
John Reck63a06672014-05-07 13:45:54 -070075 ANDROID_API void setOpaque(bool opaque);
John Reckba6adf62015-02-19 14:36:50 -080076 ANDROID_API int64_t* frameInfo();
77 ANDROID_API int syncAndDrawFrame();
John Reck17035b02014-09-03 07:39:53 -070078 ANDROID_API void destroy();
John Reck4f02bf42014-01-03 18:09:17 -080079
John Reck3b202512014-06-23 13:13:08 -070080 ANDROID_API static void invokeFunctor(Functor* functor, bool waitForCompletion);
John Reck4f02bf42014-01-03 18:09:17 -080081
John Reckfc53ef272014-02-11 10:40:25 -080082 ANDROID_API void runWithGlContext(RenderTask* task);
83
John Reck19b6bcf2014-02-14 20:03:38 -080084 ANDROID_API DeferredLayerUpdater* createTextureLayer();
John Reck3e824952014-08-20 10:08:39 -070085 ANDROID_API void buildLayer(RenderNode* node);
John Reck3731dc22015-04-13 15:20:29 -070086 ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap& bitmap);
John Reckd72e0a32014-05-29 18:56:11 -070087 ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
88 ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
John Reck918ad522014-06-27 14:45:25 -070089 ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
John Reck19b6bcf2014-02-14 20:03:38 -080090
John Reckf47a5942014-06-30 16:20:04 -070091 ANDROID_API void destroyHardwareResources();
92 ANDROID_API static void trimMemory(int level);
Chris Craik2507c342015-05-04 14:36:49 -070093 ANDROID_API static void overrideProperty(const char* name, const char* value);
John Recke1628b72014-05-23 15:11:19 -070094
John Reck28ad7b52014-04-07 16:59:25 -070095 ANDROID_API void fence();
John Reckf47a5942014-06-30 16:20:04 -070096 ANDROID_API void stopDrawing();
John Recka5dda642014-05-22 15:43:54 -070097 ANDROID_API void notifyFramePending();
John Reck28ad7b52014-04-07 16:59:25 -070098
John Reckba6adf62015-02-19 14:36:50 -080099 ANDROID_API void dumpProfileInfo(int fd, int dumpFlags);
Chris Craik2ae07332015-01-21 14:22:39 -0800100 ANDROID_API static void dumpGraphicsMemory(int fd);
John Reckfe5e7b72014-05-23 17:42:28 -0700101
John Reck3b202512014-06-23 13:13:08 -0700102 ANDROID_API void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size);
John Reckedc524c2015-03-18 15:24:33 -0700103 ANDROID_API void setProcessStatsBuffer(int fd);
John Reck3b202512014-06-23 13:13:08 -0700104
John Reck4f02bf42014-01-03 18:09:17 -0800105private:
106 RenderThread& mRenderThread;
107 CanvasContext* mContext;
108
John Reck668f0e32014-03-26 15:10:40 -0700109 DrawFrameTask mDrawFrameTask;
110
John Reck4f02bf42014-01-03 18:09:17 -0800111 Mutex mSyncMutex;
112 Condition mSyncCondition;
113
John Reck4f02bf42014-01-03 18:09:17 -0800114 void destroyContext();
115
John Reck4f02bf42014-01-03 18:09:17 -0800116 void post(RenderTask* task);
117 void* postAndWait(MethodInvokeRenderTask* task);
118
John Reck0e89e2b2014-10-31 14:49:06 -0700119 static void* staticPostAndWait(MethodInvokeRenderTask* task);
120
John Reck4f02bf42014-01-03 18:09:17 -0800121 // Friend class to help with bridging
122 friend class RenderProxyBridge;
123};
124
125} /* namespace renderthread */
126} /* namespace uirenderer */
127} /* namespace android */
128#endif /* RENDERPROXY_H_ */