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

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

Issue 2063473002: Make 2D canvas disable gpu acceleration when getImageData is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 /* 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 17 matching lines...) Expand all
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/geometry/IntRect.h" 37 #include "platform/geometry/IntRect.h"
38 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
38 #include "platform/graphics/GraphicsContext.h" 39 #include "platform/graphics/GraphicsContext.h"
39 #include "platform/graphics/ImageBufferClient.h" 40 #include "platform/graphics/ImageBufferClient.h"
40 #include "platform/graphics/StaticBitmapImage.h" 41 #include "platform/graphics/StaticBitmapImage.h"
41 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 42 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
42 #include "platform/graphics/gpu/DrawingBuffer.h" 43 #include "platform/graphics/gpu/DrawingBuffer.h"
43 #include "platform/graphics/gpu/Extensions3DUtil.h" 44 #include "platform/graphics/gpu/Extensions3DUtil.h"
44 #include "platform/graphics/skia/SkiaUtils.h" 45 #include "platform/graphics/skia/SkiaUtils.h"
45 #include "platform/image-encoders/JPEGImageEncoder.h" 46 #include "platform/image-encoders/JPEGImageEncoder.h"
46 #include "platform/image-encoders/PNGImageEncoder.h" 47 #include "platform/image-encoders/PNGImageEncoder.h"
47 #include "platform/image-encoders/WEBPImageEncoder.h" 48 #include "platform/image-encoders/WEBPImageEncoder.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 void* data; 294 void* data;
294 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data); 295 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data);
295 if (!data) 296 if (!data)
296 return false; 297 return false;
297 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared); 298 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared);
298 result.transfer(contents); 299 result.transfer(contents);
299 return true; 300 return true;
300 } 301 }
301 302
302 ASSERT(canvas()); 303 ASSERT(canvas());
303 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonGetImageData); 304 AccelerationHint hint = ExpensiveCanvasHeuristicParameters::GetImageDataForc esNoAcceleration ? ForceNoAcceleration : PreferNoAcceleration;
xidachen 2016/06/15 14:12:36 We should probably do the same thing in putImageDa
305 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(hint, SnapshotReasonG etImageData);
304 if (!snapshot) 306 if (!snapshot)
305 return false; 307 return false;
306 308
307 const bool mayHaveStrayArea = 309 const bool mayHaveStrayArea =
308 m_surface->isAccelerated() // GPU readback may fail silently 310 m_surface->isAccelerated() // GPU readback may fail silently
309 || rect.x() < 0 311 || rect.x() < 0
310 || rect.y() < 0 312 || rect.y() < 0
311 || rect.maxX() > m_surface->size().width() 313 || rect.maxX() > m_surface->size().width()
312 || rect.maxY() > m_surface->size().height(); 314 || rect.maxY() > m_surface->size().height();
313 size_t allocSizeInBytes = rect.width() * rect.height() * 4; 315 size_t allocSizeInBytes = rect.width() * rect.height() * 4;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 402 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
401 403
402 Vector<unsigned char> result; 404 Vector<unsigned char> result;
403 if (!encodeImage(mimeType, quality, &result)) 405 if (!encodeImage(mimeType, quality, &result))
404 return "data:,"; 406 return "data:,";
405 407
406 return "data:" + mimeType + ";base64," + base64Encode(result); 408 return "data:" + mimeType + ";base64," + base64Encode(result);
407 } 409 }
408 410
409 } // namespace blink 411 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698