scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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" |
tfarina | bcbc178 | 2014-06-18 14:32:48 -0700 | [diff] [blame] | 9 | |
| 10 | #include "Resources.h" |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 12 | #include "SkOSFile.h" |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | /** |
| 17 | * Test copying an image from 8888 to 4444. |
| 18 | */ |
| 19 | class CopyTo4444GM : public GM { |
| 20 | public: |
| 21 | CopyTo4444GM() {} |
| 22 | |
| 23 | protected: |
| 24 | virtual SkString onShortName() { |
| 25 | return SkString("copyTo4444"); |
| 26 | } |
| 27 | |
| 28 | virtual SkISize onISize() { |
tfarina | f539318 | 2014-06-09 23:59:03 -0700 | [diff] [blame] | 29 | return SkISize::Make(1024, 512); |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | virtual void onDraw(SkCanvas* canvas) { |
| 33 | SkBitmap bm, bm4444; |
msarett | e820dfe | 2016-03-18 12:13:47 -0700 | [diff] [blame] | 34 | if (!GetResourceAsBitmap("mandrill_512.png", &bm)) { |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 35 | SkDebugf("Could not decode the file. Did you forget to set the " |
| 36 | "resourcePath?\n"); |
| 37 | return; |
| 38 | } |
| 39 | canvas->drawBitmap(bm, 0, 0); |
commit-bot@chromium.org | 8a2ad3c | 2014-02-23 03:59:35 +0000 | [diff] [blame] | 40 | SkAssertResult(bm.copyTo(&bm4444, kARGB_4444_SkColorType)); |
scroggo@google.com | 7bb36ab | 2013-08-07 19:39:56 +0000 | [diff] [blame] | 41 | canvas->drawBitmap(bm4444, SkIntToScalar(bm.width()), 0); |
scroggo@google.com | 8dc8bc5 | 2013-08-07 19:16:05 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | private: |
| 45 | typedef GM INHERITED; |
| 46 | }; |
| 47 | |
| 48 | ////////////////////////////////////////////////////////////////////////////// |
| 49 | |
| 50 | static GM* MyFactory(void*) { return new CopyTo4444GM; } |
| 51 | static GMRegistry reg(MyFactory); |
| 52 | |
| 53 | } |