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

Unified Diff: third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp

Issue 2778483002: Synchronize commits at end of JS task (Closed)
Patch Set: clean up Created 3 years, 9 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
Index: third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
diff --git a/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp b/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
index a41f0c69a83ff962d9490753f956682b135ca320..7db0de08caa1b4bbaedaf9c5015aa6e37886c702 100644
--- a/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
+++ b/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
@@ -4,6 +4,7 @@
#include "core/offscreencanvas/OffscreenCanvas.h"
+#include <memory>
#include "core/dom/ExceptionCode.h"
#include "core/fileapi/Blob.h"
#include "core/frame/ImageBitmap.h"
@@ -17,8 +18,8 @@
#include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
#include "platform/graphics/StaticBitmapImage.h"
#include "platform/image-encoders/ImageEncoderUtils.h"
+#include "public/platform/Platform.h"
#include "wtf/MathExtras.h"
-#include <memory>
namespace blink {
@@ -237,20 +238,40 @@ ScriptPromise OffscreenCanvas::commit(RefPtr<StaticBitmapImage> image,
bool isWebGLSoftwareRendering,
ScriptState* scriptState) {
getOrCreateFrameDispatcher()->setNeedsBeginFrame(true);
- if (m_commitPromiseResolver) {
+
+ if (!m_commitPromiseResolver) {
+ m_commitPromiseResolver = ScriptPromiseResolver::create(scriptState);
+ m_commitPromiseResolver->keepAliveWhilePending();
+
+ m_overdrawFrame = nullptr;
Justin Novosad 2017/03/24 17:41:53 We don't to track m_overdrawFrame anymore.
if (image) {
+ // We defer the submission of commit frames at the end of JS task
+ m_currentFrame = std::move(image);
+ m_currentFrameIsWebGLSoftwareRendering = isWebGLSoftwareRendering;
+ Platform::current()->currentThread()->addTaskObserver(m_context);
+ }
+ } else if (image) {
+ if (m_currentFrame) {
+ // An override of m_currentFrame can happen when there are multiple
+ // frames committed before JS task finishes.
+ m_currentFrame = std::move(image);
+ m_currentFrameIsWebGLSoftwareRendering = isWebGLSoftwareRendering;
+ } else {
+ // The current frame has been dispatched but the promise is not resolved
+ // yet.
m_overdrawFrame = std::move(image);
m_overdrawFrameIsWebGLSoftwareRendering = isWebGLSoftwareRendering;
}
- } else {
- m_overdrawFrame = nullptr;
- m_commitPromiseResolver = ScriptPromiseResolver::create(scriptState);
- m_commitPromiseResolver->keepAliveWhilePending();
- doCommit(std::move(image), isWebGLSoftwareRendering);
}
+
return m_commitPromiseResolver->promise();
}
+void OffscreenCanvas::doCommitAtEndOfTask() {
Justin Novosad 2017/03/24 17:41:53 What happens if we reach this point and m_commitPr
xlai (Olivia) 2017/03/24 18:18:52 Actually, this situation was already handled in th
+ doCommit(std::move(m_currentFrame), m_currentFrameIsWebGLSoftwareRendering);
+ Platform::current()->currentThread()->removeTaskObserver(m_context);
+}
+
void OffscreenCanvas::doCommit(RefPtr<StaticBitmapImage> image,
bool isWebGLSoftwareRendering) {
double commitStartTime = WTF::monotonicallyIncreasingTime();
@@ -264,7 +285,7 @@ void OffscreenCanvas::beginFrame() {
// first and save the promise resolution for later.
doCommit(std::move(m_overdrawFrame),
m_overdrawFrameIsWebGLSoftwareRendering);
- } else if (m_commitPromiseResolver) {
+ } else if (!m_currentFrame && m_commitPromiseResolver) {
m_commitPromiseResolver->resolve();
m_commitPromiseResolver.clear();
// We need to tell parent frame to stop sending signals on begin frame to

Powered by Google App Engine
This is Rietveld 408576698