Index: src/core/SkPictureImageGenerator.cpp |
diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp |
index f92de3b98660c04054797a39deb6f3f49c4d19e9..acff84c1b4e3e1422edae471e62ef99d0fac27ba 100644 |
--- a/src/core/SkPictureImageGenerator.cpp |
+++ b/src/core/SkPictureImageGenerator.cpp |
@@ -22,7 +22,7 @@ protected: |
bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], |
int* ctableCount) override; |
#if SK_SUPPORT_GPU |
- GrTexture* onGenerateTexture(GrContext*, SkImageUsageType) override; |
+ GrTexture* onGenerateTexture(GrContext*, SkImageUsageType, const SkIRect*) override; |
#endif |
private: |
@@ -88,18 +88,27 @@ SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk |
#if SK_SUPPORT_GPU |
#include "GrTexture.h" |
-GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsageType usage) { |
+GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsageType usage, |
+ const SkIRect* subset) { |
+ const SkImageInfo& info = this->getInfo(); |
+ SkImageInfo surfaceInfo = subset ? info.makeWH(subset->width(), subset->height()) : info; |
+ |
// |
// TODO: respect the usage, by possibly creating a different (pow2) surface |
// |
SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, |
SkSurface::kYes_Budgeted, |
- this->getInfo())); |
+ surfaceInfo)); |
if (!surface.get()) { |
return nullptr; |
} |
+ |
+ SkMatrix matrix = fMatrix; |
+ if (subset) { |
+ matrix.postTranslate(-subset->x(), -subset->y()); |
+ } |
surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this for us? |
- surface->getCanvas()->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()); |
+ surface->getCanvas()->drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); |
SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
if (!image.get()) { |
return nullptr; |