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

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

Issue 1482363004: Fixing laggy chrome on a multitude of accelerated canvases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: m_imageBuffer nullibility check to ensure other unrelated unit tests on layerbridge not fail Created 5 years 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
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ImageBuffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 OwnPtr<ImageBufferSurface> surface(adoptPtr(new UnacceleratedImageBufferSurf ace(size, opacityMode, initializationMode))); 72 OwnPtr<ImageBufferSurface> surface(adoptPtr(new UnacceleratedImageBufferSurf ace(size, opacityMode, initializationMode)));
73 if (!surface->isValid()) 73 if (!surface->isValid())
74 return nullptr; 74 return nullptr;
75 return adoptPtr(new ImageBuffer(surface.release())); 75 return adoptPtr(new ImageBuffer(surface.release()));
76 } 76 }
77 77
78 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface) 78 ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface)
79 : m_snapshotState(InitialSnapshotState) 79 : m_snapshotState(InitialSnapshotState)
80 , m_surface(surface) 80 , m_surface(surface)
81 , m_client(0) 81 , m_client(0)
82 , m_gpuMemoryUsage(0)
82 { 83 {
83 m_surface->setImageBuffer(this); 84 m_surface->setImageBuffer(this);
85 updateGPUMemoryUsage();
84 } 86 }
85 87
88 intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0;
89
86 ImageBuffer::~ImageBuffer() 90 ImageBuffer::~ImageBuffer()
87 { 91 {
92 ImageBuffer::s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
88 } 93 }
89 94
90 SkCanvas* ImageBuffer::canvas() const 95 SkCanvas* ImageBuffer::canvas() const
91 { 96 {
92 return m_surface->canvas(); 97 return m_surface->canvas();
93 } 98 }
94 99
95 void ImageBuffer::disableDeferral() const 100 void ImageBuffer::disableDeferral() const
96 { 101 {
97 return m_surface->disableDeferral(); 102 return m_surface->disableDeferral();
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ASSERT(originY >= 0); 341 ASSERT(originY >= 0);
337 ASSERT(originY < sourceRect.maxY()); 342 ASSERT(originY < sourceRect.maxY());
338 343
339 const size_t srcBytesPerRow = 4 * sourceSize.width(); 344 const size_t srcBytesPerRow = 4 * sourceSize.width();
340 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; 345 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4;
341 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 346 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
342 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType); 347 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType);
343 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); 348 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
344 } 349 }
345 350
351 void ImageBuffer::updateGPUMemoryUsage() const
352 {
353 if (this->isAccelerated()) {
354 // If image buffer is accelerated, we should keep track of GPU memory us age.
355 int gpuBufferCount = 2;
356 Checked<intptr_t, RecordOverflow> checkedGPUUsage = 4 * gpuBufferCount;
357 checkedGPUUsage *= this->size().width();
358 checkedGPUUsage *= this->size().height();
359 intptr_t gpuMemoryUsage;
360 if (checkedGPUUsage.safeGet(gpuMemoryUsage) == CheckedState::DidOverflow )
361 gpuMemoryUsage = std::numeric_limits<intptr_t>::max();
362
363 s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage);
364 m_gpuMemoryUsage = gpuMemoryUsage;
365 } else if (m_gpuMemoryUsage > 0) {
366 // In case of switching from accelerated to non-accelerated mode,
367 // the GPU memory usage needs to be updated too.
368 s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
369 m_gpuMemoryUsage = 0;
370 }
371 }
372
346 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const 373 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
347 { 374 {
348 if (mimeType == "image/jpeg") { 375 if (mimeType == "image/jpeg") {
349 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; 376 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
350 if (quality >= 0.0 && quality <= 1.0) 377 if (quality >= 0.0 && quality <= 1.0)
351 compressionQuality = static_cast<int>(quality * 100 + 0.5); 378 compressionQuality = static_cast<int>(quality * 100 + 0.5);
352 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage)) 379 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage))
353 return false; 380 return false;
354 } else if (mimeType == "image/webp") { 381 } else if (mimeType == "image/webp") {
355 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; 382 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality;
(...skipping 15 matching lines...) Expand all
371 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); 398 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
372 399
373 Vector<unsigned char> result; 400 Vector<unsigned char> result;
374 if (!encodeImage(mimeType, quality, &result)) 401 if (!encodeImage(mimeType, quality, &result))
375 return "data:,"; 402 return "data:,";
376 403
377 return "data:" + mimeType + ";base64," + base64Encode(result); 404 return "data:" + mimeType + ";base64," + base64Encode(result);
378 } 405 }
379 406
380 } // namespace blink 407 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ImageBuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698