| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 | 9 |
| 10 #include "Resources.h" | 10 #include "Resources.h" |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkImageDecoder.h" | |
| 13 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 14 | 13 |
| 15 namespace skiagm { | 14 namespace skiagm { |
| 16 | 15 |
| 17 /** | 16 /** |
| 18 * Test copying an image from 8888 to 4444. | 17 * Test copying an image from 8888 to 4444. |
| 19 */ | 18 */ |
| 20 class CopyTo4444GM : public GM { | 19 class CopyTo4444GM : public GM { |
| 21 public: | 20 public: |
| 22 CopyTo4444GM() {} | 21 CopyTo4444GM() {} |
| 23 | 22 |
| 24 protected: | 23 protected: |
| 25 virtual SkString onShortName() { | 24 virtual SkString onShortName() { |
| 26 return SkString("copyTo4444"); | 25 return SkString("copyTo4444"); |
| 27 } | 26 } |
| 28 | 27 |
| 29 virtual SkISize onISize() { | 28 virtual SkISize onISize() { |
| 30 return SkISize::Make(1024, 512); | 29 return SkISize::Make(1024, 512); |
| 31 } | 30 } |
| 32 | 31 |
| 33 virtual void onDraw(SkCanvas* canvas) { | 32 virtual void onDraw(SkCanvas* canvas) { |
| 34 SkBitmap bm, bm4444; | 33 SkBitmap bm, bm4444; |
| 35 SkString pngFilename = GetResourcePath("mandrill_512.png"); | 34 if (!GetResourceAsBitmap("mandrill_512.png", &bm)) { |
| 36 if (!SkImageDecoder::DecodeFile(pngFilename.c_str(), &bm, kN32_SkColorTy
pe, | |
| 37 SkImageDecoder::kDecodePixels_Mode)) { | |
| 38 SkDebugf("Could not decode the file. Did you forget to set the " | 35 SkDebugf("Could not decode the file. Did you forget to set the " |
| 39 "resourcePath?\n"); | 36 "resourcePath?\n"); |
| 40 return; | 37 return; |
| 41 } | 38 } |
| 42 canvas->drawBitmap(bm, 0, 0); | 39 canvas->drawBitmap(bm, 0, 0); |
| 43 SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType)); | 40 SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType)); |
| 44 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0); | 41 canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0); |
| 45 } | 42 } |
| 46 | 43 |
| 47 private: | 44 private: |
| 48 typedef GM INHERITED; | 45 typedef GM INHERITED; |
| 49 }; | 46 }; |
| 50 | 47 |
| 51 ////////////////////////////////////////////////////////////////////////////// | 48 ////////////////////////////////////////////////////////////////////////////// |
| 52 | 49 |
| 53 static GM* MyFactory(void*) { return new CopyTo4444GM; } | 50 static GM* MyFactory(void*) { return new CopyTo4444GM; } |
| 54 static GMRegistry reg(MyFactory); | 51 static GMRegistry reg(MyFactory); |
| 55 | 52 |
| 56 } | 53 } |
| OLD | NEW |