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