Chromium Code Reviews| 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 de389a8901b6e456b9e34973a72910200086397e..f066e364ee4bac531189fe8ae5401b17889db48b 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_totalGPUMemoryUsage = 0; |
| + |
| ImageBuffer::~ImageBuffer() |
| { |
| + ImageBuffer::s_totalGPUMemoryUsage -= m_gpuMemoryUsage; |
| } |
| SkCanvas* ImageBuffer::canvas() const |
| @@ -345,6 +350,23 @@ void ImageBuffer::putByteArray(Multiply multiplied, const unsigned char* source, |
| m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
| } |
| +void ImageBuffer::updateGPUMemoryUsage() const |
| +{ |
| + // If image buffer is accelerated, we should keep track of GPU memory usage. |
| + if (this->isAccelerated()) { |
| + 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_totalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage); |
| + m_gpuMemoryUsage = gpuMemoryUsage; |
| + } |
|
Justin Novosad
2015/12/08 22:15:27
In the case where we are not accelerated, you need
|
| +} |
| + |
| bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const |
| { |
| if (mimeType == "image/jpeg") { |