Skip to content

Commit

Permalink
* 帧率可以针对单个view
Browse files Browse the repository at this point in the history
  • Loading branch information
weolar committed Jun 27, 2018
1 parent 130b202 commit c52dcd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cc/trees/LayerTreeHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "wke/wkeWebView.h"

extern DWORD g_nowTime;
extern double g_kDrawMinInterval;

using namespace blink;

Expand Down Expand Up @@ -62,6 +61,7 @@ LayerTreeHost::LayerTreeHost(LayerTreeHostClent* hostClient, LayerTreeHostUiThre

m_memoryCanvas = nullptr;
m_paintToMemoryCanvasInUiThreadTaskCount = 0;
m_drawMinInterval = 0.003;

m_isDrawDirty = true;
m_lastCompositeTime = 0.0;
Expand Down Expand Up @@ -334,7 +334,7 @@ bool LayerTreeHost::canRecordActions() const

double lastRecordTime = WTF::monotonicallyIncreasingTime();
double detTime = lastRecordTime - m_lastRecordTime;
if (detTime < g_kDrawMinInterval)
if (detTime < m_drawMinInterval)
return false;
m_lastRecordTime = lastRecordTime;

Expand Down Expand Up @@ -920,6 +920,11 @@ void LayerTreeHost::clearCanvas(SkCanvas* canvas, const SkRect& rect, bool useLa
canvas->drawRect(skrc, clearPaint);
}

void LayerTreeHost::setDrawMinInterval(double drawMinInterval)
{
m_drawMinInterval = drawMinInterval;
}

void LayerTreeHost::postPaintMessage(const SkRect& paintRect)
{
SkRect dirtyRect = paintRect;
Expand Down Expand Up @@ -978,7 +983,7 @@ void LayerTreeHost::drawFrameInCompositeThread()

double lastCompositeTime = WTF::monotonicallyIncreasingTime();
double detTime = lastCompositeTime - m_lastCompositeTime;
if (detTime < g_kDrawMinInterval && !m_isDestroying) { // 如果刷新频率太快,缓缓再画
if (detTime < m_drawMinInterval && !m_isDestroying) { // 如果刷新频率太快,缓缓再画
requestDrawFrameToRunIntoCompositeThread();
atomicDecrement(&m_drawFrameFinishCount);
return;
Expand Down Expand Up @@ -1054,7 +1059,7 @@ void LayerTreeHost::WrapSelfForUiThread::paintInUiThread()

double lastPaintTime = WTF::monotonicallyIncreasingTime();
double detTime = lastPaintTime - m_host->m_lastPaintTime;
if (detTime < g_kDrawMinInterval) {
if (detTime < m_host->m_drawMinInterval) {
m_host->requestPaintToMemoryCanvasToUiThread(IntRect());
endPaint();
return;
Expand Down
3 changes: 3 additions & 0 deletions cc/trees/LayerTreeHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class LayerTreeHost : public blink::WebLayerTreeView {
//void setUseLayeredBuffer(bool b);
//bool getIsUseLayeredBuffer() const { return m_useLayeredBuffer; }
static void clearCanvas(SkCanvas* canvas, const SkRect& rect, bool useLayeredBuffer);

void setDrawMinInterval(double drawMinInterval);

void postPaintMessage(const SkRect& paintRect);
void firePaintEvent(HDC hdc, const RECT* paintRect);
Expand Down Expand Up @@ -245,6 +247,7 @@ class LayerTreeHost : public blink::WebLayerTreeView {
double m_lastCompositeTime;
double m_lastPaintTime;
mutable double m_lastRecordTime;
double m_drawMinInterval;

static const int m_paintMessageQueueSize = 200;
Vector<SkRect> m_dirtyRectsForComposite;
Expand Down

0 comments on commit c52dcd9

Please sign in to comment.