Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 "Resources.h" |
| 10 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 11 | #include "GrContext.h" |
| 12 | #include "SkImage.h" |
| 13 | |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 14 | DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg, |
| 15 | 5 * 256 + 60, 256 + 128 + 30) { |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 16 | sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png"); |
Hal Canary | baa2a28 | 2018-11-26 15:34:12 -0500 | [diff] [blame] | 17 | if (!encodedData) { |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 18 | *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?"; |
| 19 | return skiagm::DrawResult::kFail; |
Hal Canary | baa2a28 | 2018-11-26 15:34:12 -0500 | [diff] [blame] | 20 | } |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 21 | |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 22 | sk_sp<SkImage> images[5]; |
| 23 | images[0] = SkImage::MakeFromEncoded(encodedData); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 24 | |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 25 | SkBitmap bmp; |
| 26 | SkPixmap pixmap; |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 27 | SkAssertResult(images[0]->asLegacyBitmap(&bmp) && |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 28 | bmp.peekPixels(&pixmap)); |
| 29 | |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 30 | images[1] = SkImage::MakeCrossContextFromEncoded(context, encodedData, false, nullptr); |
| 31 | images[2] = SkImage::MakeCrossContextFromEncoded(context, encodedData, true, nullptr); |
| 32 | images[3] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false, nullptr); |
| 33 | images[4] = SkImage::MakeCrossContextFromPixmap(context, pixmap, true, nullptr); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 34 | |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 35 | canvas->translate(10, 10); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 36 | |
Brian Osman | 0471a93 | 2019-02-07 13:36:56 -0500 | [diff] [blame] | 37 | for (size_t i = 0; i < SK_ARRAY_COUNT(images); ++i) { |
| 38 | canvas->save(); |
| 39 | |
| 40 | canvas->drawImage(images[i], 0, 0); |
| 41 | canvas->translate(0, 256 + 10); |
| 42 | |
| 43 | canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128)), 0, 0); |
| 44 | canvas->translate(128, 0); |
| 45 | |
| 46 | SkPaint paint; |
| 47 | paint.setFilterQuality(kMedium_SkFilterQuality); |
| 48 | canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128), &paint); |
| 49 | |
| 50 | canvas->restore(); |
| 51 | canvas->translate(256 + 10, 0); |
| 52 | } |
Chris Dalton | 50e24d7 | 2019-02-07 16:20:09 -0700 | [diff] [blame] | 53 | return skiagm::DrawResult::kOk; |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 54 | } |