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

Side by Side Diff: gm/image_pict.cpp

Issue 1288403002: add SkImage::NewFromPicture and a GM to test it (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 unified diff | Download patch
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkCanvas.h"
10 #include "SkImage.h"
11 #include "SkPictureRecorder.h"
12
13 #if SK_SUPPORT_GPU
14 #include "GrContext.h"
15 #endif
16
17 static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
18 SkPaint paint;
19 paint.setAntiAlias(true);
20 paint.setColor(SK_ColorRED);
21 paint.setStyle(SkPaint::kStroke_Style);
22 paint.setStrokeWidth(10);
23 canvas->drawRect(bounds, paint);
24 paint.setStyle(SkPaint::kFill_Style);
25 paint.setColor(SK_ColorBLUE);
26 canvas->drawOval(bounds, paint);
27 }
28
29 /*
30 * Exercise drawing pictures inside an image, showing that the image version is pixelated
31 * (correctly) when it is inside an image.
32 */
33 class ImagePictGM : public skiagm::GM {
34 SkAutoTUnref<SkPicture> fPicture;
35 SkAutoTUnref<SkImage> fImage0;
36 SkAutoTUnref<SkImage> fImage1;
37 public:
38 ImagePictGM() {}
39
40 protected:
41 SkString onShortName() override {
42 return SkString("image-picture");
43 }
44
45 SkISize onISize() override {
46 return SkISize::Make(850, 450);
47 }
48
49 void onOnceBeforeDraw() override {
50 const SkRect bounds = SkRect::MakeXYWH(100, 100, 100, 100);
51 SkPictureRecorder recorder;
52 draw_something(recorder.beginRecording(bounds), bounds);
53 fPicture.reset(recorder.endRecording());
54
55 // extract enough just for the oval.
56 const SkISize size = SkISize::Make(100, 100);
57
58 SkMatrix matrix;
59 matrix.setTranslate(-100, -100);
60 fImage0.reset(SkImage::NewFromPicture(fPicture, size, &matrix, nullptr)) ;
61 matrix.postTranslate(-50, -50);
62 matrix.postRotate(45);
63 matrix.postTranslate(50, 50);
64 fImage1.reset(SkImage::NewFromPicture(fPicture, size, &matrix, nullptr)) ;
65 }
66
67 void drawSet(SkCanvas* canvas) const {
68 SkMatrix matrix = SkMatrix::MakeTrans(-100, -100);
69 canvas->drawPicture(fPicture, &matrix, nullptr);
70 canvas->drawImage(fImage0, 150, 0);
71 canvas->drawImage(fImage1, 300, 0);
72 }
73
74 void onDraw(SkCanvas* canvas) override {
75 canvas->translate(20, 20);
76
77 this->drawSet(canvas);
78
79 canvas->save();
80 canvas->translate(0, 130);
81 canvas->scale(0.25f, 0.25f);
82 this->drawSet(canvas);
83 canvas->restore();
84
85 canvas->save();
86 canvas->translate(0, 200);
87 canvas->scale(2, 2);
88 this->drawSet(canvas);
89 canvas->restore();
90 }
91
92 private:
93 typedef skiagm::GM INHERITED;
94 };
95 DEF_GM( return new ImagePictGM; )
96
OLDNEW
« no previous file with comments | « no previous file | include/core/SkImage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698