6db78b8638
Fixes unexpected image changes to ducky_yuv_blend after https://skia-review.googlesource.com/c/skia/+/306360 Change-Id: Ic517075883b301c3645059005c6f5d7417872c48 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307016 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com> Auto-Submit: Brian Salomon <bsalomon@google.com>
80 lines
2.8 KiB
C++
80 lines
2.8 KiB
C++
/*
|
|
* Copyright 2019 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "gm/gm.h"
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkYUVAIndex.h"
|
|
#include "include/core/SkYUVASizeInfo.h"
|
|
#include "include/gpu/GrRecordingContext.h"
|
|
#include "src/core/SkCachedData.h"
|
|
#include "src/image/SkImage_Base.h"
|
|
#include "tools/Resources.h"
|
|
#include "tools/ToolUtils.h"
|
|
#include "tools/gpu/YUVUtils.h"
|
|
|
|
// Modeled on the layout test css3/blending/background-blend-mode-image-image.html to reproduce
|
|
// skbug.com/9619
|
|
DEF_SIMPLE_GM_CAN_FAIL(ducky_yuv_blend, canvas, errorMsg, 560, 1130) {
|
|
sk_sp<SkImage> duckyBG = GetResourceAsImage("images/ducky.png");
|
|
sk_sp<SkImage> duckyFG[2] = {GetResourceAsImage("images/ducky.jpg"), nullptr};
|
|
if (!duckyFG[0] || !duckyBG) {
|
|
*errorMsg = "Image(s) failed to load.";
|
|
return skiagm::DrawResult::kFail;
|
|
}
|
|
|
|
// If we're on the GPU we do a second round of draws where the source image is YUV planes.
|
|
// Otherwise we just draw the original again,
|
|
if (auto* rContext = canvas->recordingContext(); rContext && !rContext->abandoned()) {
|
|
auto lazyYUV = sk_gpu_test::LazyYUVImage::Make(GetResourceAsData("images/ducky.jpg"),
|
|
GrMipmapped::kYes);
|
|
if (lazyYUV) {
|
|
duckyFG[1] = lazyYUV->refImage(rContext);
|
|
}
|
|
if (!duckyFG[1]) {
|
|
return skiagm::DrawResult::kFail;
|
|
}
|
|
} else {
|
|
duckyFG[1] = duckyFG[0];
|
|
}
|
|
|
|
static constexpr int kNumPerRow = 4;
|
|
static constexpr int kPad = 10;
|
|
static constexpr auto kDstRect = SkRect::MakeWH(130, 130);
|
|
int rowCnt = 0;
|
|
canvas->translate(kPad, kPad);
|
|
canvas->save();
|
|
auto newRow = [&] {
|
|
canvas->restore();
|
|
canvas->translate(0, kDstRect.height() + kPad);
|
|
canvas->save();
|
|
rowCnt = 0;
|
|
};
|
|
ToolUtils::draw_checkerboard(
|
|
canvas, SK_ColorDKGRAY, SK_ColorLTGRAY, (kDstRect.height() + kPad)/5);
|
|
for (auto& fg : duckyFG) {
|
|
for (int bm = static_cast<int>(SkBlendMode::kLastCoeffMode) + 1;
|
|
bm < static_cast<int>(SkBlendMode::kLastMode);
|
|
++bm) {
|
|
auto mode = static_cast<SkBlendMode>(bm);
|
|
SkPaint paint;
|
|
paint.setFilterQuality(kMedium_SkFilterQuality);
|
|
canvas->drawImageRect(duckyBG, kDstRect, &paint);
|
|
paint.setBlendMode(mode);
|
|
canvas->drawImageRect(fg, kDstRect, &paint);
|
|
canvas->translate(kDstRect.width() + kPad, 0);
|
|
if (++rowCnt == kNumPerRow) {
|
|
newRow();
|
|
}
|
|
}
|
|
// Force a new row between the two foreground images
|
|
newRow();
|
|
}
|
|
canvas->restore();
|
|
return skiagm::DrawResult::kOk;
|
|
}
|