///////////////////////////////////////////////////////////////////////////////
-static bool raster_canvas_supports(const SkImageInfo& info) {
- switch (info.colorType()) {
- case kN32_SkColorType:
- return kUnpremul_SkAlphaType != info.alphaType();
- case kRGB_565_SkColorType:
- return true;
- case kAlpha_8_SkColorType:
- return true;
- default:
- break;
- }
- return false;
-}
-
SkImage_Base::SkImage_Base(int width, int height, uint32_t uniqueID)
: INHERITED(width, height, uniqueID)
, fAddedToCache(false)
}
}
-bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
- int srcX, int srcY, CachingHint) const {
- if (!raster_canvas_supports(dstInfo)) {
- return false;
- }
-
- SkBitmap bm;
- bm.installPixels(dstInfo, dstPixels, dstRowBytes);
- SkCanvas canvas(bm);
-
- SkPaint paint;
- paint.setBlendMode(SkBlendMode::kSrc);
- canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
-
- return true;
-}
-
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY, CachingHint chint) const {
virtual const SkBitmap* onPeekBitmap() const { return nullptr; }
- // Default impl calls onDraw
virtual bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes,
- int srcX, int srcY, CachingHint) const;
+ int srcX, int srcY, CachingHint) const = 0;
virtual GrTexture* peekTexture() const { return nullptr; }
#if SK_SUPPORT_GPU