blob: 0e6c074e83d177cbe3a77b16687159e501748458 [file] [log] [blame]
reed@google.com71121732012-09-18 15:14:33 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#include "gm.h"
9#include "SkCanvas.h"
10#include "SkGradientShader.h"
11#include "SkGraphics.h"
12#include "SkPath.h"
13#include "SkRegion.h"
14#include "SkShader.h"
15
16static void make_bitmap(SkBitmap* bitmap) {
17 SkCanvas canvas;
18
19 {
20 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 64, 64);
21 bitmap->allocPixels();
22 canvas.setBitmapDevice(*bitmap);
23 }
24
25 canvas.drawColor(SK_ColorRED);
26 SkPaint paint;
27 paint.setAntiAlias(true);
28 const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
29 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
30 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2,
31 SkShader::kClamp_TileMode))->unref();
32 canvas.drawCircle(32, 32, 32, paint);
33}
34
35class DrawBitmapRect2 : public skiagm::GM {
36 bool fUseIRect;
37public:
38 DrawBitmapRect2(bool useIRect) : fUseIRect(useIRect) {
39 }
40
41protected:
42 virtual SkString onShortName() SK_OVERRIDE {
43 SkString str;
44 str.printf("bitmaprect_%s", fUseIRect ? "i" : "s");
45 return str;
46 }
47
48 virtual SkISize onISize() SK_OVERRIDE {
49 return SkISize::Make(640, 480);
50 }
51
52 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
53 canvas->drawColor(0xFFCCCCCC);
54
55 const SkIRect src[] = {
56 { 0, 0, 32, 32 },
57 { 0, 0, 80, 80 },
58 { 32, 32, 96, 96 },
59 { -32, -32, 32, 32, }
60 };
61
62 SkPaint paint;
63 paint.setStyle(SkPaint::kStroke_Style);
64// paint.setColor(SK_ColorGREEN);
65
66 SkBitmap bitmap;
67 make_bitmap(&bitmap);
68
69 SkRect dstR = { 0, 200, 128, 380 };
70
71 canvas->translate(16, 40);
72 for (size_t i = 0; i < SK_ARRAY_COUNT(src); i++) {
73 SkRect srcR;
74 srcR.set(src[i]);
75
76 canvas->drawBitmap(bitmap, 0, 0, &paint);
77 if (fUseIRect) {
78 canvas->drawBitmapRectToRect(bitmap, &srcR, dstR, &paint);
79 } else {
80 canvas->drawBitmapRect(bitmap, &src[i], dstR, &paint);
81 }
82
83 canvas->drawRect(dstR, paint);
84 canvas->drawRect(srcR, paint);
85
86 canvas->translate(160, 0);
87 }
88 }
89
90private:
91 typedef skiagm::GM INHERITED;
92};
93
94//////////////////////////////////////////////////////////////////////////////
95
96static skiagm::GM* MyFactory0(void*) { return new DrawBitmapRect2(false); }
97static skiagm::GM* MyFactory1(void*) { return new DrawBitmapRect2(true); }
98
99static skiagm::GMRegistry reg0(MyFactory0);
100static skiagm::GMRegistry reg1(MyFactory1);