| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef DRAWFRAMETASK_H |
| 17 |
#define DRAWFRAMETASK_H |
| 18 |
|
| 19 |
#include <android/performance_hint.h> |
| 20 |
#include <utils/Condition.h> |
| 21 |
#include <utils/Mutex.h> |
| 22 |
#include <utils/StrongPointer.h> |
| 23 |
|
| 24 |
#include <optional> |
| 25 |
#include <vector> |
| 26 |
|
| 27 |
#include "../FrameInfo.h" |
| 28 |
#include "../Rect.h" |
| 29 |
#include "../TreeInfo.h" |
| 30 |
#include "RenderTask.h" |
| 31 |
|
| 32 |
namespace android { |
| 33 |
namespace uirenderer { |
| 34 |
|
| 35 |
class DeferredLayerUpdater; |
| 36 |
class RenderNode; |
| 37 |
|
| 38 |
namespace renderthread { |
| 39 |
|
| 40 |
class CanvasContext; |
| 41 |
class RenderThread; |
| 42 |
|
| 43 |
namespace SyncResult { |
| 44 |
enum { |
| 45 |
OK = 0, |
| 46 |
UIRedrawRequired = 1 << 0, |
| 47 |
LostSurfaceRewardIfFound = 1 << 1, |
| 48 |
ContextIsStopped = 1 << 2, |
| 49 |
FrameDropped = 1 << 3, |
| 50 |
}; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
class DrawFrameTask { |
| 60 |
public: |
| 61 |
DrawFrameTask(); |
| 62 |
virtual ~DrawFrameTask(); |
| 63 |
|
| 64 |
void setContext(RenderThread* thread, CanvasContext* context, RenderNode* targetNode, |
| 65 |
int32_t uiThreadId, int32_t renderThreadId); |
| 66 |
void setContentDrawBounds(int left, int top, int right, int bottom) { |
| 67 |
mContentDrawBounds.set(left, top, right, bottom); |
| 68 |
} |
| 69 |
|
| 70 |
void pushLayerUpdate(DeferredLayerUpdater* layer); |
| 71 |
void removeLayerUpdate(DeferredLayerUpdater* layer); |
| 72 |
|
| 73 |
int drawFrame(); |
| 74 |
|
| 75 |
int64_t* frameInfo() { return mFrameInfo; } |
| 76 |
|
| 77 |
void run(); |
| 78 |
|
| 79 |
void setFrameCallback(std::function<std::function<void(bool)>(int32_t, int64_t)>&& callback) { |
| 80 |
mFrameCallback = std::move(callback); |
| 81 |
} |
| 82 |
|
| 83 |
void setFrameCommitCallback(std::function<void(bool)>&& callback) { |
| 84 |
mFrameCommitCallback = std::move(callback); |
| 85 |
} |
| 86 |
|
| 87 |
void setFrameCompleteCallback(std::function<void()>&& callback) { |
| 88 |
mFrameCompleteCallback = std::move(callback); |
| 89 |
} |
| 90 |
|
| 91 |
void forceDrawNextFrame() { mForceDrawFrame = true; } |
| 92 |
|
| 93 |
private: |
| 94 |
class HintSessionWrapper { |
| 95 |
public: |
| 96 |
HintSessionWrapper(int32_t uiThreadId, int32_t renderThreadId); |
| 97 |
~HintSessionWrapper(); |
| 98 |
|
| 99 |
void updateTargetWorkDuration(long targetDurationNanos); |
| 100 |
void reportActualWorkDuration(long actualDurationNanos); |
| 101 |
|
| 102 |
private: |
| 103 |
APerformanceHintSession* mHintSession = nullptr; |
| 104 |
}; |
| 105 |
|
| 106 |
void postAndWait(); |
| 107 |
bool syncFrameState(TreeInfo& info); |
| 108 |
void unblockUiThread(); |
| 109 |
|
| 110 |
Mutex mLock; |
| 111 |
Condition mSignal; |
| 112 |
|
| 113 |
RenderThread* mRenderThread; |
| 114 |
CanvasContext* mContext; |
| 115 |
RenderNode* mTargetNode = nullptr; |
| 116 |
int32_t mUiThreadId = -1; |
| 117 |
int32_t mRenderThreadId = -1; |
| 118 |
Rect mContentDrawBounds; |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
std::vector<sp<DeferredLayerUpdater> > mLayers; |
| 124 |
|
| 125 |
int mSyncResult; |
| 126 |
int64_t mSyncQueued; |
| 127 |
|
| 128 |
int64_t mFrameInfo[UI_THREAD_FRAME_INFO_SIZE]; |
| 129 |
|
| 130 |
std::function<std::function<void(bool)>(int32_t, int64_t)> mFrameCallback; |
| 131 |
std::function<void(bool)> mFrameCommitCallback; |
| 132 |
std::function<void()> mFrameCompleteCallback; |
| 133 |
|
| 134 |
nsecs_t mLastDequeueBufferDuration = 0; |
| 135 |
nsecs_t mLastTargetWorkDuration = 0; |
| 136 |
std::optional<HintSessionWrapper> mHintSessionWrapper; |
| 137 |
|
| 138 |
bool mForceDrawFrame = false; |
| 139 |
}; |
| 140 |
|
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
#endif |