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
8#include "modules/skottie/src/SkottiePriv.h"
9
10#include "include/utils/SkParse.h"
11#include "modules/skottie/src/SkottieJson.h"
12#include "modules/sksg/include/SkSGDraw.h"
13#include "modules/sksg/include/SkSGPaint.h"
14#include "modules/sksg/include/SkSGRect.h"
15#include "modules/sksg/include/SkSGRenderNode.h"
16
17namespace skottie {
18namespace internal {
19
20sk_sp<sksg::RenderNode> AnimationBuilder::attachSolidLayer(const skjson::ObjectValue& jlayer,
21 LayerInfo* layer_info) const {
22 layer_info->fSize = SkSize::Make(ParseDefault<float>(jlayer["sw"], 0.0f),
23 ParseDefault<float>(jlayer["sh"], 0.0f));
24 const skjson::StringValue* hex_str = jlayer["sc"];
25 uint32_t c;
26 if (layer_info->fSize.isEmpty() ||
27 !hex_str ||
28 *hex_str->begin() != '#' ||
29 !SkParse::FindHex(hex_str->begin() + 1, &c)) {
30 this->log(Logger::Level::kError, &jlayer, "Could not parse solid layer.");
31 return nullptr;
32 }
33
34 const SkColor color = 0xff000000 | c;
35
36 auto solid_paint = sksg::Color::Make(color);
37 solid_paint->setAntiAlias(true);
38
39 this->dispatchColorProperty(solid_paint);
40
41 return sksg::Draw::Make(sksg::Rect::Make(SkRect::MakeSize(layer_info->fSize)),
42 std::move(solid_paint));
43}
44
45} // namespace internal
46} // namespace skottie
47