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

Unified Diff: gm/image_pict.cpp

Issue 1291803002: Extend SkImageGenerator to support natively generated GrTextures (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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 | « no previous file | gyp/core.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/image_pict.cpp
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index ce2d2ecb0c680648ddc3a64872b9c69fe88fb11c..dd1fab549a830e54d9f1d4b9fd3ec1b3b70826d2 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -8,10 +8,14 @@
#include "gm.h"
#include "SkCanvas.h"
#include "SkImage.h"
+#include "SkImageCacherator.h"
#include "SkPictureRecorder.h"
+#include "SkSurface.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrTexture.h"
+#include "../src/image/SkImage_Gpu.h"
#endif
static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
@@ -94,3 +98,89 @@ private:
};
DEF_GM( return new ImagePictGM; )
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+class ImageCacheratorGM : public skiagm::GM {
+ SkAutoTUnref<SkPicture> fPicture;
+ SkAutoTDelete<SkImageCacherator> fCache;
+
+public:
+ ImageCacheratorGM() {}
+
+protected:
+ SkString onShortName() override {
+ return SkString("image-cacherator");
+ }
+
+ SkISize onISize() override {
+ return SkISize::Make(850, 450);
+ }
+
+ void onOnceBeforeDraw() override {
+ const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
+ SkPictureRecorder recorder;
+ draw_something(recorder.beginRecording(bounds), bounds);
+ fPicture.reset(recorder.endRecording());
+
+ // extract enough just for the oval.
+ const SkISize size = SkISize::Make(100, 100);
+
+ SkMatrix matrix;
+ matrix.setTranslate(-100, -100);
+ fCache.reset(new SkImageCacherator(SkImageGenerator::NewFromPicture(size,
+ fPicture,
+ &matrix,
+ nullptr)));
+ }
+
+ void drawSet(SkCanvas* canvas) const {
+ SkMatrix matrix = SkMatrix::MakeTrans(-100, -100);
+ canvas->drawPicture(fPicture, &matrix, nullptr);
+
+ {
+ SkBitmap bitmap;
+ fCache->lockAsBitmap(&bitmap);
+ canvas->drawBitmap(bitmap, 150, 0);
+ }
+#if SK_SUPPORT_GPU
+ {
+ SkAutoTUnref<GrTexture> texture(fCache->lockAsTexture(canvas->getGrContext(),
+ kUntiled_SkImageUsageType));
+ if (!texture) {
+ return;
+ }
+ // No API to draw a GrTexture directly, so we cheat and create a private image subclass
+ SkAutoTUnref<SkImage> image(new SkImage_Gpu(100, 100, fCache->generator()->uniqueID(),
+ kPremul_SkAlphaType, texture, 0,
+ SkSurface::kNo_Budgeted));
+ canvas->drawImage(image, 300, 0);
+ }
+#endif
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ canvas->translate(20, 20);
+
+ this->drawSet(canvas);
+
+ canvas->save();
+ canvas->translate(0, 130);
+ canvas->scale(0.25f, 0.25f);
+ this->drawSet(canvas);
+ canvas->restore();
+
+ canvas->save();
+ canvas->translate(0, 200);
+ canvas->scale(2, 2);
+ this->drawSet(canvas);
+ canvas->restore();
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new ImageCacheratorGM; )
+
+
+
« no previous file with comments | « no previous file | gyp/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698