blob: e6d81cdaa791397ee4173c22e77ccfd1dbd93c81 [file] [log] [blame]
reed@google.com7eb3a262012-08-07 14:05:14 +00001/*
2 * Copyright 2012 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#include "SkCanvas.h"
bsalomon@google.comaf562b42013-10-24 17:52:07 +000010#include "SkGradientShader.h"
reed@google.com7eb3a262012-08-07 14:05:14 +000011#include "SkPath.h"
12
bsalomon@google.comaf562b42013-10-24 17:52:07 +000013static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) {
reed@google.com7eb3a262012-08-07 14:05:14 +000014 bm->setConfig(SkBitmap::kARGB_8888_Config, width, height);
15 bm->allocPixels();
bsalomon@google.comaf562b42013-10-24 17:52:07 +000016 SkCanvas canvas(*bm);
17 SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2};
18 SkScalar radius = 40;
19 SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2,
20 SkShader::kMirror_TileMode);
21 SkPaint paint;
22 paint.setShader(shader)->unref();
23 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
24 canvas.drawPaint(paint);
reed@google.com7eb3a262012-08-07 14:05:14 +000025 bm->setImmutable();
26}
27
bsalomon@google.comaf562b42013-10-24 17:52:07 +000028static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
reed@google.com7eb3a262012-08-07 14:05:14 +000029 SkBitmap bm;
bsalomon@google.comaf562b42013-10-24 17:52:07 +000030 make_bm(&bm, width, height, colors);
reed@google.com7eb3a262012-08-07 14:05:14 +000031
32 SkPaint paint;
33 SkRect r;
34 SkIRect ir;
35
36 paint.setStyle(SkPaint::kStroke_Style);
37
38 ir.set(0, 0, 128, 128);
39 r.set(ir);
40
41 canvas->save();
42 canvas->clipRect(r);
43 canvas->drawBitmap(bm, 0, 0, NULL);
44 canvas->restore();
45 canvas->drawRect(r, paint);
46
47 r.offset(SkIntToScalar(150), 0);
48 // exercises extract bitmap, but not shader
49 canvas->drawBitmapRect(bm, &ir, r, NULL);
50 canvas->drawRect(r, paint);
51
52 r.offset(SkIntToScalar(150), 0);
53 // exercises bitmapshader
54 canvas->drawBitmapRect(bm, NULL, r, NULL);
55 canvas->drawRect(r, paint);
56}
57
58class VeryLargeBitmapGM : public skiagm::GM {
59public:
60 VeryLargeBitmapGM() {}
61
62protected:
63 virtual SkString onShortName() SK_OVERRIDE {
64 return SkString("verylargebitmap");
65 }
66
67 virtual SkISize onISize() SK_OVERRIDE {
bsalomon@google.comaf562b42013-10-24 17:52:07 +000068 return SkISize::Make(500, 600);
reed@google.com7eb3a262012-08-07 14:05:14 +000069 }
70
71 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
bsalomon@google.comedf00c72013-10-24 20:55:14 +000072 int veryBig = 65*1024; // 64K < size
73 int big = 33*1024; // 32K < size < 64K
bsalomon@google.comaf562b42013-10-24 17:52:07 +000074 // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
bsalomon@google.comedf00c72013-10-24 20:55:14 +000075 int medium = 5*1024;
robertphillips@google.comc3dc12d2013-07-15 15:48:48 +000076 int small = 150;
reed@google.com7eb3a262012-08-07 14:05:14 +000077
bsalomon@google.comaf562b42013-10-24 17:52:07 +000078 SkColor colors[2];
79
reed@google.com7eb3a262012-08-07 14:05:14 +000080 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
bsalomon@google.comaf562b42013-10-24 17:52:07 +000081 colors[0] = SK_ColorRED;
82 colors[1] = SK_ColorGREEN;
83 show_bm(canvas, small, small, colors);
reed@google.com7eb3a262012-08-07 14:05:14 +000084 canvas->translate(0, SkIntToScalar(150));
85
bsalomon@google.comaf562b42013-10-24 17:52:07 +000086 colors[0] = SK_ColorBLUE;
87 colors[1] = SK_ColorMAGENTA;
88 show_bm(canvas, big, small, colors);
reed@google.com7eb3a262012-08-07 14:05:14 +000089 canvas->translate(0, SkIntToScalar(150));
rmistry@google.comae933ce2012-08-23 18:19:56 +000090
bsalomon@google.comaf562b42013-10-24 17:52:07 +000091 colors[0] = SK_ColorMAGENTA;
92 colors[1] = SK_ColorYELLOW;
bsalomon@google.comaf562b42013-10-24 17:52:07 +000093 show_bm(canvas, medium, medium, colors);
94 canvas->translate(0, SkIntToScalar(150));
95
96 colors[0] = SK_ColorGREEN;
97 colors[1] = SK_ColorYELLOW;
98 // as of this writing, the raster code will fail to draw the scaled version
99 // since it has a 64K limit on x,y coordinates... (but gpu should succeed)
100 show_bm(canvas, veryBig, small, colors);
reed@google.com7eb3a262012-08-07 14:05:14 +0000101 }
102
commit-bot@chromium.org537e26a2013-10-30 18:58:03 +0000103 virtual uint32_t onGetFlags() const {
104#ifdef SK_BUILD_FOR_WIN32
105 // The Windows bot runs out of memory in replay modes on this test in 32bit builds:
106 // http://skbug.com/1756
107 return kSkipPicture_Flag |
108 kSkipPipe_Flag |
109 kSkipPipeCrossProcess_Flag |
110 kSkipTiled_Flag |
111 kSkipScaledReplay_Flag;
112#else
113 return 0;
114#endif
115 }
116
reed@google.com7eb3a262012-08-07 14:05:14 +0000117private:
118 typedef skiagm::GM INHERITED;
119};
120
121//////////////////////////////////////////////////////////////////////////////
122
borenet@google.com24e89992012-08-07 14:46:05 +0000123// This GM allocates more memory than Android devices are capable of fulfilling.
124#ifndef SK_BUILD_FOR_ANDROID
reed@google.com7eb3a262012-08-07 14:05:14 +0000125static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; }
126static skiagm::GMRegistry reg(MyFactory);
borenet@google.com24e89992012-08-07 14:46:05 +0000127#endif