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

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: included missing file 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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 bool ImageBuffer::isSurfaceValid() const 119 bool ImageBuffer::isSurfaceValid() const
119 { 120 {
120 return m_surface->isValid(); 121 return m_surface->isValid();
121 } 122 }
122 123
123 bool ImageBuffer::isDirty() 124 bool ImageBuffer::isDirty()
124 { 125 {
125 return m_client ? m_client->isDirty() : false; 126 return m_client ? m_client->isDirty() : false;
126 } 127 }
127 128
129 void ImageBuffer::didDisableAcceleration() const
130 {
131 DCHECK(m_gpuMemoryUsage);
132 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u);
133 if (m_client)
134 m_client->didDisableAcceleration();
135 s_globalAcceleratedImageBufferCount--;
136 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
137 }
138
128 void ImageBuffer::didFinalizeFrame() 139 void ImageBuffer::didFinalizeFrame()
129 { 140 {
130 if (m_client) 141 if (m_client)
131 m_client->didFinalizeFrame(); 142 m_client->didFinalizeFrame();
132 } 143 }
133 144
134 void ImageBuffer::finalizeFrame(const FloatRect &dirtyRect) 145 void ImageBuffer::finalizeFrame(const FloatRect &dirtyRect)
135 { 146 {
136 m_surface->finalizeFrame(dirtyRect); 147 m_surface->finalizeFrame(dirtyRect);
137 didFinalizeFrame(); 148 didFinalizeFrame();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 void* data; 311 void* data;
301 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data); 312 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data);
302 if (!data) 313 if (!data)
303 return false; 314 return false;
304 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared); 315 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared);
305 result.transfer(contents); 316 result.transfer(contents);
306 return true; 317 return true;
307 } 318 }
308 319
309 DCHECK(canvas()); 320 DCHECK(canvas());
310 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonGetImageData); 321 AccelerationHint hint = (ExpensiveCanvasHeuristicParameters::GetImageDataFor cesNoAcceleration) ? ForceNoAcceleration : PreferNoAcceleration;
322 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(hint, SnapshotReasonG etImageData);
311 if (!snapshot) 323 if (!snapshot)
312 return false; 324 return false;
313 325
314 const bool mayHaveStrayArea = 326 const bool mayHaveStrayArea =
315 m_surface->isAccelerated() // GPU readback may fail silently 327 m_surface->isAccelerated() // GPU readback may fail silently
316 || rect.x() < 0 328 || rect.x() < 0
317 || rect.y() < 0 329 || rect.y() < 0
318 || rect.maxX() > m_surface->size().width() 330 || rect.maxX() > m_surface->size().width()
319 || rect.maxY() > m_surface->size().height(); 331 || rect.maxY() > m_surface->size().height();
320 size_t allocSizeInBytes = rect.width() * rect.height() * 4; 332 size_t allocSizeInBytes = rect.width() * rect.height() * 4;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 424 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
413 425
414 Vector<unsigned char> result; 426 Vector<unsigned char> result;
415 if (!encodeImage(mimeType, quality, &result)) 427 if (!encodeImage(mimeType, quality, &result))
416 return "data:,"; 428 return "data:,";
417 429
418 return "data:" + mimeType + ";base64," + base64Encode(result); 430 return "data:" + mimeType + ";base64," + base64Encode(result);
419 } 431 }
420 432
421 } // namespace blink 433 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698