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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDiscardablePixelRef.h" 8 #include "SkDiscardablePixelRef.h"
9 #include "SkDiscardableMemory.h" 9 #include "SkDiscardableMemory.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 rec->fColorTable = fCTable.get(); 100 rec->fColorTable = fCTable.get();
101 rec->fRowBytes = fRowBytes; 101 rec->fRowBytes = fRowBytes;
102 return true; 102 return true;
103 } 103 }
104 104
105 void SkDiscardablePixelRef::onUnlockPixels() { 105 void SkDiscardablePixelRef::onUnlockPixels() {
106 fDiscardableMemory->unlock(); 106 fDiscardableMemory->unlock();
107 fDiscardableMemoryIsLocked = false; 107 fDiscardableMemoryIsLocked = false;
108 } 108 }
109 109
110 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, 110 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, const SkIRect* su bset, SkBitmap* dst,
111 SkDiscardableMemory::Factory* factory) { 111 SkDiscardableMemory::Factory* factory) {
112 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); 112 SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
113 if (NULL == autoGenerator.get()) { 113 if (NULL == autoGenerator.get()) {
114 return false; 114 return false;
115 } 115 }
116 SkImageInfo info = autoGenerator->getInfo(); 116
117 if (info.isEmpty() || !dst->setInfo(info)) { 117 SkImageInfo prInfo = autoGenerator->getInfo();
118 if (prInfo.isEmpty()) {
118 return false; 119 return false;
119 } 120 }
120 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap
121 info = dst->info();
122 121
123 SkASSERT(info.colorType() != kUnknown_SkColorType); 122 SkIPoint origin = SkIPoint::Make(0, 0);
123 SkImageInfo bmInfo = prInfo;
124 if (subset) {
125 const SkIRect prBounds = SkIRect::MakeWH(prInfo.width(), prInfo.height() );
126 if (subset->isEmpty() || !prBounds.contains(*subset)) {
127 return false;
128 }
129 bmInfo = prInfo.makeWH(subset->width(), subset->height());
130 origin.set(subset->x(), subset->y());
131 }
132
133 // must compute our desired rowBytes w.r.t. the pixelRef's dimensions, now o urs, which may be
scroggo 2015/06/22 17:40:01 not* ours
reed1 2015/06/22 18:41:51 Done.
134 // smaller.
135 if (!dst->setInfo(bmInfo, prInfo.minRowBytes())) {
136 return false;
137 }
138
139 // Since dst->setInfo() may have changed/fixed-up info, we check from the bi tmap
140 SkASSERT(dst->info().colorType() != kUnknown_SkColorType);
141
124 if (dst->empty()) { // Use a normal pixelref. 142 if (dst->empty()) { // Use a normal pixelref.
125 return dst->tryAllocPixels(); 143 return dst->tryAllocPixels();
126 } 144 }
127 SkAutoTUnref<SkDiscardablePixelRef> ref( 145 SkAutoTUnref<SkDiscardablePixelRef> ref(
128 SkNEW_ARGS(SkDiscardablePixelRef, 146 SkNEW_ARGS(SkDiscardablePixelRef,
129 (info, autoGenerator.detach(), dst->rowBytes(), factory))); 147 (prInfo, autoGenerator.detach(), dst->rowBytes(), factory)));
130 dst->setPixelRef(ref); 148 dst->setPixelRef(ref, origin.x(), origin.y());
131 return true; 149 return true;
132 } 150 }
133 151
134 // These are the public API 152 // These are the public API
135 153
136 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { 154 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) {
137 return SkInstallDiscardablePixelRef(generator, dst, NULL); 155 return SkInstallDiscardablePixelRef(generator, NULL, dst, NULL);
138 } 156 }
139 157
140 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) { 158 bool SkInstallDiscardablePixelRef(SkData* encoded, SkBitmap* dst) {
141 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded); 159 SkImageGenerator* generator = SkImageGenerator::NewFromData(encoded);
142 return generator ? SkInstallDiscardablePixelRef(generator, dst, NULL) : fals e; 160 return generator ? SkInstallDiscardablePixelRef(generator, NULL, dst, NULL) : false;
143 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698