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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/offscreencanvas/OffscreenCanvas.h" 5 #include "core/offscreencanvas/OffscreenCanvas.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/fileapi/Blob.h" 10 #include "core/fileapi/Blob.h"
11 #include "core/frame/ImageBitmap.h" 11 #include "core/frame/ImageBitmap.h"
12 #include "core/html/ImageData.h" 12 #include "core/html/ImageData.h"
13 #include "core/html/canvas/CanvasAsyncBlobCreator.h" 13 #include "core/html/canvas/CanvasAsyncBlobCreator.h"
14 #include "core/html/canvas/CanvasContextCreationAttributes.h" 14 #include "core/html/canvas/CanvasContextCreationAttributes.h"
15 #include "core/html/canvas/CanvasRenderingContext.h" 15 #include "core/html/canvas/CanvasRenderingContext.h"
16 #include "core/html/canvas/CanvasRenderingContextFactory.h" 16 #include "core/html/canvas/CanvasRenderingContextFactory.h"
17 #include "platform/graphics/Image.h" 17 #include "platform/graphics/Image.h"
18 #include "platform/graphics/ImageBuffer.h" 18 #include "platform/graphics/ImageBuffer.h"
19 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h" 19 #include "platform/graphics/OffscreenCanvasFrameDispatcherImpl.h"
20 #include "platform/graphics/StaticBitmapImage.h" 20 #include "platform/graphics/StaticBitmapImage.h"
21 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
22 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h"
21 #include "platform/image-encoders/ImageEncoderUtils.h" 23 #include "platform/image-encoders/ImageEncoderUtils.h"
22 #include "platform/instrumentation/tracing/TraceEvent.h" 24 #include "platform/instrumentation/tracing/TraceEvent.h"
23 #include "platform/wtf/MathExtras.h" 25 #include "platform/wtf/MathExtras.h"
24 #include "public/platform/Platform.h" 26 #include "public/platform/Platform.h"
25 #include "third_party/skia/include/core/SkSurface.h" 27 #include "third_party/skia/include/core/SkSurface.h"
26 28
27 namespace blink { 29 namespace blink {
28 30
29 OffscreenCanvas::OffscreenCanvas(const IntSize& size) : size_(size) {} 31 OffscreenCanvas::OffscreenCanvas(const IntSize& size) : size_(size) {}
30 32
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // The frame dispatcher connects the current thread of OffscreenCanvas 232 // The frame dispatcher connects the current thread of OffscreenCanvas
231 // (either main or worker) to the browser process and remains unchanged 233 // (either main or worker) to the browser process and remains unchanged
232 // throughout the lifetime of this OffscreenCanvas. 234 // throughout the lifetime of this OffscreenCanvas.
233 frame_dispatcher_ = WTF::WrapUnique(new OffscreenCanvasFrameDispatcherImpl( 235 frame_dispatcher_ = WTF::WrapUnique(new OffscreenCanvasFrameDispatcherImpl(
234 this, client_id_, sink_id_, placeholder_canvas_id_, size_.Width(), 236 this, client_id_, sink_id_, placeholder_canvas_id_, size_.Width(),
235 size_.Height())); 237 size_.Height()));
236 } 238 }
237 return frame_dispatcher_.get(); 239 return frame_dispatcher_.get();
238 } 240 }
239 241
242 void OffscreenCanvas::DiscardImageBuffer() {
243 image_buffer_.reset();
244 needs_matrix_clip_restore_ = true;
245 }
246
247 ImageBuffer* OffscreenCanvas::GetImageBuffer() const {
248 if (!image_buffer_) {
249 IntSize surface_size(width(), height());
250 OpacityMode opacity_mode =
251 context_->CreationAttributes().hasAlpha() ? kNonOpaque : kOpaque;
252 std::unique_ptr<ImageBufferSurface> surface;
253 if (RuntimeEnabledFeatures::accelerated2dCanvasEnabled()) {
254 surface.reset(
255 new AcceleratedImageBufferSurface(surface_size, opacity_mode));
256 }
257
258 if (!surface || !surface->IsValid()) {
259 surface.reset(new UnacceleratedImageBufferSurface(
260 surface_size, opacity_mode, kInitializeImagePixels));
261 }
262
263 // argh.
Justin Novosad 2017/05/01 15:18:57 Comment not useful.
fserb 2017/05/02 18:49:30 done
264 OffscreenCanvas* non_const_this = const_cast<OffscreenCanvas*>(this);
Justin Novosad 2017/05/01 15:18:57 Another reason to remove "const" from the function
fserb 2017/05/02 18:49:30 done done
265 non_const_this->image_buffer_ = ImageBuffer::Create(std::move(surface));
266
267 if (needs_matrix_clip_restore_) {
268 non_const_this->needs_matrix_clip_restore_ = false;
269 context_->RestoreCanvasMatrixClipStack(image_buffer_->Canvas());
270 }
271 }
272
273 return image_buffer_.get();
274 }
275
240 ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image, 276 ScriptPromise OffscreenCanvas::Commit(RefPtr<StaticBitmapImage> image,
241 bool is_web_gl_software_rendering, 277 bool is_web_gl_software_rendering,
242 ScriptState* script_state, 278 ScriptState* script_state,
243 ExceptionState& exception_state) { 279 ExceptionState& exception_state) {
244 TRACE_EVENT0("blink", "OffscreenCanvas::Commit"); 280 TRACE_EVENT0("blink", "OffscreenCanvas::Commit");
245 281
246 if (!HasPlaceholderCanvas()) { 282 if (!HasPlaceholderCanvas()) {
247 exception_state.ThrowDOMException( 283 exception_state.ThrowDOMException(
248 kInvalidStateError, 284 kInvalidStateError,
249 "Commit() was called on a context whose " 285 "Commit() was called on a context whose "
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 } 404 }
369 405
370 DEFINE_TRACE(OffscreenCanvas) { 406 DEFINE_TRACE(OffscreenCanvas) {
371 visitor->Trace(context_); 407 visitor->Trace(context_);
372 visitor->Trace(execution_context_); 408 visitor->Trace(execution_context_);
373 visitor->Trace(commit_promise_resolver_); 409 visitor->Trace(commit_promise_resolver_);
374 EventTargetWithInlineData::Trace(visitor); 410 EventTargetWithInlineData::Trace(visitor);
375 } 411 }
376 412
377 } // namespace blink 413 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698