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

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

Issue 2101823002: Revert of 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, 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"
39 #include "platform/graphics/GraphicsContext.h" 38 #include "platform/graphics/GraphicsContext.h"
40 #include "platform/graphics/ImageBufferClient.h" 39 #include "platform/graphics/ImageBufferClient.h"
41 #include "platform/graphics/StaticBitmapImage.h" 40 #include "platform/graphics/StaticBitmapImage.h"
42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 41 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
43 #include "platform/graphics/gpu/DrawingBuffer.h" 42 #include "platform/graphics/gpu/DrawingBuffer.h"
44 #include "platform/graphics/gpu/Extensions3DUtil.h" 43 #include "platform/graphics/gpu/Extensions3DUtil.h"
45 #include "platform/graphics/skia/SkiaUtils.h" 44 #include "platform/graphics/skia/SkiaUtils.h"
46 #include "platform/image-encoders/JPEGImageEncoder.h" 45 #include "platform/image-encoders/JPEGImageEncoder.h"
47 #include "platform/image-encoders/PNGImageEncoder.h" 46 #include "platform/image-encoders/PNGImageEncoder.h"
48 #include "platform/image-encoders/WEBPImageEncoder.h" 47 #include "platform/image-encoders/WEBPImageEncoder.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 bool ImageBuffer::isSurfaceValid() const 118 bool ImageBuffer::isSurfaceValid() const
120 { 119 {
121 return m_surface->isValid(); 120 return m_surface->isValid();
122 } 121 }
123 122
124 bool ImageBuffer::isDirty() 123 bool ImageBuffer::isDirty()
125 { 124 {
126 return m_client ? m_client->isDirty() : false; 125 return m_client ? m_client->isDirty() : false;
127 } 126 }
128 127
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
140 void ImageBuffer::didFinalizeFrame() 128 void ImageBuffer::didFinalizeFrame()
141 { 129 {
142 if (m_client) 130 if (m_client)
143 m_client->didFinalizeFrame(); 131 m_client->didFinalizeFrame();
144 } 132 }
145 133
146 void ImageBuffer::finalizeFrame(const FloatRect &dirtyRect) 134 void ImageBuffer::finalizeFrame(const FloatRect &dirtyRect)
147 { 135 {
148 m_surface->finalizeFrame(dirtyRect); 136 m_surface->finalizeFrame(dirtyRect);
149 didFinalizeFrame(); 137 didFinalizeFrame();
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 void* data; 300 void* data;
313 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data); 301 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, WTF::Ar rayBufferContents::ZeroInitialize, data);
314 if (!data) 302 if (!data)
315 return false; 303 return false;
316 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared); 304 WTF::ArrayBufferContents result(data, allocSizeInBytes, WTF::ArrayBuffer Contents::NotShared);
317 result.transfer(contents); 305 result.transfer(contents);
318 return true; 306 return true;
319 } 307 }
320 308
321 DCHECK(canvas()); 309 DCHECK(canvas());
322 AccelerationHint hint = (ExpensiveCanvasHeuristicParameters::GetImageDataFor cesNoAcceleration) ? ForceNoAcceleration : PreferNoAcceleration; 310 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotReasonGetImageData);
323 RefPtr<SkImage> snapshot = m_surface->newImageSnapshot(hint, SnapshotReasonG etImageData);
324 if (!snapshot) 311 if (!snapshot)
325 return false; 312 return false;
326 313
327 const bool mayHaveStrayArea = 314 const bool mayHaveStrayArea =
328 m_surface->isAccelerated() // GPU readback may fail silently 315 m_surface->isAccelerated() // GPU readback may fail silently
329 || rect.x() < 0 316 || rect.x() < 0
330 || rect.y() < 0 317 || rect.y() < 0
331 || rect.maxX() > m_surface->size().width() 318 || rect.maxX() > m_surface->size().width()
332 || rect.maxY() > m_surface->size().height(); 319 || rect.maxY() > m_surface->size().height();
333 size_t allocSizeInBytes = rect.width() * rect.height() * 4; 320 size_t allocSizeInBytes = rect.width() * rect.height() * 4;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 412 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
426 413
427 Vector<unsigned char> result; 414 Vector<unsigned char> result;
428 if (!encodeImage(mimeType, quality, &result)) 415 if (!encodeImage(mimeType, quality, &result))
429 return "data:,"; 416 return "data:,";
430 417
431 return "data:" + mimeType + ";base64," + base64Encode(result); 418 return "data:" + mimeType + ";base64," + base64Encode(result);
432 } 419 }
433 420
434 } // namespace blink 421 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698