blob: 351589144577e801e014abbeed2dc62b215b6912 [file] [log] [blame]
Brian Osman13dddce2017-05-09 13:19:50 -04001/*
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 Osman13dddce2017-05-09 13:19:50 -040011#include "GrContext.h"
12#include "SkImage.h"
13
Chris Dalton50e24d72019-02-07 16:20:09 -070014DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
15 5 * 256 + 60, 256 + 128 + 30) {
Brian Osman0471a932019-02-07 13:36:56 -050016 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
Hal Canarybaa2a282018-11-26 15:34:12 -050017 if (!encodedData) {
Chris Dalton50e24d72019-02-07 16:20:09 -070018 *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
19 return skiagm::DrawResult::kFail;
Hal Canarybaa2a282018-11-26 15:34:12 -050020 }
Brian Osman13dddce2017-05-09 13:19:50 -040021
Brian Osman0471a932019-02-07 13:36:56 -050022 sk_sp<SkImage> images[5];
23 images[0] = SkImage::MakeFromEncoded(encodedData);
Brian Osman13dddce2017-05-09 13:19:50 -040024
Brian Osman63bc48d2017-11-07 10:37:00 -050025 SkBitmap bmp;
26 SkPixmap pixmap;
Brian Osman0471a932019-02-07 13:36:56 -050027 SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
Brian Osman63bc48d2017-11-07 10:37:00 -050028 bmp.peekPixels(&pixmap));
29
Brian Osman0471a932019-02-07 13:36:56 -050030 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);
Brian Osman63bc48d2017-11-07 10:37:00 -050034
Brian Osman0471a932019-02-07 13:36:56 -050035 canvas->translate(10, 10);
Brian Osman13dddce2017-05-09 13:19:50 -040036
Brian Osman0471a932019-02-07 13:36:56 -050037 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 }
Chris Dalton50e24d72019-02-07 16:20:09 -070053 return skiagm::DrawResult::kOk;
Brian Osman13dddce2017-05-09 13:19:50 -040054}