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

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

Powered by Google App Engine
This is Rietveld 408576698