remove unused (by the outside) SkImage::newSurface, and simplify newImage -> newSubset
BUG=skia:
Review URL: https://codereview.chromium.org/1364443002
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 163e62e..1a63a0d 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -15,10 +15,9 @@
#include "SkPixelRef.h"
SkImage_Gpu::SkImage_Gpu(int w, int h, uint32_t uniqueID, SkAlphaType at, GrTexture* tex,
- int sampleCountForNewSurfaces, SkSurface::Budgeted budgeted)
+ SkSurface::Budgeted budgeted)
: INHERITED(w, h, uniqueID, nullptr)
, fTexture(SkRef(tex))
- , fSampleCountForNewSurfaces(sampleCountForNewSurfaces)
, fAlphaType(at)
, fBudgeted(budgeted)
, fAddedRasterVersionToCache(false)
@@ -30,19 +29,6 @@
}
}
-SkSurface* SkImage_Gpu::onNewSurface(const SkImageInfo& info, const SkSurfaceProps& props) const {
- GrTexture* tex = this->getTexture();
- SkASSERT(tex);
- GrContext* ctx = tex->getContext();
- if (!ctx) {
- // the texture may have been abandoned, so we have to check
- return nullptr;
- }
- // TODO: Change signature of onNewSurface to take a budgeted param.
- const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted;
- return SkSurface::NewRenderTarget(ctx, budgeted, info, fSampleCountForNewSurfaces, &props);
-}
-
extern void SkTextureImageApplyBudgetedDecision(SkImage* image) {
if (as_IB(image)->getTexture()) {
((SkImage_Gpu*)image)->applyBudgetDecision();
@@ -136,6 +122,22 @@
return true;
}
+SkImage* SkImage_Gpu::onNewSubset(const SkIRect& subset) const {
+ GrContext* ctx = fTexture->getContext();
+ GrSurfaceDesc desc = fTexture->desc();
+ desc.fWidth = subset.width();
+ desc.fHeight = subset.height();
+
+ GrTexture* subTx = ctx->textureProvider()->createTexture(desc,
+ SkSurface::kYes_Budgeted == fBudgeted);
+ if (!subTx) {
+ return nullptr;
+ }
+ ctx->copySurface(subTx, fTexture, subset, SkIPoint::Make(0, 0));
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, fAlphaType, subTx,
+ fBudgeted);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc,
@@ -154,7 +156,7 @@
}
const SkSurface::Budgeted budgeted = SkSurface::kNo_Budgeted;
- return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, 0, budgeted);
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, tex, budgeted);
}
SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at,
@@ -186,8 +188,7 @@
}
const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
- const int sampleCount = 0; // todo: make this an explicit parameter to newSurface()?
- return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst, sampleCount,
+ return new SkImage_Gpu(desc.fWidth, desc.fHeight, kNeedNewImageUniqueID, at, dst,
budgeted);
}
@@ -267,7 +268,7 @@
drawContext->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(), rect);
ctx->flushSurfaceWrites(dst);
return new SkImage_Gpu(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImageUniqueID,
- kOpaque_SkAlphaType, dst, 0, budgeted);
+ kOpaque_SkAlphaType, dst, budgeted);
}
///////////////////////////////////////////////////////////////////////////////////////////////////