Flutter Engine
The Flutter Engine
SolidLayer.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 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
11#include "include/core/SkSize.h"
21#include "src/utils/SkJSON.h"
22
23#include <cstdint>
24#include <utility>
25
26namespace skottie {
27namespace internal {
28
29sk_sp<sksg::RenderNode> AnimationBuilder::attachSolidLayer(const skjson::ObjectValue& jlayer,
30 LayerInfo* layer_info) const {
31 layer_info->fSize = SkSize::Make(ParseDefault<float>(jlayer["sw"], 0.0f),
32 ParseDefault<float>(jlayer["sh"], 0.0f));
33 const skjson::StringValue* hex_str = jlayer["sc"];
34 uint32_t c;
35 if (layer_info->fSize.isEmpty() ||
36 !hex_str ||
37 *hex_str->begin() != '#' ||
38 !SkParse::FindHex(hex_str->begin() + 1, &c)) {
39 this->log(Logger::Level::kError, &jlayer, "Could not parse solid layer.");
40 return nullptr;
41 }
42
43 const SkColor color = 0xff000000 | c;
44
45 auto solid_paint = sksg::Color::Make(color);
46 solid_paint->setAntiAlias(true);
47 this->dispatchColorProperty(solid_paint);
48
49 return sksg::Draw::Make(sksg::Rect::Make(SkRect::MakeSize(layer_info->fSize)),
50 std::move(solid_paint));
51}
52
53} // namespace internal
54} // namespace skottie
uint32_t SkColor
Definition: SkColor.h:37
static const char * FindHex(const char str[], uint32_t *value)
Definition: SkParse.cpp:114
const char * begin() const
Definition: SkJSON.h:315
bool dispatchColorProperty(const sk_sp< sksg::Color > &) const
Definition: Skottie.cpp:228
void log(Logger::Level, const skjson::Value *, const char fmt[],...) const SK_PRINTF_LIKE(4
Definition: Skottie.cpp:71
static sk_sp< Color > Make(SkColor c)
Definition: SkSGPaint.cpp:44
static sk_sp< Draw > Make(sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
Definition: SkSGDraw.h:35
static sk_sp< Rect > Make()
Definition: SkSGRect.h:36
DlColor color
static constexpr SkRect MakeSize(const SkSize &size)
Definition: SkRect.h:633
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56