Commit db501e55 authored by Brian Osman's avatar Brian Osman Committed by Commit Bot

Replace SkRuntimeColorFilterFactory with SkRuntimeEffect

This is a refactored (and now public) API to solve the same problem.
SkRuntimeColorFilterFactory was just a shim over SkRuntimeEffect,
and will be deprecated/deleted soon.

Change-Id: I043c82ab38a2ddebfa29680f394c4263973ac42d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1982791Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarBrian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Cr-Commit-Position: refs/heads/master@{#728250}
parent 2fd937b7
......@@ -53,10 +53,10 @@
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/skia/include/effects/SkImageFilters.h"
#include "third_party/skia/include/effects/SkOverdrawColorFilter.h"
#include "third_party/skia/include/effects/SkRuntimeEffect.h"
#include "third_party/skia/include/effects/SkShaderMaskFilter.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/third_party/skcms/skcms.h"
#include "third_party/skia/src/core/SkColorFilterPriv.h"
#include "ui/gfx/color_transform.h"
#include "ui/gfx/geometry/axis_transform2d.h"
#include "ui/gfx/geometry/rect_conversions.h"
......@@ -2151,9 +2151,8 @@ sk_sp<SkColorFilter> SkiaRenderer::GetColorFilter(const gfx::ColorSpace& src,
sdr_white_level / gfx::ColorSpace::kDefaultSDRWhiteLevel);
}
std::unique_ptr<SkRuntimeColorFilterFactory>& factory =
color_filter_cache_[dst][adjusted_src];
if (!factory) {
sk_sp<SkRuntimeEffect>& effect = color_filter_cache_[dst][adjusted_src];
if (!effect) {
std::unique_ptr<gfx::ColorTransform> transform =
gfx::ColorTransform::NewColorTransform(
adjusted_src, dst, gfx::ColorTransform::Intent::INTENT_PERCEPTUAL);
......@@ -2178,8 +2177,9 @@ void main(inout half4 color) {
std::string shader = hdr + transform->GetSkShaderSource() + ftr;
factory.reset(new SkRuntimeColorFilterFactory(
SkString(shader.c_str(), shader.size())));
effect = std::get<0>(
SkRuntimeEffect::Make(SkString(shader.c_str(), shader.size())));
DCHECK(effect);
}
YUVInput input;
......@@ -2187,7 +2187,7 @@ void main(inout half4 color) {
input.multiplier = resource_multiplier;
sk_sp<SkData> data = SkData::MakeWithCopy(&input, sizeof(input));
return factory->make(std::move(data));
return effect->makeColorFilter(std::move(data));
}
SkiaRenderer::DrawRPDQParams SkiaRenderer::CalculateRPDQParams(
......
......@@ -22,7 +22,7 @@
class SkColorFilter;
class SkNWayCanvas;
class SkPictureRecorder;
class SkRuntimeColorFilterFactory;
class SkRuntimeEffect;
namespace gpu {
struct Capabilities;
......@@ -327,9 +327,7 @@ class VIZ_SERVICE_EXPORT SkiaRenderer : public DirectRenderer {
ContextProvider* context_provider_ = nullptr;
base::Optional<SyncQueryCollection> sync_queries_;
std::map<
gfx::ColorSpace,
std::map<gfx::ColorSpace, std::unique_ptr<SkRuntimeColorFilterFactory>>>
std::map<gfx::ColorSpace, std::map<gfx::ColorSpace, sk_sp<SkRuntimeEffect>>>
color_filter_cache_;
DISALLOW_COPY_AND_ASSIGN(SkiaRenderer);
......
......@@ -7,7 +7,7 @@
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/src/core/SkColorFilterPriv.h"
#include "third_party/skia/include/effects/SkRuntimeEffect.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/color_transform.h"
#include "ui/gfx/icc_profile.h"
......@@ -517,9 +517,10 @@ TEST(SimpleColorSpace, CanParseSkShaderSource) {
src, dst, ColorTransform::Intent::INTENT_PERCEPTUAL);
std::string source = "void main(inout half4 color) {" +
transform->GetSkShaderSource() + "}";
SkRuntimeColorFilterFactory factory(
SkString(source.c_str(), source.length()), nullptr);
EXPECT_TRUE(factory.testCompile());
auto result =
SkRuntimeEffect::Make(SkString(source.c_str(), source.length()));
EXPECT_NE(std::get<0>(result), nullptr);
EXPECT_TRUE(std::get<1>(result).isEmpty()) << std::get<1>(result).c_str();
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment