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

Unified Diff: third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h

Issue 1665413004: toBlob: If idle image encoding is postponed for too long, switch to main thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed unnecessary include in unit test Created 4 years, 10 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/html/canvas/CanvasAsyncBlobCreator.h
diff --git a/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h b/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h
index 391a9ce9a387789b3fe74163480054a777b39a63..0ac104d548994a9c6976cdaa0af541dc7d2ad08a 100644
--- a/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h
+++ b/third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.h
@@ -5,6 +5,7 @@
#include "core/CoreExport.h"
#include "core/dom/DOMTypedArray.h"
#include "core/fileapi/BlobCallback.h"
+#include "platform/Task.h"
#include "platform/geometry/IntSize.h"
#include "platform/heap/Handle.h"
#include "wtf/OwnPtr.h"
@@ -23,11 +24,32 @@ public:
static PassRefPtr<CanvasAsyncBlobCreator> create(PassRefPtr<DOMUint8ClampedArray> unpremultipliedRGBAImageData, const String& mimeType, const IntSize&, BlobCallback*);
void scheduleAsyncBlobCreation(bool canUseIdlePeriodScheduling, double quality = 0.0);
virtual ~CanvasAsyncBlobCreator();
+ enum IdleTaskStatus {
+ IdleTaskNotStarted,
+ IdleTaskStarted,
+ IdleTaskCompleted,
+ IdleTaskFailed,
+ IdleTaskSwitchedToMainThreadTask,
+ Default // Idle tasks are not implemented for some image types
+ };
+ virtual void signalTaskSwitchInStartTimeoutEventForTesting() { }
+ virtual void signalTaskSwitchInCompleteTimeoutEventForTesting() { }
-private:
+protected:
CanvasAsyncBlobCreator(PassRefPtr<DOMUint8ClampedArray> data, const String& mimeType, const IntSize&, BlobCallback*);
- void scheduleCreateBlobAndCallOnMainThread();
- void scheduleCreateNullptrAndCallOnMainThread();
+ virtual void scheduleInitiatePngEncoding();
+ virtual void idleEncodeRowsPng(double deadlineSeconds);
+ virtual void postDelayedTaskToMainThread(const WebTraceLocation&, Task*, double delayMs);
+ virtual void clearAlternativeSelfReference();
+ virtual void createBlobAndCall();
+ virtual void createNullptrAndCall();
+
+ void clearSelfReference();
+ void initiatePngEncoding(double deadlineSeconds);
+ IdleTaskStatus m_idleTaskStatus;
+
+private:
+ friend class CanvasAsyncBlobCreatorTest;
OwnPtr<PNGImageEncoderState> m_pngEncoderState;
OwnPtr<JPEGImageEncoderState> m_jpegEncoderState;
@@ -40,18 +62,22 @@ private:
const String m_mimeType;
CrossThreadPersistent<BlobCallback> m_callback;
+ // To keep this asyncBlobCreator alive before async encoding task completes
+ // Used by all image types
RefPtr<CanvasAsyncBlobCreator> m_selfRef;
- void clearSelfReference();
+ // To keep this asyncBlobCreator alive before the alternative code path (for
+ // the case when idle task is postponed for too long) is confirmed not to
+ // continue any more; Used by png image type only
+ RefPtr<CanvasAsyncBlobCreator> m_alternativeSelfRef;
- void initiatePngEncoding(double deadlineSeconds);
- void scheduleIdleEncodeRowsPng();
- void idleEncodeRowsPng(double deadlineSeconds);
+ bool initializePngStruct();
+ void encodeRowsPngOnMainThread(); // Similar to idleEncodeRowsPng without deadline
+ void encodeImageOnEncoderThread(double quality);
void initiateJpegEncoding(const double& quality);
- void createBlobAndCall();
-
- void encodeImageOnEncoderThread(double quality);
+ void idleTaskStartTimeoutEvent(double quality);
+ void idleTaskCompleteTimeoutEvent();
};
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/html/canvas/CanvasAsyncBlobCreator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698