Tyler Denniston | 8ed0443 | 2020-12-10 15:51:04 -0500 | [diff] [blame] | 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 "include/effects/SkImageFilters.h" |
| 9 | #include "modules/svg/include/SkSVGFeFlood.h" |
| 10 | #include "modules/svg/include/SkSVGFilterContext.h" |
| 11 | #include "modules/svg/include/SkSVGRenderContext.h" |
| 12 | #include "modules/svg/include/SkSVGValue.h" |
| 13 | |
| 14 | SkColor SkSVGFeFlood::resolveFloodColor(const SkSVGRenderContext& ctx) const { |
| 15 | const auto floodColor = this->getFloodColor(); |
| 16 | const auto floodOpacity = this->getFloodOpacity(); |
| 17 | // Uninherited presentation attributes should have a concrete value by now. |
| 18 | if (!floodColor.isValue() || !floodOpacity.isValue()) { |
| 19 | SkDebugf("unhandled: flood-color or flood-opacity has no value\n"); |
| 20 | return SK_ColorBLACK; |
| 21 | } |
| 22 | |
| 23 | SkColor color; |
| 24 | switch (floodColor->type()) { |
| 25 | case SkSVGColor::Type::kColor: |
| 26 | color = floodColor->color(); |
| 27 | break; |
| 28 | case SkSVGColor::Type::kCurrentColor: |
| 29 | color = *ctx.presentationContext().fInherited.fColor; |
| 30 | break; |
| 31 | case SkSVGColor::Type::kICCColor: |
| 32 | SkDebugf("unimplemented 'icccolor' flood-color type\n"); |
| 33 | color = SK_ColorBLACK; |
| 34 | break; |
| 35 | } |
| 36 | return SkColorSetA(color, SkScalarRoundToInt(*floodOpacity * 255)); |
| 37 | } |
| 38 | |
| 39 | sk_sp<SkImageFilter> SkSVGFeFlood::onMakeImageFilter(const SkSVGRenderContext& ctx, |
| 40 | const SkSVGFilterContext& fctx) const { |
| 41 | return SkImageFilters::Shader(SkShaders::Color(resolveFloodColor(ctx)), |
| 42 | fctx.filterEffectsRegion()); |
| 43 | } |