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 | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 14 | bm->setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 15 | bm->allocPixels(); |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 16 | 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.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 25 | bm->setImmutable(); |
| 26 | } |
| 27 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 28 | 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] | 29 | SkBitmap bm; |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 30 | make_bm(&bm, width, height, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 31 | |
| 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 | |
| 58 | class VeryLargeBitmapGM : public skiagm::GM { |
| 59 | public: |
| 60 | VeryLargeBitmapGM() {} |
| 61 | |
| 62 | protected: |
| 63 | virtual SkString onShortName() SK_OVERRIDE { |
| 64 | return SkString("verylargebitmap"); |
| 65 | } |
| 66 | |
| 67 | virtual SkISize onISize() SK_OVERRIDE { |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 68 | return SkISize::Make(500, 600); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { |
bsalomon@google.com | edf00c7 | 2013-10-24 20:55:14 +0000 | [diff] [blame] | 72 | int veryBig = 65*1024; // 64K < size |
| 73 | int big = 33*1024; // 32K < size < 64K |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 74 | // 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] | 75 | int medium = 5*1024; |
robertphillips@google.com | c3dc12d | 2013-07-15 15:48:48 +0000 | [diff] [blame] | 76 | int small = 150; |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 77 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 78 | SkColor colors[2]; |
| 79 | |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 80 | canvas->translate(SkIntToScalar(10), SkIntToScalar(10)); |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 81 | colors[0] = SK_ColorRED; |
| 82 | colors[1] = SK_ColorGREEN; |
| 83 | show_bm(canvas, small, small, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 84 | canvas->translate(0, SkIntToScalar(150)); |
| 85 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 86 | colors[0] = SK_ColorBLUE; |
| 87 | colors[1] = SK_ColorMAGENTA; |
| 88 | show_bm(canvas, big, small, colors); |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 89 | canvas->translate(0, SkIntToScalar(150)); |
rmistry@google.com | ae933ce | 2012-08-23 18:19:56 +0000 | [diff] [blame] | 90 | |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 91 | colors[0] = SK_ColorMAGENTA; |
| 92 | colors[1] = SK_ColorYELLOW; |
bsalomon@google.com | af562b4 | 2013-10-24 17:52:07 +0000 | [diff] [blame] | 93 | 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.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 101 | } |
| 102 | |
commit-bot@chromium.org | 537e26a | 2013-10-30 18:58:03 +0000 | [diff] [blame^] | 103 | 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.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 117 | private: |
| 118 | typedef skiagm::GM INHERITED; |
| 119 | }; |
| 120 | |
| 121 | ////////////////////////////////////////////////////////////////////////////// |
| 122 | |
borenet@google.com | 24e8999 | 2012-08-07 14:46:05 +0000 | [diff] [blame] | 123 | // This GM allocates more memory than Android devices are capable of fulfilling. |
| 124 | #ifndef SK_BUILD_FOR_ANDROID |
reed@google.com | 7eb3a26 | 2012-08-07 14:05:14 +0000 | [diff] [blame] | 125 | static skiagm::GM* MyFactory(void*) { return new VeryLargeBitmapGM; } |
| 126 | static skiagm::GMRegistry reg(MyFactory); |
borenet@google.com | 24e8999 | 2012-08-07 14:46:05 +0000 | [diff] [blame] | 127 | #endif |