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 15 DEF_SIMPLE_GM(cross_context_image, canvas, 512 * 3 + 60, 512 + 128 + 30) { 16 GrContext* context = canvas->getGrContext(); 17 if (!context) { 18 skiagm::GM::DrawGpuOnlyMessage(canvas); 19 return; 20 } 21 22 sk_sp<SkData> encodedData = GetResourceAsData("images/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( 28 context, encodedData, false, canvas->imageInfo().colorSpace()); 29 canvas->drawImage(crossContextImage, 512 + 30, 10); 30 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 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); 43 sk_sp<SkImage> crossContextRasterSubset = crossContextRaster->makeSubset(subset); 44 45 canvas->drawImage(encodedSubset, 10, 512 + 30); 46 canvas->drawImage(crossContextSubset, 512 + 30, 512 + 30); 47 canvas->drawImage(crossContextRasterSubset, 512 + 512 + 60, 512 + 30); 48 } 49 50 #endif 51