Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1297)

Unified Diff: third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp

Issue 2594843002: Implementing promise-based commit for driving OffscreenCanvas animations (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 61331f8308302508f2389421354e8de745899dbd..e392678fa20ea8be19fcb136b59be0d3d308087a 100644
--- a/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
+++ b/third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.cpp
@@ -27,13 +27,21 @@
namespace blink {
+// This constant specifies the maximum number of pixel buffer that are allowed
+// to co-exist at a given time. The minimum number is 2 (double buffered).
+// larger numbers can help maintain a steadier frame rates, but they increase
+// latency.
+const int kMaximumOffscreenCanvasBufferCount = 3;
+
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_changeSizeForNextCommit(false),
@@ -50,6 +58,10 @@ OffscreenCanvasFrameDispatcherImpl::OffscreenCanvasFrameDispatcherImpl(
mojo::MakeRequest(&m_sink));
}
+OffscreenCanvasFrameDispatcherImpl::~OffscreenCanvasFrameDispatcherImpl() {
+ m_syntheticBeginFrameTask.cancel();
+}
+
void OffscreenCanvasFrameDispatcherImpl::setTransferableResourceToSharedBitmap(
cc::TransferableResource& resource,
RefPtr<StaticBitmapImage> image) {
@@ -178,9 +190,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
@@ -363,6 +373,21 @@ void OffscreenCanvasFrameDispatcherImpl::dispatchFrame(
m_changeSizeForNextCommit = false;
}
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() {
@@ -370,7 +395,22 @@ 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();
+
+ // Limit the rate of compositor commits.
+ if (framesInFlight < kMaximumOffscreenCanvasBufferCount) {
+ 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) {
@@ -384,7 +424,6 @@ void OffscreenCanvasFrameDispatcherImpl::ReclaimResources(
void OffscreenCanvasFrameDispatcherImpl::WillDrawSurface() {
// TODO(fsamuel, staraz): Implement this.
- NOTIMPLEMENTED();
}
void OffscreenCanvasFrameDispatcherImpl::reclaimResource(unsigned resourceId) {
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/OffscreenCanvasFrameDispatcherImpl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698