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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp

Issue 2171513003: Re-enable canvas optimization for getImageData with new codepath (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix tests Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsTypes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, Google Inc. All rights reserved. 2 * Copyright (c) 2008, Google Inc. All rights reserved.
3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are 7 * modification, are permitted provided that the following conditions are
8 * met: 8 * met:
9 * 9 *
10 * * Redistributions of source code must retain the above copyright 10 * * Redistributions of source code must retain the above copyright
(...skipping 16 matching lines...) Expand all
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33 #include "platform/graphics/ImageBuffer.h" 33 #include "platform/graphics/ImageBuffer.h"
34 34
35 #include "gpu/command_buffer/client/gles2_interface.h" 35 #include "gpu/command_buffer/client/gles2_interface.h"
36 #include "platform/MIMETypeRegistry.h" 36 #include "platform/MIMETypeRegistry.h"
37 #include "platform/RuntimeEnabledFeatures.h"
37 #include "platform/geometry/IntRect.h" 38 #include "platform/geometry/IntRect.h"
38 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" 39 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
39 #include "platform/graphics/GraphicsContext.h" 40 #include "platform/graphics/GraphicsContext.h"
40 #include "platform/graphics/ImageBufferClient.h" 41 #include "platform/graphics/ImageBufferClient.h"
41 #include "platform/graphics/RecordingImageBufferSurface.h" 42 #include "platform/graphics/RecordingImageBufferSurface.h"
42 #include "platform/graphics/StaticBitmapImage.h" 43 #include "platform/graphics/StaticBitmapImage.h"
43 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 44 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
44 #include "platform/graphics/gpu/DrawingBuffer.h" 45 #include "platform/graphics/gpu/DrawingBuffer.h"
45 #include "platform/graphics/gpu/Extensions3DUtil.h" 46 #include "platform/graphics/gpu/Extensions3DUtil.h"
46 #include "platform/graphics/skia/SkiaUtils.h" 47 #include "platform/graphics/skia/SkiaUtils.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void* data; 315 void* data;
315 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data); 316 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data);
316 if (!data) 317 if (!data)
317 return false; 318 return false;
318 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared); 319 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared);
319 result.transfer(contents); 320 result.transfer(contents);
320 return true; 321 return true;
321 } 322 }
322 323
323 DCHECK(canvas()); 324 DCHECK(canvas());
324 AccelerationHint hint = (ExpensiveCanvasHeuristicParameters::GetImageDataFor cesNoAcceleration) ? ForceNoAcceleration : PreferNoAcceleration; 325
325 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(hint, SnapshotReasonG etImageData); 326 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration && !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled())
327 const_cast<ImageBuffer*>(this)->disableAcceleration();
328
329 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonGetImageData);
326 if (!snapshot) 330 if (!snapshot)
327 return false; 331 return false;
328 332
329 const bool mayHaveStrayArea = 333 const bool mayHaveStrayArea =
330 m_surface->isAccelerated() // GPU readback may fail silently 334 m_surface->isAccelerated() // GPU readback may fail silently
331 || rect.x() < 0 335 || rect.x() < 0
332 || rect.y() < 0 336 || rect.y() < 0
333 || rect.maxX() > m_surface->size().width() 337 || rect.maxX() > m_surface->size().width()
334 || rect.maxY() > m_surface->size().height(); 338 || rect.maxY() > m_surface->size().height();
335 size_t allocSizeInBytes = rect.width() * rect.height() * 4; 339 size_t allocSizeInBytes = rect.width() * rect.height() * 4;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode) 411 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode)
408 { 412 {
409 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) ); 413 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) );
410 } 414 }
411 415
412 virtual ~UnacceleratedSurfaceFactory() { } 416 virtual ~UnacceleratedSurfaceFactory() { }
413 }; 417 };
414 418
415 void ImageBuffer::disableAcceleration() 419 void ImageBuffer::disableAcceleration()
416 { 420 {
417 if (!isAccelerated()) { 421 if (!isAccelerated())
418 return; 422 return;
419 }
420 423
421 // Get current frame. 424 // Get current frame.
422 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get(); 425 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get();
423 426
424 // Create and configure a recording (unaccelerated) surface. 427 // Create and configure a recording (unaccelerated) surface.
425 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory()); 428 std::unique_ptr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = wrapUnique(new UnacceleratedSurfaceFactory());
426 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode())); 429 std::unique_ptr<ImageBufferSurface> surface = wrapUnique(new RecordingImageB ufferSurface(m_surface->size(), std::move(surfaceFactory), m_surface->getOpacity Mode()));
427 surface->canvas()->drawImage(image, 0, 0); 430 surface->canvas()->drawImage(image, 0, 0);
428 surface->setImageBuffer(this); 431 surface->setImageBuffer(this);
429 432
(...skipping 28 matching lines...) Expand all
458 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 461 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
459 462
460 Vector<unsigned char> result; 463 Vector<unsigned char> result;
461 if (!encodeImage(mimeType, quality, &result)) 464 if (!encodeImage(mimeType, quality, &result))
462 return "data:,"; 465 return "data:,";
463 466
464 return "data:" + mimeType + ";base64," + base64Encode(result); 467 return "data:" + mimeType + ";base64," + base64Encode(result);
465 } 468 }
466 469
467 } // namespace blink 470 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/GraphicsTypes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698