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

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: 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 | gyp/gmslides.gypi » ('j') | include/effects/SkBitmapSource.h » ('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
12 class BitmapSourceGM : public skiagm::GM {
13 public:
14 BitmapSourceGM() : fInitialized(false) {
15 }
16
17 protected:
18 virtual SkString onShortName() {
19 return SkString("bitmapsource");
20 }
21
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
36 virtual SkISize onISize() { return SkISize::Make(500, 150); }
37
38 virtual void onDraw(SkCanvas* canvas) {
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 SkAutoTUnref<SkImageFilter> bitmapSource(new SkBitmapSource(fBitmap) );
49 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRect(new SkBitmapSource(f Bitmap, &srcRect));
50 SkAutoTUnref<SkImageFilter> bitmapSourceSrcRectDstRect(new SkBitmapS ource(fBitmap, &srcRect, &dstRect));
51 SkAutoTUnref<SkImageFilter> bitmapSourceDstRectOnly(new SkBitmapSour ce(fBitmap, NULL, &dstRect));
52
53 SkPaint paint;
54 paint.setImageFilter(bitmapSource);
55 canvas->save();
56 canvas->clipRect(clipRect);
57 canvas->drawPaint(paint);
58 canvas->restore();
59 canvas->translate(SkIntToScalar(100), 0);
60
61 paint.setImageFilter(bitmapSourceSrcRect);
62 canvas->save();
63 canvas->clipRect(clipRect);
64 canvas->drawPaint(paint);
65 canvas->restore();
66 canvas->translate(SkIntToScalar(100), 0);
67
68 paint.setImageFilter(bitmapSourceSrcRectDstRect);
69 canvas->save();
70 canvas->clipRect(clipRect);
71 canvas->drawPaint(paint);
72 canvas->restore();
73 canvas->translate(SkIntToScalar(100), 0);
74
75 paint.setImageFilter(bitmapSourceDstRectOnly);
76 canvas->save();
77 canvas->clipRect(clipRect);
78 canvas->drawPaint(paint);
79 canvas->restore();
80 canvas->translate(SkIntToScalar(100), 0);
81 }
82 }
83
84 private:
85 typedef GM INHERITED;
86 SkBitmap fBitmap;
87 bool fInitialized;
88 };
89
90 ///////////////////////////////////////////////////////////////////////////////
91
92 static skiagm::GM* MyFactory(void*) { return new BitmapSourceGM; }
93 static skiagm::GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | include/effects/SkBitmapSource.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698