2017-05-09 17:19:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkData.h"
|
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPixmap.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
|
|
|
#include "include/gpu/GrRecordingContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, rContext, canvas, errorMsg,
|
2019-08-15 16:13:53 +00:00
|
|
|
3 * 256 + 40, 256 + 128 + 30) {
|
2019-02-07 18:36:56 +00:00
|
|
|
sk_sp<SkData> encodedData = GetResourceAsData("images/mandrill_256.png");
|
2018-11-26 20:34:12 +00:00
|
|
|
if (!encodedData) {
|
2019-02-07 23:20:09 +00:00
|
|
|
*errorMsg = "Could not load mandrill_256.png. Did you forget to set the resourcePath?";
|
|
|
|
return skiagm::DrawResult::kFail;
|
2018-11-26 20:34:12 +00:00
|
|
|
}
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
auto dContext = rContext->asDirectContext();
|
2020-08-11 15:47:47 +00:00
|
|
|
if (!dContext) {
|
2020-06-26 12:08:22 +00:00
|
|
|
*errorMsg = "CrossContext image creation requires a direct context.";
|
|
|
|
return skiagm::DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2019-08-15 16:13:53 +00:00
|
|
|
sk_sp<SkImage> images[3];
|
2019-02-07 18:36:56 +00:00
|
|
|
images[0] = SkImage::MakeFromEncoded(encodedData);
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2017-11-07 15:37:00 +00:00
|
|
|
SkBitmap bmp;
|
|
|
|
SkPixmap pixmap;
|
2019-02-07 18:36:56 +00:00
|
|
|
SkAssertResult(images[0]->asLegacyBitmap(&bmp) &&
|
2017-11-07 15:37:00 +00:00
|
|
|
bmp.peekPixels(&pixmap));
|
|
|
|
|
2020-08-11 15:47:47 +00:00
|
|
|
images[1] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false);
|
|
|
|
images[2] = SkImage::MakeCrossContextFromPixmap(dContext, pixmap, true);
|
2019-02-07 18:36:56 +00:00
|
|
|
|
|
|
|
canvas->translate(10, 10);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(images); ++i) {
|
|
|
|
canvas->save();
|
2017-11-07 15:37:00 +00:00
|
|
|
|
2019-02-07 18:36:56 +00:00
|
|
|
canvas->drawImage(images[i], 0, 0);
|
|
|
|
canvas->translate(0, 256 + 10);
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2020-08-11 15:47:47 +00:00
|
|
|
canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128), dContext),
|
|
|
|
0, 0);
|
2019-02-07 18:36:56 +00:00
|
|
|
canvas->translate(128, 0);
|
|
|
|
|
2021-01-23 23:10:39 +00:00
|
|
|
canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128),
|
|
|
|
SkSamplingOptions(SkFilterMode::kLinear,
|
|
|
|
SkMipmapMode::kLinear));
|
2019-02-07 18:36:56 +00:00
|
|
|
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(256 + 10, 0);
|
|
|
|
}
|
2019-02-07 23:20:09 +00:00
|
|
|
return skiagm::DrawResult::kOk;
|
2017-05-09 17:19:50 +00:00
|
|
|
}
|