Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2540)

Unified Diff: src/lazy/SkDiscardablePixelRef.cpp

Issue 1199473002: change old picture serialization to really handle images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/lazy/SkDiscardablePixelRef.cpp
diff --git a/src/lazy/SkDiscardablePixelRef.cpp b/src/lazy/SkDiscardablePixelRef.cpp
index 1e42042fb6d10c05626f8a3d5bedd28dfcb257c8..0d34b63e1d592084669b2d18bef6c32bc4286d8e 100644
--- a/src/lazy/SkDiscardablePixelRef.cpp
+++ b/src/lazy/SkDiscardablePixelRef.cpp
@@ -107,19 +107,31 @@ void SkDiscardablePixelRef::onUnlockPixels() {
fDiscardableMemoryIsLocked = false;
}
-bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
+bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, const SkIRect* subset, SkBitmap* dst,
SkDiscardableMemory::Factory* factory) {
SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
if (NULL == autoGenerator.get()) {
return false;
}
+
+ SkIPoint origin = SkIPoint::Make(0, 0);
SkImageInfo info = autoGenerator->getInfo();
- if (info.isEmpty() || !dst->setInfo(info)) {
+ if (info.isEmpty()) {
+ return false;
+ }
+ if (subset) {
+ if (subset->isEmpty() || !SkIRect::MakeWH(info.width(), info.height()).contains(*subset)) {
+ return false;
+ }
+ info = info.makeWH(subset->width(), subset->height());
+ origin.set(subset->x(), subset->y());
+ }
+ if (!dst->setInfo(info)) {
return false;
}
+
// Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap
info = dst->info();
-
SkASSERT(info.colorType() != kUnknown_SkColorType);
if (dst->empty()) { // Use a normal pixelref.
return dst->tryAllocPixels();
@@ -127,17 +139,17 @@ bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
SkAutoTUnref<SkDiscardablePixelRef> ref(
SkNEW_ARGS(SkDiscardablePixelRef,
(info, autoGenerator.detach(), dst->rowBytes(), factory)));
- dst->setPixelRef(ref);
+ dst->setPixelRef(ref, origin.x(), origin.y());
return true;
}
// These are the public API
bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) {
- return SkInstallDiscardablePixelRef(generator, dst, NULL);
+ return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL);
}
bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded);
- return generator ? SkInstallDiscardablePixelRef(generator, dst, NULL) : false;
+ return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL) : false;
}
« gm/factory.cpp ('K') | « src/lazy/SkDiscardablePixelRef.h ('k') | src/utils/SkLua.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698