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/SkFilterQuality.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"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
class GrContext;
|
|
|
|
class GrRenderTargetContext;
|
2017-05-09 17:19:50 +00:00
|
|
|
|
2019-02-07 23:20:09 +00:00
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(cross_context_image, context, rtc, 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
|
|
|
|
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));
|
|
|
|
|
2019-08-15 16:13:53 +00:00
|
|
|
images[1] = SkImage::MakeCrossContextFromPixmap(context, pixmap, false);
|
|
|
|
images[2] = SkImage::MakeCrossContextFromPixmap(context, 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
|
|
|
|
2019-02-07 18:36:56 +00:00
|
|
|
canvas->drawImage(images[i]->makeSubset(SkIRect::MakeXYWH(64, 64, 128, 128)), 0, 0);
|
|
|
|
canvas->translate(128, 0);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setFilterQuality(kMedium_SkFilterQuality);
|
|
|
|
canvas->drawImageRect(images[i], SkRect::MakeWH(128, 128), &paint);
|
|
|
|
|
|
|
|
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
|
|
|
}
|