DrawFrameTask.h revision d72e0a339b54af0c4e731513bbad120dff694723
1/*
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
19#include <vector>
20
21#include <utils/Condition.h>
22#include <utils/Mutex.h>
23#include <utils/StrongPointer.h>
24
25#include "RenderTask.h"
26
27#include "../Rect.h"
28#include "../TreeInfo.h"
29
30namespace android {
31namespace uirenderer {
32
33class DeferredLayerUpdater;
34class DisplayListData;
35class RenderNode;
36
37namespace renderthread {
38
39class CanvasContext;
40class RenderThread;
41
42enum SyncResult {
43    kSync_OK = 0,
44    kSync_UIRedrawRequired = 1 << 1,
45};
46
47/*
48 * This is a special Super Task. It is re-used multiple times by RenderProxy,
49 * and contains state (such as layer updaters & new DisplayListDatas) that is
50 * tracked across many frames not just a single frame.
51 * It is the sync-state task, and will kick off the post-sync draw
52 */
53class DrawFrameTask : public RenderTask {
54public:
55    DrawFrameTask();
56    virtual ~DrawFrameTask();
57
58    void setContext(RenderThread* thread, CanvasContext* context);
59
60    void pushLayerUpdate(DeferredLayerUpdater* layer);
61    void removeLayerUpdate(DeferredLayerUpdater* layer);
62
63    void setDirty(int left, int top, int right, int bottom);
64    void setDensity(float density) { mDensity = density; }
65    int drawFrame(nsecs_t frameTimeNanos, nsecs_t recordDurationNanos);
66
67    virtual void run();
68
69private:
70    void postAndWait();
71    bool syncFrameState(TreeInfo& info);
72    void unblockUiThread();
73
74    Mutex mLock;
75    Condition mSignal;
76
77    RenderThread* mRenderThread;
78    CanvasContext* mContext;
79
80    /*********************************************
81     *  Single frame data
82     *********************************************/
83    Rect mDirty;
84    nsecs_t mFrameTimeNanos;
85    nsecs_t mRecordDurationNanos;
86    float mDensity;
87    std::vector< sp<DeferredLayerUpdater> > mLayers;
88
89    int mSyncResult;
90};
91
92} /* namespace renderthread */
93} /* namespace uirenderer */
94} /* namespace android */
95
96#endif /* DRAWFRAMETASK_H */
97