1 /* 2 * Copyright 2020 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "modules/svg/include/SkSVGFeFlood.h" 9 10 #include "include/core/SkScalar.h" 11 #include "include/core/SkShader.h" 12 #include "include/effects/SkImageFilters.h" 13 #include "include/private/base/SkDebug.h" 14 #include "modules/svg/include/SkSVGRenderContext.h" 15 16 class SkImageFilter; 17 class SkSVGFilterContext; 18 resolveFloodColor(const SkSVGRenderContext & ctx) const19SkColor SkSVGFeFlood::resolveFloodColor(const SkSVGRenderContext& ctx) const { 20 const auto floodColor = this->getFloodColor(); 21 const auto floodOpacity = this->getFloodOpacity(); 22 // Uninherited presentation attributes should have a concrete value by now. 23 if (!floodColor.isValue() || !floodOpacity.isValue()) { 24 SkDEBUGF("unhandled: flood-color or flood-opacity has no value\n"); 25 return SK_ColorBLACK; 26 } 27 28 const SkColor color = ctx.resolveSvgColor(*floodColor); 29 return SkColorSetA(color, SkScalarRoundToInt(*floodOpacity * 255)); 30 } 31 onMakeImageFilter(const SkSVGRenderContext & ctx,const SkSVGFilterContext & fctx) const32sk_sp<SkImageFilter> SkSVGFeFlood::onMakeImageFilter(const SkSVGRenderContext& ctx, 33 const SkSVGFilterContext& fctx) const { 34 return SkImageFilters::Shader(SkShaders::Color(resolveFloodColor(ctx)), 35 this->resolveFilterSubregion(ctx, fctx)); 36 } 37