OLD | NEW |
---|---|
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 Loading... | |
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_totalGPUMemoryUsage = 0; | |
89 | |
86 ImageBuffer::~ImageBuffer() | 90 ImageBuffer::~ImageBuffer() |
87 { | 91 { |
92 ImageBuffer::s_totalGPUMemoryUsage -= m_gpuMemoryUsage; | |
88 } | 93 } |
89 | 94 |
90 SkCanvas* ImageBuffer::canvas() const | 95 SkCanvas* ImageBuffer::canvas() const |
91 { | 96 { |
92 if (!isSurfaceValid()) | 97 if (!isSurfaceValid()) |
93 return nullptr; | 98 return nullptr; |
94 return m_surface->canvas(); | 99 return m_surface->canvas(); |
95 } | 100 } |
96 | 101 |
97 void ImageBuffer::disableDeferral() const | 102 void ImageBuffer::disableDeferral() const |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 ASSERT(originY >= 0); | 343 ASSERT(originY >= 0); |
339 ASSERT(originY < sourceRect.maxY()); | 344 ASSERT(originY < sourceRect.maxY()); |
340 | 345 |
341 const size_t srcBytesPerRow = 4 * sourceSize.width(); | 346 const size_t srcBytesPerRow = 4 * sourceSize.width(); |
342 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; | 347 const void* srcAddr = source + originY * srcBytesPerRow + originX * 4; |
343 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 348 SkAlphaType alphaType = (multiplied == Premultiplied) ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
344 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType); | 349 SkImageInfo info = SkImageInfo::Make(sourceRect.width(), sourceRect.height() , kRGBA_8888_SkColorType, alphaType); |
345 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); | 350 m_surface->writePixels(info, srcAddr, srcBytesPerRow, destX, destY); |
346 } | 351 } |
347 | 352 |
353 void ImageBuffer::updateGPUMemoryUsage() const | |
354 { | |
355 // If image buffer is accelerated, we should keep track of GPU memory usage. | |
356 if (this->isAccelerated()) { | |
357 int gpuBufferCount = 2; | |
358 Checked<intptr_t, RecordOverflow> checkedGPUUsage = 4 * gpuBufferCount; | |
359 checkedGPUUsage *= this->size().width(); | |
360 checkedGPUUsage *= this->size().height(); | |
361 intptr_t gpuMemoryUsage; | |
362 if (checkedGPUUsage.safeGet(gpuMemoryUsage) == CheckedState::DidOverflow ) | |
363 gpuMemoryUsage = std::numeric_limits<intptr_t>::max(); | |
364 | |
365 s_totalGPUMemoryUsage += (gpuMemoryUsage - m_gpuMemoryUsage); | |
366 m_gpuMemoryUsage = gpuMemoryUsage; | |
367 } | |
Justin Novosad
2015/12/08 22:15:27
In the case where we are not accelerated, you need
| |
368 } | |
369 | |
348 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const | 370 bool ImageDataBuffer::encodeImage(const String& mimeType, const double& quality, Vector<unsigned char>* encodedImage) const |
349 { | 371 { |
350 if (mimeType == "image/jpeg") { | 372 if (mimeType == "image/jpeg") { |
351 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; | 373 int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality; |
352 if (quality >= 0.0 && quality <= 1.0) | 374 if (quality >= 0.0 && quality <= 1.0) |
353 compressionQuality = static_cast<int>(quality * 100 + 0.5); | 375 compressionQuality = static_cast<int>(quality * 100 + 0.5); |
354 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage)) | 376 if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage)) |
355 return false; | 377 return false; |
356 } else if (mimeType == "image/webp") { | 378 } else if (mimeType == "image/webp") { |
357 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; | 379 int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality; |
(...skipping 15 matching lines...) Expand all Loading... | |
373 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 395 ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
374 | 396 |
375 Vector<unsigned char> result; | 397 Vector<unsigned char> result; |
376 if (!encodeImage(mimeType, quality, &result)) | 398 if (!encodeImage(mimeType, quality, &result)) |
377 return "data:,"; | 399 return "data:,"; |
378 | 400 |
379 return "data:" + mimeType + ";base64," + base64Encode(result); | 401 return "data:" + mimeType + ";base64," + base64Encode(result); |
380 } | 402 } |
381 | 403 |
382 } // namespace blink | 404 } // namespace blink |
OLD | NEW |