blob: 83ecb98f548f52d48861357ea96cf3441e548f9d [file] [log] [blame]
John Reck668f0e32014-03-26 15:10:40 -07001/*
2 * Copyright (C) 2014 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#ifndef DRAWFRAMETASK_H
17#define DRAWFRAMETASK_H
18
John Reckd72e0a32014-05-29 18:56:11 -070019#include <vector>
20
John Reck668f0e32014-03-26 15:10:40 -070021#include <utils/Condition.h>
22#include <utils/Mutex.h>
John Reck087bc0c2014-04-04 16:20:08 -070023#include <utils/StrongPointer.h>
John Reck668f0e32014-03-26 15:10:40 -070024
25#include "RenderTask.h"
26
27#include "../Rect.h"
John Reckba6adf62015-02-19 14:36:50 -080028#include "../FrameInfo.h"
John Recka5dda642014-05-22 15:43:54 -070029#include "../TreeInfo.h"
John Reck668f0e32014-03-26 15:10:40 -070030
31namespace android {
32namespace uirenderer {
33
34class DeferredLayerUpdater;
Chris Craik003cc3d2015-10-16 10:24:55 -070035class DisplayList;
John Reck668f0e32014-03-26 15:10:40 -070036class RenderNode;
37
38namespace renderthread {
39
40class CanvasContext;
41class RenderThread;
42
John Reck9a17da82016-04-18 11:17:52 -070043namespace SyncResult {
44enum {
45 OK = 0,
46 UIRedrawRequired = 1 << 0,
47 LostSurfaceRewardIfFound = 1 << 1,
48 ContextIsStopped = 1 << 2,
John Reckf9be7792014-05-02 18:21:16 -070049};
John Reck9a17da82016-04-18 11:17:52 -070050}
John Reckf9be7792014-05-02 18:21:16 -070051
John Reck668f0e32014-03-26 15:10:40 -070052/*
53 * This is a special Super Task. It is re-used multiple times by RenderProxy,
Chris Craik003cc3d2015-10-16 10:24:55 -070054 * and contains state (such as layer updaters & new DisplayLists) that is
John Reck668f0e32014-03-26 15:10:40 -070055 * tracked across many frames not just a single frame.
56 * It is the sync-state task, and will kick off the post-sync draw
57 */
58class DrawFrameTask : public RenderTask {
59public:
60 DrawFrameTask();
61 virtual ~DrawFrameTask();
62
Skuhneea7a7fb2015-08-28 07:10:31 -070063 void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode);
John Reckf138b172017-09-08 11:00:42 -070064 void setContentDrawBounds(int left, int top, int right, int bottom) {
65 mContentDrawBounds.set(left, top, right, bottom);
66 }
John Reck668f0e32014-03-26 15:10:40 -070067
John Reckd72e0a32014-05-29 18:56:11 -070068 void pushLayerUpdate(DeferredLayerUpdater* layer);
69 void removeLayerUpdate(DeferredLayerUpdater* layer);
John Reck668f0e32014-03-26 15:10:40 -070070
John Reck2de950d2017-01-25 10:58:30 -080071 int drawFrame();
John Reckba6adf62015-02-19 14:36:50 -080072
73 int64_t* frameInfo() { return mFrameInfo; }
John Reck668f0e32014-03-26 15:10:40 -070074
Chris Craikd41c4d82015-01-05 15:51:13 -080075 virtual void run() override;
John Reck668f0e32014-03-26 15:10:40 -070076
77private:
John Reck18f16e62014-05-02 16:46:41 -070078 void postAndWait();
John Recka5dda642014-05-22 15:43:54 -070079 bool syncFrameState(TreeInfo& info);
John Reck668f0e32014-03-26 15:10:40 -070080 void unblockUiThread();
John Reck668f0e32014-03-26 15:10:40 -070081
John Reck668f0e32014-03-26 15:10:40 -070082 Mutex mLock;
83 Condition mSignal;
84
John Reck18f16e62014-05-02 16:46:41 -070085 RenderThread* mRenderThread;
John Reck668f0e32014-03-26 15:10:40 -070086 CanvasContext* mContext;
Skuhneea7a7fb2015-08-28 07:10:31 -070087 RenderNode* mTargetNode = nullptr;
John Reckf138b172017-09-08 11:00:42 -070088 Rect mContentDrawBounds;
John Reck668f0e32014-03-26 15:10:40 -070089
90 /*********************************************
91 * Single frame data
92 *********************************************/
John Reckd72e0a32014-05-29 18:56:11 -070093 std::vector< sp<DeferredLayerUpdater> > mLayers;
John Reck668f0e32014-03-26 15:10:40 -070094
John Reckf9be7792014-05-02 18:21:16 -070095 int mSyncResult;
John Reckbe3fba02015-07-06 13:49:58 -070096 int64_t mSyncQueued;
John Reckba6adf62015-02-19 14:36:50 -080097
98 int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE];
John Reck668f0e32014-03-26 15:10:40 -070099};
100
101} /* namespace renderthread */
102} /* namespace uirenderer */
103} /* namespace android */
104
105#endif /* DRAWFRAMETASK_H */