skia2/gm/makecolorspace.cpp

180 lines
7.7 KiB
C++
Raw Normal View History

/*
* Copyright 2017 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/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
#include "include/gpu/GrDirectContext.h"
#include "src/core/SkImagePriv.h"
#include "tools/Resources.h"
#include <initializer_list>
#include <memory>
sk_sp<SkImage> make_raster_image(const char* path) {
Revert "Revert "resources: remove most uses of GetResourcePath()"" This reverts commit cca230055921d2df8708ed6f9abcc2d43468dc7f. Reason for revert: think I guessed wrong about g32 -- unreverting Original change's description: > Revert "resources: remove most uses of GetResourcePath()" > > This reverts commit 5093a539def3ae09df324018f2343827009b2e05. > > Reason for revert: google3 seems broken > > Original change's description: > > resources: remove most uses of GetResourcePath() > > > > Going forward, we will standardize on GetResourceAsData(), which will > > make it easier to run tests in environments without access to the > > filesystem. > > > > Also: GetResourceAsData() complains when a resource is missing. > > This is usually an error. > > > > Change-Id: Iaf70b71b0ca5ed8cd1a5538a60ef185ae8736188 > > Reviewed-on: https://skia-review.googlesource.com/82642 > > Reviewed-by: Hal Canary <halcanary@google.com> > > Commit-Queue: Hal Canary <halcanary@google.com> > > TBR=halcanary@google.com,scroggo@google.com > > Change-Id: Ic5a7c0167c995a672e6b06dc92abe00564432214 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/83001 > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Mike Reed <reed@google.com> TBR=halcanary@google.com,scroggo@google.com,reed@google.com Change-Id: I5a46e4de61186a8a5eb9cacd3275e24e311d5a07 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/82942 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
2017-12-09 01:27:41 +00:00
sk_sp<SkData> resourceData = GetResourceAsData(path);
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(resourceData);
return std::get<0>(codec->getImage());
}
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
sk_sp<SkImage> make_color_space(
sk_sp<SkImage> orig, sk_sp<SkColorSpace> colorSpace, GrDirectContext* direct) {
sk_sp<SkImage> xform = orig->makeColorSpace(colorSpace, direct);
// Assign an sRGB color space on the xformed image, so we can see the effects of the xform
// when we draw.
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
if (colorSpace->gammaIsLinear()) {
srgb = SkColorSpace::MakeSRGBLinear();
}
return xform->reinterpretColorSpace(std::move(srgb));
}
DEF_SIMPLE_GM_CAN_FAIL(makecolorspace, canvas, errorMsg, 128 * 3, 128 * 4) {
sk_sp<SkColorSpace> wideGamut = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB,
SkNamedGamut::kAdobeRGB);
sk_sp<SkColorSpace> wideGamutLinear = wideGamut->makeLinearGamma();
// Lazy images
sk_sp<SkImage> opaqueImage = GetResourceAsImage("images/mandrill_128.png");
sk_sp<SkImage> premulImage = GetResourceAsImage("images/color_wheel.png");
if (!opaqueImage || !premulImage) {
*errorMsg = "Failed to load images. Did you forget to set the resourcePath?";
return skiagm::DrawResult::kFail;
}
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
auto direct = GrAsDirectContext(canvas->recordingContext());
canvas->drawImage(opaqueImage, 0.0f, 0.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(make_color_space(opaqueImage, wideGamut, direct), 128.0f, 0.0f);
canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear, direct), 256.0f, 0.0f);
canvas->drawImage(premulImage, 0.0f, 128.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(make_color_space(premulImage, wideGamut, direct), 128.0f, 128.0f);
canvas->drawImage(make_color_space(premulImage, wideGamutLinear, direct), 256.0f, 128.0f);
canvas->translate(0.0f, 256.0f);
// Raster images
opaqueImage = make_raster_image("images/mandrill_128.png");
premulImage = make_raster_image("images/color_wheel.png");
canvas->drawImage(opaqueImage, 0.0f, 0.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(make_color_space(opaqueImage, wideGamut, direct), 128.0f, 0.0f);
canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear, direct), 256.0f, 0.0f);
canvas->drawImage(premulImage, 0.0f, 128.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(make_color_space(premulImage, wideGamut, direct), 128.0f, 128.0f);
canvas->drawImage(make_color_space(premulImage, wideGamutLinear, direct), 256.0f, 128.0f);
return skiagm::DrawResult::kOk;
}
DEF_SIMPLE_GM_BG(makecolortypeandspace, canvas, 128 * 3, 128 * 4, SK_ColorWHITE) {
sk_sp<SkImage> images[] = {
GetResourceAsImage("images/mandrill_128.png"),
GetResourceAsImage("images/color_wheel.png"),
};
auto rec2020 = SkColorSpace::MakeRGB(SkNamedTransferFn::kSRGB, SkNamedGamut::kRec2020);
// Use the lazy images on the first iteration, and concrete (raster/GPU) images on the second
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
auto direct = GrAsDirectContext(canvas->recordingContext());
for (bool lazy : {true, false}) {
for (int j = 0; j < 2; ++j) {
const SkImage* image = images[j].get();
if (!image) {
// Can happen on bots that abandon the GPU context
continue;
}
// Unmodified
canvas->drawImage(image, 0, 0);
// Change the color type/space of the image in a couple ways. In both cases, codec
// may fail, because we refude to decode transparent sources to opaque color types.
// Guard against that, to avoid cascading failures in DDL.
// 565 in a wide color space (should be visibly quantized). Fails with the color_wheel,
// because of the codec issues mentioned above.
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
auto image565 = image->makeColorTypeAndColorSpace(kRGB_565_SkColorType,
rec2020, direct);
if (!lazy || image565->makeRasterImage()) {
canvas->drawImage(image565, 128, 0);
}
// Grayscale in the original color space. This fails in even more cases, due to the
// above opaque issue, and because Ganesh doesn't support drawing to gray, at all.
auto imageGray = image->makeColorTypeAndColorSpace(kGray_8_SkColorType,
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
image->refColorSpace(),
direct);
if (!lazy || imageGray->makeRasterImage()) {
canvas->drawImage(imageGray, 256, 0);
}
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
images[j] = direct ? image->makeTextureImage(direct) : image->makeRasterImage();
canvas->translate(0, 128);
}
}
}
DEF_SIMPLE_GM_CAN_FAIL(reinterpretcolorspace, canvas, errorMsg, 128 * 3, 128 * 3) {
// We draw a 3x3 grid. The three rows are lazy (encoded), raster, and GPU (or another copy of
// raster so all configs look similar). In each row, we draw three variants:
// - The original image (should look normal).
// - The image, reinterpreted as being in the color-spin space. The pixel data isn't changed,
// so in untagged configs, this looks like the first column. In tagged configs, this has the
// the effect of rotating the colors (RGB -> GBR).
// - The image converted to the color-spin space, then reinterpreted as being sRGB. In all
// configs, this appears to be spun backwards (RGB -> BRG), and tests the composition of
// these two APIs.
// In all cases, every column should be identical. In tagged configs, the 'R' in the columns
// should be Red, Green, Blue.
sk_sp<SkColorSpace> srgb = SkColorSpace::MakeSRGB();
sk_sp<SkColorSpace> spin = srgb->makeColorSpin();
sk_sp<SkImage> image = GetResourceAsImage("images/color_wheel.png");
if (!image) {
*errorMsg = "Failed to load image. Did you forget to set the resourcePath?";
return skiagm::DrawResult::kFail;
}
// Lazy images
canvas->drawImage(image, 0.0f, 0.0f);
canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(image->makeColorSpace(spin, nullptr)->reinterpretColorSpace(srgb),
256.0f, 0.0f);
canvas->translate(0.0f, 128.0f);
// Raster images
image = image->makeRasterImage();
canvas->drawImage(image, 0.0f, 0.0f);
canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(image->makeColorSpace(spin, nullptr)->reinterpretColorSpace(srgb),
256.0f, 0.0f);
canvas->translate(0.0f, 128.0f);
// GPU images
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
auto direct = GrAsDirectContext(canvas->recordingContext());
if (auto gpuImage = image->makeTextureImage(direct)) {
image = gpuImage;
}
canvas->drawImage(image, 0.0f, 0.0f);
canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
Reland "Add a direct context arg to makeColorTypeAndColorSpace" This reverts commit 779813a2394073f2f00029a7ef89e886d592eba1. Reason for revert: Avoid null dereference in DDL test case Original change's description: > Revert "Add a direct context arg to makeColorTypeAndColorSpace" > > This reverts commit a56da9ee923c5f09ed9b97a83e250400b3c78deb. > > Reason for revert: UBSAN complains in Vulkan OOPRDDL mode > > Original change's description: > > Add a direct context arg to makeColorTypeAndColorSpace > > > > This is part of a larger effort to de-power SkImage and force users to > > specify the GPU context for all new images. > > > > Staging flag landed in Chrome CL 2296632. > > > > Bug: skia:10466 > > Change-Id: I6b7bbec10369f7d8ee884dd1bcc234d332c30a6c > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302290 > > Commit-Queue: Adlai Holler <adlai@google.com> > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Reviewed-by: Robert Phillips <robertphillips@google.com> > > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com > > Change-Id: Ide36bed6966d3d92ad6b8d05f897d22d287b40b1 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10466 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302824 > Reviewed-by: Adlai Holler <adlai@google.com> > Commit-Queue: Adlai Holler <adlai@google.com> Bug: skia:10466 Change-Id: I59de0bd2b33989b1af08e8af2f8a52542b6b5db0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/302829 Commit-Queue: Adlai Holler <adlai@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
2020-07-15 14:37:50 +00:00
canvas->drawImage(image->makeColorSpace(spin, direct)->reinterpretColorSpace(srgb),
256.0f, 0.0f);
return skiagm::DrawResult::kOk;
}