// SkImage::withMipmaps will always make a copy for us so we can temporarily share // the pixel ref with fBitmap
SkBitmap tmpSubset; if (!fBitmap.extractSubset(&tmpSubset, subset)) { return nullptr;
}
sk_sp<SkImage> tmp( new SkImage_Raster(tmpSubset, /*mips=*/nullptr, /* bitmapMayBeMutable= */ true));
// withMipmaps will auto generate the mipmaps if a nullptr is passed in
SkASSERT(!mips || mips->validForRootLevel(tmp->imageInfo()));
img = tmp->withMipmaps(std::move(mips));
} else {
SkBitmap copy = copy_bitmap_subset(fBitmap, subset); if (!copy.isNull()) {
img = SkImages::RasterFromBitmap(copy);
}
}
bool SkImage_Raster::onAsLegacyBitmap(GrDirectContext*, SkBitmap* bitmap) const { // When we're a snapshot from a surface, our bitmap may not be marked immutable // even though logically always we are, but in that case we can't physically share our // pixelref since the caller might call setImmutable() themselves // (thus changing our state). if (fBitmap.isImmutable()) {
SkIPoint origin = fBitmap.pixelRefOrigin();
bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
bitmap->setPixelRef(sk_ref_sp(fBitmap.pixelRef()), origin.x(), origin.y()); return true;
} return this->SkImage_Base::onAsLegacyBitmap(nullptr, bitmap);
}
sk_sp<SkShader> SkImage_Raster::makeShaderForPaint(const SkPaint& paint,
SkTileMode tmx,
SkTileMode tmy, const SkSamplingOptions& sampling, const SkMatrix* localMatrix) { auto s = SkImageShader::Make(sk_ref_sp<SkImage>(this), tmx, tmy, sampling, localMatrix); if (!s) { return nullptr;
} if (SkColorTypeIsAlphaOnly(this->colorType()) && paint.getShader()) { // Compose the image shader with the paint's shader. Alpha images+shaders should output the // texture's alpha multiplied by the shader's color. DstIn (d*sa) will achieve this with // the source image and dst shader (MakeBlend takes dst first, src second).
s = SkShaders::Blend(SkBlendMode::kDstIn, paint.refShader(), std::move(s));
} return s;
}
sk_sp<SkImage> SkImage_Raster::onMakeWithMipmaps(sk_sp<SkMipmap> mips) const { // It's dangerous to have two SkBitmaps that share a SkPixelRef but have different SkMipmaps // since various caches key on SkPixelRef's generation ID. Also, SkPixelRefs that back // SkSurfaces are marked "temporarily immutable" and making an image that uses the same // SkPixelRef can interact badly with SkSurface/SkImage copy-on-write. So we just always // make a copy with a new ID. if (!mips) {
mips.reset(SkMipmap::Build(fBitmap.pixmap(), nullptr));
} return SkImage_Raster::MakeFromBitmap(fBitmap, SkCopyPixelsMode::kAlways, std::move(mips));
}
sk_sp<SkImage> SkImage_Raster::onReinterpretColorSpace(sk_sp<SkColorSpace> newCS) const{ // TODO: If our bitmap is immutable, then we could theoretically create another image sharing // our pixelRef. That doesn't work (without more invasive logic), because the image gets its // gen ID from the bitmap, which gets it from the pixelRef.
SkPixmap pixmap = fBitmap.pixmap();
pixmap.setColorSpace(std::move(newCS)); return SkImages::RasterFromPixmapCopy(pixmap);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.