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