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

Side by Side Diff: gm/imagesource.cpp

Issue 1343703005: SkImageSource (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments Created 5 years, 3 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 | gyp/effects.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkBitmapSource.h" 10 #include "SkImage.h"
11 #include "SkImageSource.h"
11 12
12 // This GM exercises the SkBitmapSource ImageFilter class. 13 // This GM exercises the SkImageSource ImageFilter class.
13 14
14 class BitmapSourceGM : public skiagm::GM { 15 class ImageSourceGM : public skiagm::GM {
15 public: 16 public:
16 BitmapSourceGM() { 17 ImageSourceGM() { }
17 }
18 18
19 protected: 19 protected:
20 SkString onShortName() override { 20 SkString onShortName() override {
21 return SkString("bitmapsource"); 21 return SkString("imagesource");
22 } 22 }
23 23
24 SkISize onISize() override { return SkISize::Make(500, 150); } 24 SkISize onISize() override { return SkISize::Make(500, 150); }
25 25
26 void onOnceBeforeDraw() override { 26 void onOnceBeforeDraw() override {
27 fBitmap = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e"); 27 SkBitmap bm = sk_tool_utils::create_string_bitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e");
28 fImage.reset(SkImage::NewFromBitmap(bm));
28 } 29 }
29 30
30 static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma geFilter* filter) { 31 static void FillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma geFilter* filter) {
31 SkPaint paint; 32 SkPaint paint;
32 paint.setImageFilter(filter); 33 paint.setImageFilter(filter);
33 canvas->save(); 34 canvas->save();
34 canvas->clipRect(clipRect); 35 canvas->clipRect(clipRect);
35 canvas->drawPaint(paint); 36 canvas->drawPaint(paint);
36 canvas->restore(); 37 canvas->restore();
37 } 38 }
38 39
39 void onDraw(SkCanvas* canvas) override { 40 void onDraw(SkCanvas* canvas) override {
40 canvas->clear(SK_ColorBLACK); 41 canvas->clear(SK_ColorBLACK);
41 { 42 {
42 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); 43 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
43 SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60); 44 SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
44 SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100); 45 SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
45 SkRect bounds; 46 SkRect bounds = SkRect::MakeIWH(fImage->width(), fImage->height());
46 fBitmap.getBounds(&bounds); 47 SkAutoTUnref<SkImageFilter> imageSource(SkImageSource::Create(fImage ));
47 SkAutoTUnref<SkImageFilter> bitmapSource(SkBitmapSource::Create(fBit map)); 48 SkAutoTUnref<SkImageFilter> imageSourceSrcRect(
48 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(SkBitmapSource::Crea te(fBitmap, srcRect, srcRect)); 49 SkImageSource::Create(fImage, srcRect, srcRect, kHigh_SkFilterQu ality));
49 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(SkBitmapSourc e::Create(fBitmap, srcRect, dstRect)); 50 SkAutoTUnref<SkImageFilter> imageSourceSrcRectDstRect(
50 SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(SkBitmapSource:: Create(fBitmap, bounds, dstRect)); 51 SkImageSource::Create(fImage, srcRect, dstRect, kHigh_SkFilterQu ality));
52 SkAutoTUnref<SkImageFilter> imageSourceDstRectOnly(
53 SkImageSource::Create(fImage, bounds, dstRect, kHigh_SkFilterQua lity));
51 54
52 // Draw an unscaled bitmap. 55 // Draw an unscaled bitmap.
53 FillRectFiltered(canvas, clipRect, bitmapSource); 56 FillRectFiltered(canvas, clipRect, imageSource);
54 canvas->translate(SkIntToScalar(100), 0); 57 canvas->translate(SkIntToScalar(100), 0);
55 58
56 // Draw an unscaled subset of the source bitmap (srcRect -> srcRect) . 59 // Draw an unscaled subset of the source bitmap (srcRect -> srcRect) .
57 FillRectFiltered(canvas, clipRect, bitmapSourceSrcRect); 60 FillRectFiltered(canvas, clipRect, imageSourceSrcRect);
58 canvas->translate(SkIntToScalar(100), 0); 61 canvas->translate(SkIntToScalar(100), 0);
59 62
60 // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect). 63 // Draw a subset of the bitmap scaled to a destination rect (srcRect -> dstRect).
61 FillRectFiltered(canvas, clipRect, bitmapSourceSrcRectDstRect); 64 FillRectFiltered(canvas, clipRect, imageSourceSrcRectDstRect);
62 canvas->translate(SkIntToScalar(100), 0); 65 canvas->translate(SkIntToScalar(100), 0);
63 66
64 // Draw the entire bitmap scaled to a destination rect (bounds -> ds tRect). 67 // Draw the entire bitmap scaled to a destination rect (bounds -> ds tRect).
65 FillRectFiltered(canvas, clipRect, bitmapSourceDstRectOnly); 68 FillRectFiltered(canvas, clipRect, imageSourceDstRectOnly);
66 canvas->translate(SkIntToScalar(100), 0); 69 canvas->translate(SkIntToScalar(100), 0);
67 } 70 }
68 } 71 }
69 72
70 private: 73 private:
71 SkBitmap fBitmap; 74 SkAutoTUnref<SkImage> fImage;
72 typedef GM INHERITED; 75 typedef GM INHERITED;
73 }; 76 };
74 77
75 /////////////////////////////////////////////////////////////////////////////// 78 ///////////////////////////////////////////////////////////////////////////////
76 79
77 DEF_GM( return new BitmapSourceGM; ) 80 DEF_GM( return new ImageSourceGM; )
OLDNEW
« no previous file with comments | « no previous file | gyp/effects.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698