This is the third step in a three part change:
(1) Skia: Add SkBRDAllocator.
(2) Android: Make JavaPixelAllocator and RecyclingClippingPixelAllocator
implement SkBRDAllocator.
(3) Skia: Change SkBitmapRegionDecoder to use SkBRDAllocator and take
advantage of zero allocated memory when possible.
BUG=skia:
Review URL: https://codereview.chromium.org/
1420053010
, fDecoder(decoder)
{}
-bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
+bool SkBitmapRegionCanvas::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType,
bool requireUnpremul) {
// Reject color types not supported by this method
// TODO (msarett): Can we make this faster by implementing it to only
// zero parts of the image that we won't overwrite with
// pixels?
- // TODO (msarett): This could be skipped if memory is zero initialized.
- // This would matter if this code is moved to Android and
- // uses Android bitmaps.
if (SubsetType::kPartiallyInside_SubsetType == type) {
- bitmap->eraseColor(0);
+ SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() :
+ SkCodec::kNo_ZeroInitialized;
+ if (SkCodec::kNo_ZeroInitialized == zeroInit) {
+ bitmap->eraseColor(0);
+ }
}
// Use a canvas to crop and scale to the destination bitmap
*/
SkBitmapRegionCanvas(SkCodec* decoder);
- bool decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
+ bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize,
SkColorType colorType, bool requireUnpremul) override;
, fCodec(codec)
{}
-bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
+bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize, SkColorType dstColorType,
bool requireUnpremul) {
// TODO (msarett): Can we make this faster by implementing it to only
// zero parts of the image that we won't overwrite with
// pixels?
- // TODO (msarett): This could be skipped if memory is zero initialized.
- // This would matter if this code is moved to Android and
- // uses Android bitmaps.
- if (SubsetType::kPartiallyInside_SubsetType == type) {
+ SkCodec::ZeroInitialized zeroInit = allocator ? allocator->zeroInit() :
+ SkCodec::kNo_ZeroInitialized;
+ if (SubsetType::kPartiallyInside_SubsetType == type &&
+ SkCodec::kNo_ZeroInitialized == zeroInit) {
void* pixels = bitmap->getPixels();
size_t bytes = outInfo.getSafeSize(bitmap->rowBytes());
memset(pixels, 0, bytes);
options.fSubset = ⊂
options.fColorPtr = colorPtr;
options.fColorCount = colorCountPtr;
+ options.fZeroInitialized = zeroInit;
void* dst = bitmap->getAddr(scaledOutX, scaledOutY);
// FIXME: skbug.com/4538
*/
SkBitmapRegionCodec(SkAndroidCodec* codec);
- bool decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
+ bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize,
SkColorType colorType, bool requireUnpremul) override;
#define SkBitmapRegionDecoder_DEFINED
#include "SkBitmap.h"
+#include "SkBRDAllocator.h"
#include "SkEncodedFormat.h"
#include "SkStream.h"
* alpha type to use.
*
*/
- virtual bool decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
+ virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize,
SkColorType colorType, bool requireUnpremul) = 0;
/*