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

Side by Side Diff: gm/bitmapsource.cpp

Issue 106933002: Implement srcRect and dstRect functionality in SkBitmapSource. This is required for the "preserveAs… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix SkTileImageFilter to respect CTM, and not to request an invalid subset Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gm/tileimagefilter.cpp » ('j') | gm/xfermodeimagefilter.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 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
10 #include "SkBitmapSource.h"
11
robertphillips 2013/12/09 16:23:01 // This GM ...?
Stephen White 2013/12/09 17:04:25 Done.
12 class BitmapSourceGM : public skiagm::GM {
13 public:
14 BitmapSourceGM() : fInitialized(false) {
15 }
16
17 protected:
robertphillips 2013/12/09 16:23:01 override
Stephen White 2013/12/09 17:04:25 Done.
18 virtual SkString onShortName() {
19 return SkString("bitmapsource");
20 }
21
robertphillips 2013/12/09 16:23:01 makeBitmap?
Stephen White 2013/12/09 17:04:25 Done.
22 void make_bitmap() {
23 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
24 fBitmap.allocPixels();
25 SkBitmapDevice device(fBitmap);
26 SkCanvas canvas(&device);
27 canvas.clear(0x00000000);
28 SkPaint paint;
29 paint.setAntiAlias(true);
30 paint.setColor(0xFFFFFFFF);
31 paint.setTextSize(SkIntToScalar(96));
32 const char* str = "e";
33 canvas.drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
34 }
35
robertphillips 2013/12/09 16:23:01 override
Stephen White 2013/12/09 17:04:25 Done.
36 virtual SkISize onISize() { return SkISize::Make(500, 150); }
37
robertphillips 2013/12/09 16:23:01 override
Stephen White 2013/12/09 17:04:25 Done.
38 virtual void onDraw(SkCanvas* canvas) {
robertphillips 2013/12/09 16:23:01 maybe just do this in onOnceBeforeDraw?
Stephen White 2013/12/09 17:04:25 Done.
39 if (!fInitialized) {
40 this->make_bitmap();
41 fInitialized = true;
42 }
43 canvas->clear(0x00000000);
44 {
45 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
46 SkRect dstRect = SkRect::MakeXYWH(0, 10, 60, 60);
47 SkRect clipRect = SkRect::MakeXYWH(0, 0, 100, 100);
48 SkRect bounds;
49 fBitmap.getBounds(&bounds);
50 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap) );
51 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(new SkBitmapSource(f Bitmap, srcRect, srcRect));
52 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(new SkBitmapS ource(fBitmap, srcRect, dstRect));
53 SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(new SkBitmapSour ce(fBitmap, bounds, dstRect));
54
robertphillips 2013/12/09 16:23:01 subroutine/loop?
Stephen White 2013/12/09 17:04:25 Done.
55 SkPaint paint;
56 paint.setImageFilter(bitmapSource);
57 canvas->save();
58 canvas->clipRect(clipRect);
59 canvas->drawPaint(paint);
60 canvas->restore();
61 canvas->translate(SkIntToScalar(100), 0);
62
63 paint.setImageFilter(bitmapSourceSrcRect);
64 canvas->save();
65 canvas->clipRect(clipRect);
66 canvas->drawPaint(paint);
67 canvas->restore();
68 canvas->translate(SkIntToScalar(100), 0);
69
70 paint.setImageFilter(bitmapSourceSrcRectDstRect);
71 canvas->save();
72 canvas->clipRect(clipRect);
73 canvas->drawPaint(paint);
74 canvas->restore();
75 canvas->translate(SkIntToScalar(100), 0);
76
77 paint.setImageFilter(bitmapSourceDstRectOnly);
78 canvas->save();
79 canvas->clipRect(clipRect);
80 canvas->drawPaint(paint);
81 canvas->restore();
82 canvas->translate(SkIntToScalar(100), 0);
83 }
84 }
85
86 private:
robertphillips 2013/12/09 16:23:01 micro-nit: this is supposed to go last
Stephen White 2013/12/09 17:04:25 Done.
87 typedef GM INHERITED;
88 SkBitmap fBitmap;
89 bool fInitialized;
90 };
91
92 ///////////////////////////////////////////////////////////////////////////////
93
robertphillips 2013/12/09 16:23:01 DEF_GM
Stephen White 2013/12/09 17:04:25 Done.
94 static skiagm::GM* MyFactory(void*) { return new BitmapSourceGM; }
95 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | gm/tileimagefilter.cpp » ('j') | gm/xfermodeimagefilter.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698