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 | |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 14 | DEF_SIMPLE_GM(cross_context_image, canvas, 512 * 3 + 60, 512 + 128 + 30) { |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 15 | GrContext* context = canvas->getGrContext(); |
| 16 | if (!context) { |
| 17 | skiagm::GM::DrawGpuOnlyMessage(canvas); |
| 18 | return; |
| 19 | } |
| 20 | |
Hal Canary | c465d13 | 2017-12-08 10:21:31 -0500 | [diff] [blame] | 21 | sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_512.png"); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 22 | |
| 23 | sk_sp<SkImage> encodedImage = SkImage::MakeFromEncoded(encodedData); |
| 24 | canvas->drawImage(encodedImage, 10, 10); |
| 25 | |
| 26 | sk_sp<SkImage> crossContextImage = SkImage::MakeCrossContextFromEncoded( |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 27 | context, encodedData, false, canvas->imageInfo().colorSpace()); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 28 | canvas->drawImage(crossContextImage, 512 + 30, 10); |
| 29 | |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 30 | SkBitmap bmp; |
| 31 | SkPixmap pixmap; |
Cary Clark | 4f5a79c | 2018-02-07 15:51:00 -0500 | [diff] [blame] | 32 | SkAssertResult(encodedImage->asLegacyBitmap(&bmp) && |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 33 | bmp.peekPixels(&pixmap)); |
| 34 | |
| 35 | sk_sp<SkImage> crossContextRaster = SkImage::MakeCrossContextFromPixmap( |
| 36 | context, pixmap, false, canvas->imageInfo().colorSpace()); |
| 37 | canvas->drawImage(crossContextRaster, 512 + 512 + 60, 10); |
| 38 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 39 | SkIRect subset = SkIRect::MakeXYWH(256 - 64, 256 - 64, 128, 128); |
| 40 | sk_sp<SkImage> encodedSubset = encodedImage->makeSubset(subset); |
| 41 | sk_sp<SkImage> crossContextSubset = crossContextImage->makeSubset(subset); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 42 | sk_sp<SkImage> crossContextRasterSubset = crossContextRaster->makeSubset(subset); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 43 | |
| 44 | canvas->drawImage(encodedSubset, 10, 512 + 30); |
| 45 | canvas->drawImage(crossContextSubset, 512 + 30, 512 + 30); |
Brian Osman | 63bc48d | 2017-11-07 10:37:00 -0500 | [diff] [blame] | 46 | canvas->drawImage(crossContextRasterSubset, 512 + 512 + 60, 512 + 30); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 47 | } |