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/gm.h" 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" 20 #include "tools/Resources.h" 21 22 class GrContext; 23 class GrRenderTargetContext; 24 25 DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg, 26 3 * 256 + 40, 256 + 128 + 30) { 27 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png"); 28 if (!encodedData) { 29 *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?"; 30 return skiagm::DrawResult::kFail; 31 } 32 33 sk_sp<SkImage> images[3]; 34 images[0] = SkImage::MakeFromEncoded(encodedData); 35 36 SkBitmap bmp; 37 SkPixmap pixmap; 38 SkAssertResult(images[0]->asLegacyBitmap(&bmp) && 39 bmp.peekPixels(&pixmap)); 40 41 images[1] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false); 42 images[2] = SkImage::MakeCrossContextFromPixmap(context, pixmap, true); 43 44 canvas->translate(10, 10); 45 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 } 62 return skiagm::DrawResult::kOk; 63 } 64