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

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

Issue 2849463005: Refactor ImageBuffer to make OffscreenCanvas match HTMLCanvasElement (Closed)
Patch Set: x Created 3 years, 8 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 c94e05c81040f6398d1c29b041800fc63abdf881..ebd8677aa0f0974de3f7cdf621489e95a648d402 100644
--- a/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
+++ b/third_party/WebKit/Source/core/offscreencanvas/OffscreenCanvas.cpp
@@ -18,6 +18,8 @@
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
#include "platform/graphics/StaticBitmapImage.h"
+#include "platform/graphics/UnacceleratedImageBufferSurface.h"
+#include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
#include "platform/image-encoders/ImageEncoderUtils.h"
#include "platform/instrumentation/tracing/TraceEvent.h"
#include "platform/wtf/MathExtras.h"
@@ -109,7 +111,7 @@ PassRefPtr<Image> OffscreenCanvas::GetSourceImageForCanvas(
SourceImageStatus* status,
AccelerationHint hint,
SnapshotReason reason,
- const FloatSize& size) const {
+ const FloatSize& size) {
if (!context_) {
*status = kInvalidSourceImageStatus;
sk_sp<SkSurface> surface =
@@ -237,6 +239,38 @@ OffscreenCanvasFrameDispatcher* OffscreenCanvas::GetOrCreateFrameDispatcher() {
return frame_dispatcher_.get();
}
+void OffscreenCanvas::DiscardImageBuffer() {
+ image_buffer_.reset();
+ needs_matrix_clip_restore_ = true;
+}
+
+ImageBuffer* OffscreenCanvas::GetOrCreateImageBuffer() {
+ if (!image_buffer_) {
+ IntSize surface_size(width(), height());
+ OpacityMode opacity_mode =
+ context_->CreationAttributes().hasAlpha() ? kNonOpaque : kOpaque;
+ std::unique_ptr<ImageBufferSurface> surface;
+ if (RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) {
+ surface.reset(
+ new AcceleratedImageBufferSurface(surface_size, opacity_mode));
+ }
+
+ if (!surface || !surface->IsValid()) {
+ surface.reset(new UnacceleratedImageBufferSurface(
+ surface_size, opacity_mode, kInitializeImagePixels));
+ }
+
+ image_buffer_ = ImageBuffer::Create(std::move(surface));
+
+ if (needs_matrix_clip_restore_) {
+ needs_matrix_clip_restore_ = false;
+ context_->RestoreCanvasMatrixClipStack(image_buffer_->Canvas());
+ }
+ }
+
+ return image_buffer_.get();
+}
+
ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image,
bool is_web_gl_software_rendering,
ScriptState* script_state,

Powered by Google App Engine
This is Rietveld 408576698