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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/ImageBuffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
index c27bd0b4bda46877646770f62154060f5f5926d0..569b10bfd7a50193c0d6244057592bcb7e289eb6 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp
@@ -79,12 +79,17 @@ ImageBuffer::ImageBuffer(PassOwnPtr<ImageBufferSurface> surface)
: m_snapshotState(InitialSnapshotState)
, m_surface(surface)
, m_client(0)
+ , m_gpuMemoryUsage(0)
{
m_surface->setImageBuffer(this);
+ updateGPUMemoryUsage();
}
+intptr_t ImageBuffer::s_globalGPUMemoryUsage = 0;
+
ImageBuffer::~ImageBuffer()
{
+ ImageBuffer::s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
}
SkCanvas* ImageBuffer::canvas() const
@@ -343,6 +348,28 @@ void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source,
m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY);
}
+void ImageBuffer::updateGPUMemoryUsage() const
+{
+ if (this->isAccelerated()) {
+ // If image buffer is accelerated, we should keep track of GPU memory usage.
+ int gpuBufferCount = 2;
+ Checked<intptr_t, RecordOverflow> checkedGPUUsage = 4 * gpuBufferCount;
+ checkedGPUUsage *= this->size().width();
+ checkedGPUUsage *= this->size().height();
+ intptr_t gpuMemoryUsage;
+ if (checkedGPUUsage.safeGet(gpuMemoryUsage) == CheckedState::DidOverflow)
+ gpuMemoryUsage = std::numeric_limits<intptr_t>::max();
+
+ s_globalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage);
+ m_gpuMemoryUsage = gpuMemoryUsage;
+ } else if (m_gpuMemoryUsage > 0) {
+ // In case of switching from accelerated to non-accelerated mode,
+ // the GPU memory usage needs to be updated too.
+ s_globalGPUMemoryUsage -= m_gpuMemoryUsage;
+ m_gpuMemoryUsage = 0;
+ }
+}
+
bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const
{
if (mimeType == "image/jpeg") {
« 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