Index: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp |
index d32911013a6969b58007c6caa300f8888771d873..5ef6921ef9e0793883f61ac3a8f5a6b2437f78df 100644 |
--- a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp |
@@ -28,12 +28,14 @@ |
namespace blink { |
OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl( |
+ OffscreenCanvasFrameDispatcherClient* client, |
uint32_t clientId, |
uint32_t sinkId, |
int canvasId, |
int width, |
int height) |
- : m_frameSinkId(cc::FrameSinkId(clientId, sinkId)), |
+ : OffscreenCanvasFrameDispatcher(client), |
+ m_frameSinkId(cc::FrameSinkId(clientId, sinkId)), |
m_width(width), |
m_height(height), |
m_nextResourceId(1u), |
@@ -49,6 +51,10 @@ OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl( |
mojo::MakeRequest(&m_sink)); |
} |
+OffscreenCanvasFrameDispatcherImpl::~OffscreenCanvasFrameDispatcherImpl() { |
+ m_syntheticBeginFrameTask.cancel(); |
+} |
+ |
void OffscreenCanvasFrameDispatcherImpl::setTransferableResourceToSharedBitmap( |
cc::TransferableResource& resource, |
RefPtr<StaticBitmapImage> image) { |
@@ -177,9 +183,7 @@ void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( |
double commitStartTime, |
bool isWebGLSoftwareRendering /* This flag is true when WebGL's commit is |
called on SwiftShader. */) { |
- if (!image) |
- return; |
- if (!verifyImageSize(image->size())) |
+ if (!image || !verifyImageSize(image->size())) |
return; |
cc::CompositorFrame frame; |
// TODO(crbug.com/652931): update the device_scale_factor |
@@ -358,6 +362,21 @@ void OffscreenCanvasFrameDispatcherImpl::dispatchFrame( |
} |
m_sink->SubmitCompositorFrame(m_currentLocalFrameId, std::move(frame)); |
+ |
+ // TODO(crbug.com/674744): Get BeginFrame to fire on its own. |
+ scheduleSyntheticBeginFrame(); |
+} |
+ |
+void OffscreenCanvasFrameDispatcherImpl::scheduleSyntheticBeginFrame() { |
+ m_syntheticBeginFrameTask = |
+ Platform::current() |
+ ->currentThread() |
+ ->getWebTaskRunner() |
+ ->postDelayedCancellableTask( |
+ BLINK_FROM_HERE, |
+ WTF::bind(&OffscreenCanvasFrameDispatcherImpl::OnBeginFrame, |
+ WTF::unretained(this), cc::BeginFrameArgs()), |
+ 16); |
} |
void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck() { |
@@ -365,7 +384,20 @@ void OffscreenCanvasFrameDispatcherImpl::DidReceiveCompositorFrameAck() { |
} |
void OffscreenCanvasFrameDispatcherImpl::OnBeginFrame( |
- const cc::BeginFrameArgs& beginFrameArgs) {} |
+ const cc::BeginFrameArgs& beginFrameArgs) { |
+ if (!client()) |
+ return; |
+ unsigned framesInFlight = m_cachedImages.size() + m_sharedBitmaps.size() + |
+ m_cachedTextureIds.size(); |
+ if (framesInFlight < 3) { // Backpressure guard |
Stephen White
2016/12/21 15:14:43
Make this be a compile-time constant?
|
+ client()->beginFrame(); |
+ } else { |
+ // TODO(crbug.com/674744): Get BeginFrame to fire on its own. |
+ // The following call is to reschedule the frame in cases where we encounter |
+ // a backlog. |
+ scheduleSyntheticBeginFrame(); |
+ } |
+} |
void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( |
const cc::ReturnedResourceArray& resources) { |
@@ -379,7 +411,6 @@ void OffscreenCanvasFrameDispatcherImpl::ReclaimResources( |
void OffscreenCanvasFrameDispatcherImpl::WillDrawSurface() { |
// TODO(fsamuel, staraz): Implement this. |
- NOTIMPLEMENTED(); |
} |
void OffscreenCanvasFrameDispatcherImpl::reclaimResource(unsigned resourceId) { |