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 #include "GrContext.h" 12 #include "SkImage.h" 13 14 DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg, 15 5 * 256 + 60, 256 + 128 + 30) { 16 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png"); 17 if (!encodedData) { 18 *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?"; 19 return skiagm::DrawResult::kFail; 20 } 21 22 sk_sp<SkImage> images[5]; 23 images[0] = SkImage::MakeFromEncoded(encodedData); 24 25 SkBitmap bmp; 26 SkPixmap pixmap; 27 SkAssertResult(images[0]->asLegacyBitmap(&bmp) && 28 bmp.peekPixels(&pixmap)); 29 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); 34 35 canvas->translate(10, 10); 36 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 } 53 return skiagm::DrawResult::kOk; 54 } 55