blob: 8afbf6d4a92840cd5da814f12338e1d7b3055cdb [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050020#include "tools/Resources.h"
Brian Osman13dddce2017-05-09 13:19:50 -040021
Ben Wagner7fde8e12019-05-01 17:28:53 -040022class GrContext;
23class GrRenderTargetContext;
Brian Osman13dddce2017-05-09 13:19:50 -040024
Chris Dalton50e24d72019-02-07 16:20:09 -070025DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, canvas, errorMsg,
Brian Osman4c3fd342019-08-15 12:13:53 -040026 3 * 256 + 40, 256 + 128 + 30) {
Brian Osman0471a932019-02-07 13:36:56 -050027 sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
Hal Canarybaa2a282018-11-26 15:34:12 -050028 if (!encodedData) {
Chris Dalton50e24d72019-02-07 16:20:09 -070029 *errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
30 return skiagm::DrawResult::kFail;
Hal Canarybaa2a282018-11-26 15:34:12 -050031 }
Brian Osman13dddce2017-05-09 13:19:50 -040032
Brian Osman4c3fd342019-08-15 12:13:53 -040033 sk_sp<SkImage> images[3];
Brian Osman0471a932019-02-07 13:36:56 -050034 images[0] = SkImage::MakeFromEncoded(encodedData);
Brian Osman13dddce2017-05-09 13:19:50 -040035
Brian Osman63bc48d2017-11-07 10:37:00 -050036 SkBitmap bmp;
37 SkPixmap pixmap;
Brian Osman0471a932019-02-07 13:36:56 -050038 SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
Brian Osman63bc48d2017-11-07 10:37:00 -050039 bmp.peekPixels(&pixmap));
40
Brian Osman4c3fd342019-08-15 12:13:53 -040041 images[1] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false);
42 images[2] = SkImage::MakeCrossContextFromPixmap(context, pixmap, true);
Brian Osman63bc48d2017-11-07 10:37:00 -050043
Brian Osman0471a932019-02-07 13:36:56 -050044 canvas->translate(10, 10);
Brian Osman13dddce2017-05-09 13:19:50 -040045
Brian Osman0471a932019-02-07 13:36:56 -050046 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 }
Chris Dalton50e24d72019-02-07 16:20:09 -070062 return skiagm::DrawResult::kOk;
Brian Osman13dddce2017-05-09 13:19:50 -040063}