Debian Codegraph @

modules/skottie/src/layers/SolidLayer.cpp

raw
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 "include/core/SkColor.h"
9 #include "include/core/SkRect.h"
10 #include "include/core/SkRefCnt.h"
11 #include "include/core/SkSize.h"
12 #include "include/utils/SkParse.h"
13 #include "modules/jsonreader/SkJSONReader.h"
14 #include "modules/skottie/include/Skottie.h"
15 #include "modules/skottie/src/SkottieJson.h"
16 #include "modules/skottie/src/SkottiePriv.h"
17 #include "modules/sksg/include/SkSGDraw.h"
18 #include "modules/sksg/include/SkSGGeometryNode.h"
19 #include "modules/sksg/include/SkSGPaint.h"
20 #include "modules/sksg/include/SkSGRect.h"
21 #include "modules/sksg/include/SkSGRenderNode.h"
22
23 #include <cstdint>
24 #include <utility>
25
26 namespace skottie {
27 namespace internal {
28
29 sk_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