void SkSurface_Raster::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkSamplingOptions& sampling, const SkPaint* paint) {
canvas->drawImage(fBitmap.asImage().get(), x, y, sampling, paint);
}
sk_sp<SkImage> SkSurface_Raster::onNewImageSnapshot(const SkIRect* subset) { if (subset) {
SkASSERT(SkIRect::MakeWH(fBitmap.width(), fBitmap.height()).contains(*subset));
SkBitmap dst;
dst.allocPixels(fBitmap.info().makeDimensions(subset->size()));
SkAssertResult(fBitmap.readPixels(dst.pixmap(), subset->left(), subset->top()));
dst.setImmutable(); // key, so MakeFromBitmap doesn't make a copy of the buffer return dst.asImage();
}
SkCopyPixelsMode cpm = kIfMutable_SkCopyPixelsMode; if (fWeOwnThePixels) { // SkImage_raster requires these pixels are immutable for its full lifetime. // We'll undo this via onRestoreBackingMutability() if we can avoid the COW. if (SkPixelRef* pr = fBitmap.pixelRef()) {
pr->setTemporarilyImmutable();
}
} else {
cpm = kAlways_SkCopyPixelsMode;
}
// Our pixels are in memory, so read access on the snapshot SkImage could be cheap. // Lock the shared pixel ref to ensure peekPixels() is usable. return SkMakeImageFromRasterBitmap(fBitmap, cpm);
}
void SkSurface_Raster::onWritePixels(const SkPixmap& src, int x, int y) {
fBitmap.writePixels(src, x, y);
}
void SkSurface_Raster::onRestoreBackingMutability() {
SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there. if (SkPixelRef* pr = fBitmap.pixelRef()) {
pr->restoreMutability();
}
}
bool SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { // are we sharing pixelrefs with the image?
sk_sp<SkImage> cached(this->refCachedImage());
SkASSERT(cached); if (SkBitmapImageGetPixelRef(cached.get()) == fBitmap.pixelRef()) {
SkASSERT(fWeOwnThePixels); if (kDiscard_ContentChangeMode == mode) { if (!fBitmap.tryAllocPixels()) { returnfalse;
}
} else {
SkBitmap prev(fBitmap); if (!fBitmap.tryAllocPixels()) { returnfalse;
}
SkASSERT(prev.info() == fBitmap.info());
SkASSERT(prev.rowBytes() == fBitmap.rowBytes());
memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.computeByteSize());
}
// Now fBitmap is a deep copy of itself (and therefore different from // what is being used by the image. Next we update the canvas to use // this as its backend, so we can't modify the image's pixels anymore.
SkASSERT(this->getCachedCanvas());
SkBitmapDevice* bmDev = static_cast<SkBitmapDevice*>(this->getCachedCanvas()->rootDevice());
bmDev->replaceBitmapBackendForRasterSurface(fBitmap);
} returntrue;
}
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.