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

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

Issue 2141793002: Improving canvas 2D performance by switching graphics rendering pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor change 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 20 matching lines...) Expand all
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/ExpensiveCanvasHeuristicParameters.h"
39 #include "platform/graphics/GraphicsContext.h" 39 #include "platform/graphics/GraphicsContext.h"
40 #include "platform/graphics/ImageBufferClient.h" 40 #include "platform/graphics/ImageBufferClient.h"
41 #include "platform/graphics/RecordingImageBufferSurface.h"
41 #include "platform/graphics/StaticBitmapImage.h" 42 #include "platform/graphics/StaticBitmapImage.h"
42 #include "platform/graphics/UnacceleratedImageBufferSurface.h" 43 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
43 #include "platform/graphics/gpu/DrawingBuffer.h" 44 #include "platform/graphics/gpu/DrawingBuffer.h"
44 #include "platform/graphics/gpu/Extensions3DUtil.h" 45 #include "platform/graphics/gpu/Extensions3DUtil.h"
45 #include "platform/graphics/skia/SkiaUtils.h" 46 #include "platform/graphics/skia/SkiaUtils.h"
46 #include "platform/image-encoders/JPEGImageEncoder.h" 47 #include "platform/image-encoders/JPEGImageEncoder.h"
47 #include "platform/image-encoders/PNGImageEncoder.h" 48 #include "platform/image-encoders/PNGImageEncoder.h"
48 #include "platform/image-encoders/WEBPImageEncoder.h" 49 #include "platform/image-encoders/WEBPImageEncoder.h"
49 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
50 #include "public/platform/WebExternalTextureMailbox.h" 51 #include "public/platform/WebExternalTextureMailbox.h"
(...skipping 22 matching lines...) Expand all
73 74
74 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode) 75 std::unique_ptr<ImageBuffer> ImageBuffer::create(const IntSize& size, OpacityMod e opacityMode, ImageInitializationMode initializationMode)
75 { 76 {
76 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode))); 77 std::unique_ptr<ImageBufferSurface> surface(wrapUnique(new UnacceleratedImag eBufferSurface(size, opacityMode, initializationMode)));
77 if (!surface->isValid()) 78 if (!surface->isValid())
78 return nullptr; 79 return nullptr;
79 return wrapUnique(new ImageBuffer(std::move(surface))); 80 return wrapUnique(new ImageBuffer(std::move(surface)));
80 } 81 }
81 82
82 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface) 83 ImageBuffer::ImageBuffer(std::unique_ptr<ImageBufferSurface> surface)
83 : m_snapshotState(InitialSnapshotState) 84 : m_weakPtrFactory(this)
85 , m_snapshotState(InitialSnapshotState)
84 , m_surface(std::move(surface)) 86 , m_surface(std::move(surface))
85 , m_client(0) 87 , m_client(0)
86 , m_gpuMemoryUsage(0) 88 , m_gpuMemoryUsage(0)
87 { 89 {
88 m_surface->setImageBuffer(this); 90 m_surface->setImageBuffer(this);
89 updateGPUMemoryUsage(); 91 updateGPUMemoryUsage();
90 } 92 }
91 93
92 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0; 94 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0;
93 unsigned ImageBuffer::s_globalAcceleratedImageBufferCount = 0; 95 unsigned ImageBuffer::s_globalAcceleratedImageBufferCount = 0;
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } else if (m_gpuMemoryUsage) { 395 } else if (m_gpuMemoryUsage) {
394 // In case of switching from accelerated to non-accelerated mode, 396 // In case of switching from accelerated to non-accelerated mode,
395 // the GPU memory usage needs to be updated too. 397 // the GPU memory usage needs to be updated too.
396 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u); 398 DCHECK_GT(s_globalAcceleratedImageBufferCount, 0u);
397 s_globalAcceleratedImageBufferCount--; 399 s_globalAcceleratedImageBufferCount--;
398 s_globalGPUMemoryUsage -= m_gpuMemoryUsage; 400 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
399 m_gpuMemoryUsage = 0; 401 m_gpuMemoryUsage = 0;
400 } 402 }
401 } 403 }
402 404
405 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
406 public:
407 virtual std::unique_ptr<ImageBufferSurface> createSurface(const IntSize& siz e, OpacityMode opacityMode)
408 {
409 return wrapUnique(new UnacceleratedImageBufferSurface(size, opacityMode) );
410 }
411
412 virtual ~UnacceleratedSurfaceFactory() { }
413 };
414
415 void ImageBuffer::disableAcceleration()
416 {
417 if (!isAccelerated()) {
418 return;
419 }
420
421 // Get current frame.
422 SkImage* image = m_surface->newImageSnapshot(PreferNoAcceleration, SnapshotR easonPaint).get();
423
424 // Create and configure a recording (unaccelerated) surface.
425 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()));
427 surface->canvas()->drawImage(image, 0, 0);
428 surface->setImageBuffer(this);
429
430 // Replace the current surface with the new surface.
431 m_surface = std::move(surface);
432
433 didDisableAcceleration();
434 }
435
403 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 436 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
404 { 437 {
405 if (mimeType == "image/jpeg") { 438 if (mimeType == "image/jpeg") {
406 if (!JPEGImageEncoder::encode(*this, quality, encodedImage)) 439 if (!JPEGImageEncoder::encode(*this, quality, encodedImage))
407 return false; 440 return false;
408 } else if (mimeType == "image/webp") { 441 } else if (mimeType == "image/webp") {
409 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; 442 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality;
410 if (quality >= 0.0 && quality <= 1.0) 443 if (quality >= 0.0 && quality <= 1.0)
411 compressionQuality = static_cast<int>(quality * 100 + 0.5); 444 compressionQuality = static_cast<int>(quality * 100 + 0.5);
412 if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage)) 445 if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage))
(...skipping 12 matching lines...) Expand all
425 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 458 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
426 459
427 Vector<unsigned char> result; 460 Vector<unsigned char> result;
428 if (!encodeImage(mimeType, quality, &result)) 461 if (!encodeImage(mimeType, quality, &result))
429 return "data:,"; 462 return "data:,";
430 463
431 return "data:" + mimeType + ";base64," + base64Encode(result); 464 return "data:" + mimeType + ";base64," + base64Encode(result);
432 } 465 }
433 466
434 } // namespace blink 467 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ImageBuffer.h ('k') | third_party/WebKit/Source/web/WebRuntimeFeatures.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698