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

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
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
135 #ifdef SK_SUPPORT_LEGACY_NEWIMAGE
142 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset, 136 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
143 SkFilterQuality quality) const { 137 SkFilterQuality) const {
138 #if 0
144 if (newWidth <= 0 || newHeight <= 0) { 139 if (newWidth <= 0 || newHeight <= 0) {
145 return nullptr; 140 return nullptr;
146 } 141 }
147 142
148 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); 143 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
149 144
150 if (subset) { 145 if (subset) {
151 if (!bounds.contains(*subset)) { 146 if (!bounds.contains(*subset)) {
152 return nullptr; 147 return nullptr;
153 } 148 }
154 if (bounds == *subset) { 149 if (bounds == *subset) {
155 subset = nullptr; // and fall through to check below 150 subset = nullptr; // and fall through to check below
156 } 151 }
157 } 152 }
158 153
159 if (nullptr == subset && this->width() == newWidth && this->height() == newH eight) { 154 if (nullptr == subset && this->width() == newWidth && this->height() == newH eight) {
160 return SkRef(const_cast<SkImage*>(this)); 155 return SkRef(const_cast<SkImage*>(this));
161 } 156 }
162 157
163 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); 158 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
159 #else
160 SkASSERT(subset);
161 SkASSERT(subset->width() == newWidth);
162 SkASSERT(subset->height() == newHeight);
163 return this->newSubset(*subset);
164 #endif
165 }
166 #endif
167
168 SkImage* SkImage::newSubset(const SkIRect& subset) const {
169 if (subset.isEmpty()) {
170 return nullptr;
171 }
172
173 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
174 if (!bounds.contains(subset)) {
175 return nullptr;
176 }
177
178 // optimization : return self if the subset == our bounds
179 if (bounds == subset) {
180 return SkRef(const_cast<SkImage*>(this));
181 }
182 return as_IB(this)->onNewSubset(subset);
164 } 183 }
165 184
166 #if SK_SUPPORT_GPU 185 #if SK_SUPPORT_GPU
167 186
168 GrTexture* SkImage::getTexture() const { 187 GrTexture* SkImage::getTexture() const {
169 return as_IB(this)->peekTexture(); 188 return as_IB(this)->peekTexture();
170 } 189 }
171 190
172 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture( )); } 191 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture( )); }
173 192
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 bm.installPixels(dstInfo, dstPixels, dstRowBytes); 256 bm.installPixels(dstInfo, dstPixels, dstRowBytes);
238 SkCanvas canvas(bm); 257 SkCanvas canvas(bm);
239 258
240 SkPaint paint; 259 SkPaint paint;
241 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 260 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
242 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 261 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
243 262
244 return true; 263 return true;
245 } 264 }
246 265
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 //////////////////////////////////////////////////////////////////////////////// /////////////////// 266 //////////////////////////////////////////////////////////////////////////////// ///////////////////
275 267
276 bool SkImage::peekPixels(SkPixmap* pmap) const { 268 bool SkImage::peekPixels(SkPixmap* pmap) const {
277 SkImageInfo info; 269 SkImageInfo info;
278 size_t rowBytes; 270 size_t rowBytes;
279 const void* pixels = this->peekPixels(&info, &rowBytes); 271 const void* pixels = this->peekPixels(&info, &rowBytes);
280 if (pixels) { 272 if (pixels) {
281 if (pmap) { 273 if (pmap) {
282 pmap->reset(info, pixels, rowBytes); 274 pmap->reset(info, pixels, rowBytes);
283 } 275 }
(...skipping 20 matching lines...) Expand all
304 if (!bm.isImmutable()) { 296 if (!bm.isImmutable()) {
305 const bool notBudgeted = false; 297 const bool notBudgeted = false;
306 tex = GrDeepCopyTexture(tex, notBudgeted); 298 tex = GrDeepCopyTexture(tex, notBudgeted);
307 if (nullptr == tex) { 299 if (nullptr == tex) {
308 return nullptr; 300 return nullptr;
309 } 301 }
310 unrefCopy.reset(tex); 302 unrefCopy.reset(tex);
311 } 303 }
312 const SkImageInfo info = bm.info(); 304 const SkImageInfo info = bm.info();
313 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(), 305 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(),
314 tex, 0, SkSurface::kNo_Budgeted); 306 tex, SkSurface::kNo_Budgeted);
315 } 307 }
316 #endif 308 #endif
317 309
318 // This will check for immutable (share or copy) 310 // This will check for immutable (share or copy)
319 return SkNewImageFromRasterBitmap(bm, nullptr); 311 return SkNewImageFromRasterBitmap(bm, nullptr);
320 } 312 }
321 313
322 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { 314 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
323 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); 315 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
324 } 316 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 357
366 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 358 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
367 return nullptr; 359 return nullptr;
368 } 360 }
369 361
370 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 362 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
371 return nullptr; 363 return nullptr;
372 } 364 }
373 365
374 #endif 366 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698