| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "Resources.h" | 9 #include "Resources.h" |
| 10 | 10 |
| 11 #include "SkImageDecoder.h" |
| 11 #include "SkPixelXorXfermode.h" | 12 #include "SkPixelXorXfermode.h" |
| 12 #include "SkStream.h" | 13 #include "SkStream.h" |
| 13 | 14 |
| 14 class PixelXorXfermodeGM : public skiagm::GM { | 15 class PixelXorXfermodeGM : public skiagm::GM { |
| 15 public: | 16 public: |
| 16 PixelXorXfermodeGM() { } | 17 PixelXorXfermodeGM() { } |
| 17 | 18 |
| 18 protected: | 19 protected: |
| 19 SkString onShortName() override { | 20 SkString onShortName() override { |
| 20 return SkString("pixelxorxfermode"); | 21 return SkString("pixelxorxfermode"); |
| 21 } | 22 } |
| 22 | 23 |
| 23 SkISize onISize() override { return SkISize::Make(512, 512); } | 24 SkISize onISize() override { return SkISize::Make(512, 512); } |
| 24 | 25 |
| 25 void onOnceBeforeDraw() override { | 26 void onOnceBeforeDraw() override { |
| 26 if (!GetResourceAsBitmap("mandrill_512.png", &fBM)) { | 27 SkImageDecoder* codec = nullptr; |
| 28 SkString resourcePath = GetResourcePath("mandrill_512.png"); |
| 29 SkFILEStream stream(resourcePath.c_str()); |
| 30 if (stream.isValid()) { |
| 31 codec = SkImageDecoder::Factory(&stream); |
| 32 } |
| 33 if (codec) { |
| 34 stream.rewind(); |
| 35 codec->decode(&stream, &fBM, kN32_SkColorType, SkImageDecoder::kDeco
dePixels_Mode); |
| 36 delete codec; |
| 37 } else { |
| 27 fBM.allocN32Pixels(1, 1); | 38 fBM.allocN32Pixels(1, 1); |
| 28 fBM.eraseARGB(255, 255, 0 , 0); // red == bad | 39 fBM.eraseARGB(255, 255, 0 , 0); // red == bad |
| 29 } | 40 } |
| 30 } | 41 } |
| 31 | 42 |
| 32 void onDraw(SkCanvas* canvas) override { | 43 void onDraw(SkCanvas* canvas) override { |
| 33 canvas->drawBitmap(fBM, 0, 0); | 44 canvas->drawBitmap(fBM, 0, 0); |
| 34 | 45 |
| 35 SkRect r = SkRect::MakeIWH(256, 256); | 46 SkRect r = SkRect::MakeIWH(256, 256); |
| 36 | 47 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 84 |
| 74 private: | 85 private: |
| 75 SkBitmap fBM; | 86 SkBitmap fBM; |
| 76 | 87 |
| 77 typedef GM INHERITED; | 88 typedef GM INHERITED; |
| 78 }; | 89 }; |
| 79 | 90 |
| 80 ////////////////////////////////////////////////////////////////////////////// | 91 ////////////////////////////////////////////////////////////////////////////// |
| 81 | 92 |
| 82 DEF_GM(return new PixelXorXfermodeGM;) | 93 DEF_GM(return new PixelXorXfermodeGM;) |
| OLD | NEW |