blob: 12ef6796ff9797ea85d1941a61478c3b81beee17 [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
Brian Osman63bc48d2017-11-07 10:37:00 -050014DEF_SIMPLE_GM(cross_context_image, canvas, 512 * 3 + 60, 512 + 128 + 30) {
Brian Osman13dddce2017-05-09 13:19:50 -040015 GrContext* context = canvas->getGrContext();
16 if (!context) {
17 skiagm::GM::DrawGpuOnlyMessage(canvas);
18 return;
19 }
20
Hal Canaryc465d132017-12-08 10:21:31 -050021 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_512.png");
Brian Osman13dddce2017-05-09 13:19:50 -040022
23 sk_sp<SkImage> encodedImage = SkImage::MakeFromEncoded(encodedData);
24 canvas->drawImage(encodedImage, 10, 10);
25
26 sk_sp<SkImage> crossContextImage = SkImage::MakeCrossContextFromEncoded(
Brian Osman63bc48d2017-11-07 10:37:00 -050027 context, encodedData, false, canvas->imageInfo().colorSpace());
Brian Osman13dddce2017-05-09 13:19:50 -040028 canvas->drawImage(crossContextImage, 512 + 30, 10);
29
Brian Osman63bc48d2017-11-07 10:37:00 -050030 SkBitmap bmp;
31 SkPixmap pixmap;
Cary Clark4f5a79c2018-02-07 15:51:00 -050032 SkAssertResult(encodedImage->asLegacyBitmap(&bmp) &&
Brian Osman63bc48d2017-11-07 10:37:00 -050033 bmp.peekPixels(&pixmap));
34
35 sk_sp<SkImage> crossContextRaster = SkImage::MakeCrossContextFromPixmap(
36 context, pixmap, false, canvas->imageInfo().colorSpace());
37 canvas->drawImage(crossContextRaster, 512 + 512 + 60, 10);
38
Brian Osman13dddce2017-05-09 13:19:50 -040039 SkIRect subset = SkIRect::MakeXYWH(256 - 64, 256 - 64, 128, 128);
40 sk_sp<SkImage> encodedSubset = encodedImage->makeSubset(subset);
41 sk_sp<SkImage> crossContextSubset = crossContextImage->makeSubset(subset);
Brian Osman63bc48d2017-11-07 10:37:00 -050042 sk_sp<SkImage> crossContextRasterSubset = crossContextRaster->makeSubset(subset);
Brian Osman13dddce2017-05-09 13:19:50 -040043
44 canvas->drawImage(encodedSubset, 10, 512 + 30);
45 canvas->drawImage(crossContextSubset, 512 + 30, 512 + 30);
Brian Osman63bc48d2017-11-07 10:37:00 -050046 canvas->drawImage(crossContextRasterSubset, 512 + 512 + 60, 512 + 30);
Brian Osman13dddce2017-05-09 13:19:50 -040047}