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

Side by Side Diff: src/image/SkImage.cpp

Issue 1364443002: remove unused (by the outside) SkImage::newSurface, and simplify newImage -> newSubset (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « samplecode/SampleFilterQuality.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 121 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
122 if (nullptr == encoded || 0 == encoded->size()) { 122 if (nullptr == encoded || 0 == encoded->size()) {
123 return nullptr; 123 return nullptr;
124 } 124 }
125 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded); 125 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded);
126 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr; 126 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
127 } 127 }
128 128
129 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const {
130 if (nullptr == props) {
131 props = &as_IB(this)->props();
132 }
133 return as_IB(this)->onNewSurface(info, *props);
134 }
135
136 const char* SkImage::toString(SkString* str) const { 129 const char* SkImage::toString(SkString* str) const {
137 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), 130 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
138 this->isOpaque() ? "opaque" : ""); 131 this->isOpaque() ? "opaque" : "");
139 return str->c_str(); 132 return str->c_str();
140 } 133 }
141 134
142 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset, 135 #ifdef SK_SUPPORT_LEGACY_NEWIMAGE
143 SkFilterQuality quality) const { 136 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset) c onst {
137 #if 0
144 if (newWidth <= 0 || newHeight <= 0) { 138 if (newWidth <= 0 || newHeight <= 0) {
145 return nullptr; 139 return nullptr;
146 } 140 }
147 141
148 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); 142 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
149 143
150 if (subset) { 144 if (subset) {
151 if (!bounds.contains(*subset)) { 145 if (!bounds.contains(*subset)) {
152 return nullptr; 146 return nullptr;
153 } 147 }
154 if (bounds == *subset) { 148 if (bounds == *subset) {
155 subset = nullptr; // and fall through to check below 149 subset = nullptr; // and fall through to check below
156 } 150 }
157 } 151 }
158 152
159 if (nullptr == subset && this->width() == newWidth && this->height() == newH eight) { 153 if (nullptr == subset && this->width() == newWidth && this->height() == newH eight) {
160 return SkRef(const_cast<SkImage*>(this)); 154 return SkRef(const_cast<SkImage*>(this));
161 } 155 }
162 156
163 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); 157 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
158 #else
159 SkASSERT(subset);
160 SkASSERT(subset->width() == newWidth);
161 SkASSERT(subset->height() == newHeight);
162 return this->newSubset(*subset);
163 #endif
164 }
165 #endif
166
167 SkImage* SkImage::newSubset(const SkIRect& subset) const {
168 if (subset.isEmpty()) {
169 return nullptr;
170 }
171
172 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
173 if (!bounds.contains(subset)) {
174 return nullptr;
175 }
176
177 // optimization : return self if the subset == our bounds
178 if (bounds == subset) {
179 return SkRef(const_cast<SkImage*>(this));
180 }
181 return as_IB(this)->onNewSubset(subset);
164 } 182 }
165 183
166 #if SK_SUPPORT_GPU 184 #if SK_SUPPORT_GPU
167 185
168 GrTexture* SkImage::getTexture() const { 186 GrTexture* SkImage::getTexture() const {
169 return as_IB(this)->peekTexture(); 187 return as_IB(this)->peekTexture();
170 } 188 }
171 189
172 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture( )); } 190 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture( )); }
173 191
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 255 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
238 SkCanvas canvas(bm); 256 SkCanvas canvas(bm);
239 257
240 SkPaint paint; 258 SkPaint paint;
241 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 259 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
242 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 260 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
243 261
244 return true; 262 return true;
245 } 263 }
246 264
247 SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* su bset,
248 SkFilterQuality quality) const {
249 const bool opaque = this->isOpaque();
250 const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColor Type,
251 opaque ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
252 SkAutoTUnref<SkSurface> surface(this->newSurface(info, nullptr));
253 if (!surface.get()) {
254 return nullptr;
255 }
256
257 SkRect src;
258 if (subset) {
259 src.set(*subset);
260 } else {
261 src = SkRect::MakeIWH(this->width(), this->height());
262 }
263
264 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height() );
265 surface->getCanvas()->translate(-src.x(), -src.y());
266
267 SkPaint paint;
268 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
269 paint.setFilterQuality(quality);
270 surface->getCanvas()->drawImage(this, 0, 0, &paint);
271 return surface->newImageSnapshot();
272 }
273
274 //////////////////////////////////////////////////////////////////////////////// /////////////////// 265 //////////////////////////////////////////////////////////////////////////////// ///////////////////
275 266
276 bool SkImage::peekPixels(SkPixmap* pmap) const { 267 bool SkImage::peekPixels(SkPixmap* pmap) const {
277 SkImageInfo info; 268 SkImageInfo info;
278 size_t rowBytes; 269 size_t rowBytes;
279 const void* pixels = this->peekPixels(&info, &rowBytes); 270 const void* pixels = this->peekPixels(&info, &rowBytes);
280 if (pixels) { 271 if (pixels) {
281 if (pmap) { 272 if (pmap) {
282 pmap->reset(info, pixels, rowBytes); 273 pmap->reset(info, pixels, rowBytes);
283 } 274 }
(...skipping 20 matching lines...) Expand all
304 if (!bm.isImmutable()) { 295 if (!bm.isImmutable()) {
305 const bool notBudgeted = false; 296 const bool notBudgeted = false;
306 tex = GrDeepCopyTexture(tex, notBudgeted); 297 tex = GrDeepCopyTexture(tex, notBudgeted);
307 if (nullptr == tex) { 298 if (nullptr == tex) {
308 return nullptr; 299 return nullptr;
309 } 300 }
310 unrefCopy.reset(tex); 301 unrefCopy.reset(tex);
311 } 302 }
312 const SkImageInfo info = bm.info(); 303 const SkImageInfo info = bm.info();
313 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(), 304 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(),
314 tex, 0, SkSurface::kNo_Budgeted); 305 tex, SkSurface::kNo_Budgeted);
315 } 306 }
316 #endif 307 #endif
317 308
318 // This will check for immutable (share or copy) 309 // This will check for immutable (share or copy)
319 return SkNewImageFromRasterBitmap(bm, nullptr); 310 return SkNewImageFromRasterBitmap(bm, nullptr);
320 } 311 }
321 312
322 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { 313 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
323 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); 314 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
324 } 315 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 356
366 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 357 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
367 return nullptr; 358 return nullptr;
368 } 359 }
369 360
370 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 361 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
371 return nullptr; 362 return nullptr;
372 } 363 }
373 364
374 #endif 365 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleFilterQuality.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698