2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkGradientShader.h"
13 static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) {
14 bm->allocN32Pixels(width, height);
16 SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2};
18 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2,
19 SkShader::kMirror_TileMode);
21 paint.setShader(shader)->unref();
22 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
23 canvas.drawPaint(paint);
27 static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
29 make_bm(&bm, width, height, colors);
35 paint.setStyle(SkPaint::kStroke_Style);
37 ir.set(0, 0, 128, 128);
42 canvas->drawBitmap(bm, 0, 0, NULL);
44 canvas->drawRect(r, paint);
46 r.offset(SkIntToScalar(150), 0);
47 // exercises extract bitmap, but not shader
48 canvas->drawBitmapRect(bm, &ir, r, NULL);
49 canvas->drawRect(r, paint);
51 r.offset(SkIntToScalar(150), 0);
52 // exercises bitmapshader
53 canvas->drawBitmapRect(bm, NULL, r, NULL);
54 canvas->drawRect(r, paint);
57 class VeryLargeBitmapGM : public skiagm::GM {
59 VeryLargeBitmapGM() {}
62 SkString onShortName() SK_OVERRIDE {
63 return SkString("verylargebitmap");
66 SkISize onISize() SK_OVERRIDE {
67 return SkISize::Make(500, 600);
70 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
71 int veryBig = 65*1024; // 64K < size
72 int big = 33*1024; // 32K < size < 64K
73 // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
79 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
80 colors[0] = SK_ColorRED;
81 colors[1] = SK_ColorGREEN;
82 show_bm(canvas, small, small, colors);
83 canvas->translate(0, SkIntToScalar(150));
85 colors[0] = SK_ColorBLUE;
86 colors[1] = SK_ColorMAGENTA;
87 show_bm(canvas, big, small, colors);
88 canvas->translate(0, SkIntToScalar(150));
90 colors[0] = SK_ColorMAGENTA;
91 colors[1] = SK_ColorYELLOW;
92 show_bm(canvas, medium, medium, colors);
93 canvas->translate(0, SkIntToScalar(150));
95 colors[0] = SK_ColorGREEN;
96 colors[1] = SK_ColorYELLOW;
97 // as of this writing, the raster code will fail to draw the scaled version
98 // since it has a 64K limit on x,y coordinates... (but gpu should succeed)
99 show_bm(canvas, veryBig, small, colors);
103 typedef skiagm::GM INHERITED;
106 //////////////////////////////////////////////////////////////////////////////
108 static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
109 static skiagm::GMRegistry reg(MyFactory);