blob: 42f043e058dbb9b736cae78dbd1788b743e92cbf [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) {
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000017 bitmap->setConfig(SkBitmap::kARGB_8888_Config, 64, 64);
18 bitmap->allocPixels();
reed@google.com71121732012-09-18 15:14:33 +000019
mike@reedtribe.org3bd21732012-09-26 02:45:10 +000020 SkCanvas canvas(*bitmap);
reed@google.com71121732012-09-18 15:14:33 +000021
22 canvas.drawColor(SK_ColorRED);
23 SkPaint paint;
24 paint.setAntiAlias(true);
25 const SkPoint pts[] = { { 0, 0 }, { 64, 64 } };
26 const SkColor colors[] = { SK_ColorWHITE, SK_ColorBLUE };
27 paint.setShader(SkGradientShader::CreateLinear(pts, colors, NULL, 2,
28 SkShader::kClamp_TileMode))->unref();
29 canvas.drawCircle(32, 32, 32, paint);
30}
31
32class DrawBitmapRect2 : public skiagm::GM {
33 bool fUseIRect;
34public:
35 DrawBitmapRect2(bool useIRect) : fUseIRect(useIRect) {
36 }
37
38protected:
39 virtual SkString onShortName() SK_OVERRIDE {
40 SkString str;
41 str.printf("bitmaprect_%s", fUseIRect ? "i" : "s");
42 return str;
43 }
44
45 virtual SkISize onISize() SK_OVERRIDE {
46 return SkISize::Make(640, 480);
47 }
48
49 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
50 canvas->drawColor(0xFFCCCCCC);
51
52 const SkIRect src[] = {
53 { 0, 0, 32, 32 },
54 { 0, 0, 80, 80 },
55 { 32, 32, 96, 96 },
56 { -32, -32, 32, 32, }
57 };
58
59 SkPaint paint;
60 paint.setStyle(SkPaint::kStroke_Style);
61// paint.setColor(SK_ColorGREEN);
62
63 SkBitmap bitmap;
64 make_bitmap(&bitmap);
65
66 SkRect dstR = { 0, 200, 128, 380 };
67
68 canvas->translate(16, 40);
69 for (size_t i = 0; i < SK_ARRAY_COUNT(src); i++) {
70 SkRect srcR;
71 srcR.set(src[i]);
72
73 canvas->drawBitmap(bitmap, 0, 0, &paint);
74 if (fUseIRect) {
75 canvas->drawBitmapRectToRect(bitmap, &srcR, dstR, &paint);
76 } else {
77 canvas->drawBitmapRect(bitmap, &src[i], dstR, &paint);
78 }
79
80 canvas->drawRect(dstR, paint);
81 canvas->drawRect(srcR, paint);
82
83 canvas->translate(160, 0);
84 }
85 }
86
87private:
88 typedef skiagm::GM INHERITED;
89};
90
91//////////////////////////////////////////////////////////////////////////////
92
93static skiagm::GM* MyFactory0(void*) { return new DrawBitmapRect2(false); }
94static skiagm::GM* MyFactory1(void*) { return new DrawBitmapRect2(true); }
95
96static skiagm::GMRegistry reg0(MyFactory0);
97static skiagm::GMRegistry reg1(MyFactory1);