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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleFilterQuality.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 6f4655758e36cb7b50a565f514655cb51921db75..032be1949359a77f19d1dae332e441397db9684a 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -126,21 +126,15 @@ SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
}
-SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* props) const {
- if (nullptr == props) {
- props = &as_IB(this)->props();
- }
- return as_IB(this)->onNewSurface(info, *props);
-}
-
const char* SkImage::toString(SkString* str) const {
str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
this->isOpaque() ? "opaque" : "");
return str->c_str();
}
-SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
- SkFilterQuality quality) const {
+#ifdef SK_SUPPORT_LEGACY_NEWIMAGE
+SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset) const {
+#if 0
if (newWidth <= 0 || newHeight <= 0) {
return nullptr;
}
@@ -161,6 +155,30 @@ SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
}
return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
+#else
+ SkASSERT(subset);
+ SkASSERT(subset->width() == newWidth);
+ SkASSERT(subset->height() == newHeight);
+ return this->newSubset(*subset);
+#endif
+}
+#endif
+
+SkImage* SkImage::newSubset(const SkIRect& subset) const {
+ if (subset.isEmpty()) {
+ return nullptr;
+ }
+
+ const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
+ if (!bounds.contains(subset)) {
+ return nullptr;
+ }
+
+ // optimization : return self if the subset == our bounds
+ if (bounds == subset) {
+ return SkRef(const_cast<SkImage*>(this));
+ }
+ return as_IB(this)->onNewSubset(subset);
}
#if SK_SUPPORT_GPU
@@ -244,33 +262,6 @@ bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz
return true;
}
-SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* subset,
- SkFilterQuality quality) const {
- const bool opaque = this->isOpaque();
- const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColorType,
- opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
- SkAutoTUnref<SkSurface> surface(this->newSurface(info, nullptr));
- if (!surface.get()) {
- return nullptr;
- }
-
- SkRect src;
- if (subset) {
- src.set(*subset);
- } else {
- src = SkRect::MakeIWH(this->width(), this->height());
- }
-
- surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height());
- surface->getCanvas()->translate(-src.x(), -src.y());
-
- SkPaint paint;
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- paint.setFilterQuality(quality);
- surface->getCanvas()->drawImage(this, 0, 0, &paint);
- return surface->newImageSnapshot();
-}
-
///////////////////////////////////////////////////////////////////////////////////////////////////
bool SkImage::peekPixels(SkPixmap* pmap) const {
@@ -311,7 +302,7 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
}
const SkImageInfo info = bm.info();
return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
- tex, 0, SkSurface::kNo_Budgeted);
+ tex, SkSurface::kNo_Budgeted);
}
#endif
« 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