reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 1 | /* |
| 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.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 10 | #include "SkGradientShader.h" |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
| 12 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 13 | static void make_bm(SkBitmap* bm, int width, int height, SkColor colors[2]) { |
reed@google.com | eb9a46c | 2014-01-25 16:46:20 +0000 | [diff] [blame] | 14 | bm->allocN32Pixels(width, height); |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 15 | SkCanvas canvas(*bm); |
| 16 | SkPoint center = {SkIntToScalar(width)/2, SkIntToScalar(height)/2}; |
| 17 | SkScalar radius = 40; |
| 18 | SkShader* shader = SkGradientShader::CreateRadial(center, radius, colors, NULL, 2, |
| 19 | SkShader::kMirror_TileMode); |
| 20 | SkPaint paint; |
| 21 | paint.setShader(shader)->unref(); |
| 22 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 23 | canvas.drawPaint(paint); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 24 | bm->setImmutable(); |
| 25 | } |
| 26 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 27 | static void show_bm(SkCanvas* canvas, int width, int height, SkColor colors[2]) { |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 28 | SkBitmap bm; |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 29 | make_bm(&bm, width, height, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 30 | |
| 31 | SkPaint paint; |
| 32 | SkRect r; |
| 33 | SkIRect ir; |
| 34 | |
| 35 | paint.setStyle(SkPaint::kStroke_Style); |
| 36 | |
| 37 | ir.set(0, 0, 128, 128); |
| 38 | r.set(ir); |
| 39 | |
| 40 | canvas->save(); |
| 41 | canvas->clipRect(r); |
| 42 | canvas->drawBitmap(bm, 0, 0, NULL); |
| 43 | canvas->restore(); |
| 44 | canvas->drawRect(r, paint); |
| 45 | |
| 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); |
| 50 | |
| 51 | r.offset(SkIntToScalar(150), 0); |
| 52 | // exercises bitmapshader |
| 53 | canvas->drawBitmapRect(bm, NULL, r, NULL); |
| 54 | canvas->drawRect(r, paint); |
| 55 | } |
| 56 | |
| 57 | class VeryLargeBitmapGM : public skiagm::GM { |
| 58 | public: |
| 59 | VeryLargeBitmapGM() {} |
| 60 | |
| 61 | protected: |
| 62 | virtual SkString onShortName() SK_OVERRIDE { |
| 63 | return SkString("verylargebitmap"); |
| 64 | } |
| 65 | |
| 66 | virtual SkISize onISize() SK_OVERRIDE { |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 67 | return SkISize::Make(500, 600); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
bsalomon@google.com | edf00c7 | 2013-10-24 20:55:14 +0000 | [diff] [blame] | 71 | int veryBig = 65*1024; // 64K < size |
| 72 | int big = 33*1024; // 32K < size < 64K |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 73 | // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons. |
bsalomon@google.com | edf00c7 | 2013-10-24 20:55:14 +0000 | [diff] [blame] | 74 | int medium = 5*1024; |
robertphillips@google.com | c3dc12d | 2013-07-15 15:48:48 +0000 | [diff] [blame] | 75 | int small = 150; |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 76 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 77 | SkColor colors[2]; |
| 78 | |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 79 | canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 80 | colors[0] = SK_ColorRED; |
| 81 | colors[1] = SK_ColorGREEN; |
| 82 | show_bm(canvas, small, small, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 83 | canvas->translate(0, SkIntToScalar(150)); |
| 84 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 85 | colors[0] = SK_ColorBLUE; |
| 86 | colors[1] = SK_ColorMAGENTA; |
| 87 | show_bm(canvas, big, small, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 88 | canvas->translate(0, SkIntToScalar(150)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 89 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 90 | colors[0] = SK_ColorMAGENTA; |
| 91 | colors[1] = SK_ColorYELLOW; |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 92 | show_bm(canvas, medium, medium, colors); |
| 93 | canvas->translate(0, SkIntToScalar(150)); |
| 94 | |
| 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); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 100 | } |
| 101 | |
commit-bot@chromium.org | 537e26a | 2013-10-30 18:58:03 +0000 | [diff] [blame] | 102 | #ifdef SK_BUILD_FOR_WIN32 |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 103 | virtual uint32_t onGetFlags() const { |
commit-bot@chromium.org | 537e26a | 2013-10-30 18:58:03 +0000 | [diff] [blame] | 104 | // The Windows bot runs out of memory in replay modes on this test in 32bit builds: |
| 105 | // http://skbug.com/1756 |
| 106 | return kSkipPicture_Flag | |
| 107 | kSkipPipe_Flag | |
| 108 | kSkipPipeCrossProcess_Flag | |
| 109 | kSkipTiled_Flag | |
| 110 | kSkipScaledReplay_Flag; |
commit-bot@chromium.org | 537e26a | 2013-10-30 18:58:03 +0000 | [diff] [blame] | 111 | } |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 112 | #endif |
commit-bot@chromium.org | 537e26a | 2013-10-30 18:58:03 +0000 | [diff] [blame] | 113 | |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 114 | private: |
| 115 | typedef skiagm::GM INHERITED; |
| 116 | }; |
| 117 | |
| 118 | ////////////////////////////////////////////////////////////////////////////// |
| 119 | |
| 120 | static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } |
| 121 | static skiagm::GMRegistry reg(MyFactory); |