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