aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/image_pict.cpp11
-rw-r--r--include/core/SkImageGenerator.h16
-rw-r--r--src/core/SkImageCacherator.cpp17
-rw-r--r--src/core/SkImageGenerator.cpp8
-rw-r--r--src/core/SkPictureImageGenerator.cpp16
5 files changed, 40 insertions, 28 deletions
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 3a84905a9b..7f9454923f 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -221,7 +221,8 @@ public:
}
}
protected:
- GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect& subset) override {
+ GrTexture* onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
+ const SkIPoint& origin) override {
if (ctx) {
SkASSERT(ctx == fCtx.get());
}
@@ -232,11 +233,13 @@ protected:
// need to copy the subset into a new texture
GrSurfaceDesc desc = fTexture->desc();
- desc.fWidth = subset.width();
- desc.fHeight = subset.height();
+ desc.fWidth = info.width();
+ desc.fHeight = info.height();
GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted::kNo);
- fCtx->copySurface(dst, fTexture.get(), subset, SkIPoint::Make(0, 0));
+ fCtx->copySurface(dst, fTexture.get(),
+ SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height()),
+ SkIPoint::Make(0, 0));
return dst;
}
private:
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 5742c1e3f5..a88e1d466e 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -117,6 +117,18 @@ public:
* If the generator can natively/efficiently return its pixels as a GPU image (backed by a
* texture) this will return that image. If not, this will return NULL.
*
+ * This routine also supports retrieving only a subset of the pixels. That subset is specified
+ * by the following rectangle:
+ *
+ * subset = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height())
+ *
+ * If subset is not contained inside the generator's bounds, this returns false.
+ *
+ * whole = SkIRect::MakeWH(getInfo().width(), getInfo().height())
+ * if (!whole.contains(subset)) {
+ * return false;
+ * }
+ *
* Regarding the GrContext parameter:
*
* The caller may pass NULL for the context. In that case the generator may assume that its
@@ -128,7 +140,7 @@ public:
* - its internal context is the same
* - it can somehow convert its texture into one that is valid for the provided context.
*/
- GrTexture* generateTexture(GrContext*, const SkIRect& subset);
+ GrTexture* generateTexture(GrContext*, const SkImageInfo& info, const SkIPoint& origin);
struct SupportedSizes {
SkISize fSizes[2];
@@ -259,7 +271,7 @@ protected:
return false;
}
- virtual GrTexture* onGenerateTexture(GrContext*, const SkIRect&) {
+ virtual GrTexture* onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&) {
return nullptr;
}
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index f18eea36f6..21b112fcd6 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -233,9 +233,7 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client,
{
ScopedGenerator generator(fSharedGenerator);
- SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(),
- cacheInfo.width(), cacheInfo.height());
- tex.reset(generator->generateTexture(nullptr, subset));
+ tex.reset(generator->generateTexture(nullptr, cacheInfo, fOrigin));
}
if (!tex) {
bitmap->reset();
@@ -541,22 +539,21 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori
}
}
+ // The CachedFormat is both an index for which cache "slot" we'll use to store this particular
+ // decoded variant of the encoded data, and also a recipe for how to transform the original
+ // info to get the one that we're going to decode to.
+ SkImageInfo cacheInfo = this->buildCacheInfo(format);
+
// 2. Ask the generator to natively create one
{
ScopedGenerator generator(fSharedGenerator);
- SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
- if (GrTexture* tex = generator->generateTexture(ctx, subset)) {
+ if (GrTexture* tex = generator->generateTexture(ctx, cacheInfo, fOrigin)) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
return set_key_and_return(tex, key);
}
}
- // The CachedFormat is both an index for which cache "slot" we'll use to store this particular
- // decoded variant of the encoded data, and also a recipe for how to transform the original
- // info to get the one that we're going to decode to.
- SkImageInfo cacheInfo = this->buildCacheInfo(format);
-
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(cacheInfo, *ctx->caps());
#ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 410f6811bb..5344855dad 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -77,11 +77,13 @@ bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes
return this->onGetYUV8Planes(sizeInfo, planes);
}
-GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkIRect& subset) {
- if (!SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(subset)) {
+GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const SkImageInfo& info,
+ const SkIPoint& origin) {
+ SkIRect srcRect = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height());
+ if (!SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(srcRect)) {
return nullptr;
}
- return this->onGenerateTexture(ctx, subset);
+ return this->onGenerateTexture(ctx, info, origin);
}
bool SkImageGenerator::computeScaledDimensions(SkScalar scale, SupportedSizes* sizes) {
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp
index bf6d53feec..d4cf92eb94 100644
--- a/src/core/SkPictureImageGenerator.cpp
+++ b/src/core/SkPictureImageGenerator.cpp
@@ -26,7 +26,7 @@ protected:
bool onGenerateScaledPixels(const SkISize&, const SkIPoint&, const SkPixmap&) override;
#if SK_SUPPORT_GPU
- GrTexture* onGenerateTexture(GrContext*, const SkIRect&) override;
+ GrTexture* onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&) override;
#endif
private:
@@ -50,7 +50,7 @@ SkImageGenerator* SkPictureImageGenerator::Create(const SkISize& size, const SkP
SkPictureImageGenerator::SkPictureImageGenerator(const SkISize& size, const SkPicture* picture,
const SkMatrix* matrix, const SkPaint* paint)
- : INHERITED(SkImageInfo::MakeN32Premul(size))
+ : INHERITED(SkImageInfo::MakeS32(size.width(), size.height(), kPremul_SkAlphaType))
, fPicture(SkRef(picture)) {
if (matrix) {
@@ -66,7 +66,7 @@ SkPictureImageGenerator::SkPictureImageGenerator(const SkISize& size, const SkPi
bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
SkPMColor ctable[], int* ctableCount) {
- if (info != getInfo() || ctable || ctableCount) {
+ if (ctable || ctableCount) {
return false;
}
@@ -132,20 +132,18 @@ SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk
#if SK_SUPPORT_GPU
#include "GrTexture.h"
-GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, const SkIRect& subset) {
- const SkImageInfo& info = this->getInfo();
- SkImageInfo surfaceInfo = info.makeWH(subset.width(), subset.height());
-
+GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
+ const SkIPoint& origin) {
//
// TODO: respect the usage, by possibly creating a different (pow2) surface
//
- sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, surfaceInfo));
+ sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, info));
if (!surface) {
return nullptr;
}
SkMatrix matrix = fMatrix;
- matrix.postTranslate(-subset.x(), -subset.y());
+ matrix.postTranslate(-origin.x(), -origin.y());
surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this for us?
surface->getCanvas()->drawPicture(fPicture.get(), &matrix, fPaint.getMaybeNull());
sk_sp<SkImage> image(surface->makeImageSnapshot());