Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
scene_shader.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/lib/ui/painting/scene/scene_shader.h"
6
7#include <memory>
8#include <utility>
9
10#include "flutter/display_list/dl_tile_mode.h"
11#include "flutter/display_list/effects/dl_color_source.h"
12#include "flutter/lib/ui/dart_wrapper.h"
13#include "flutter/lib/ui/painting/scene/scene_node.h"
14#include "flutter/lib/ui/ui_dart_state.h"
17
23
24namespace flutter {
25
27
28SceneShader::SceneShader(fml::RefPtr<SceneNode> scene_node)
29 : scene_node_(std::move(scene_node)) {}
30
31void SceneShader::Create(Dart_Handle wrapper, Dart_Handle scene_node_handle) {
32 auto* scene_node =
34 if (!scene_node) {
35 return;
36 }
37
38 auto res = fml::MakeRefCounted<SceneShader>(fml::Ref(scene_node));
39 res->AssociateWithDartWrapper(wrapper);
40}
41
42void SceneShader::SetCameraTransform(const tonic::Float64List& matrix4) {
43 camera_transform_ =
44 impeller::Matrix(static_cast<impeller::Scalar>(matrix4[0]),
45 static_cast<impeller::Scalar>(matrix4[1]),
46 static_cast<impeller::Scalar>(matrix4[2]),
47 static_cast<impeller::Scalar>(matrix4[3]),
48 static_cast<impeller::Scalar>(matrix4[4]),
49 static_cast<impeller::Scalar>(matrix4[5]),
50 static_cast<impeller::Scalar>(matrix4[6]),
51 static_cast<impeller::Scalar>(matrix4[7]),
52 static_cast<impeller::Scalar>(matrix4[8]),
53 static_cast<impeller::Scalar>(matrix4[9]),
54 static_cast<impeller::Scalar>(matrix4[10]),
55 static_cast<impeller::Scalar>(matrix4[11]),
56 static_cast<impeller::Scalar>(matrix4[12]),
57 static_cast<impeller::Scalar>(matrix4[13]),
58 static_cast<impeller::Scalar>(matrix4[14]),
59 static_cast<impeller::Scalar>(matrix4[15]));
60}
61
63 // TODO(bdero): There's no way to know what the draw area will be yet, so
64 // make the DlSceneColorSource camera transform optional and
65 // defer this default (or parameterize the camera instead).
67 impeller::Degrees(45), impeller::ISize{800, 600}, 0.1f, 1000) *
68 impeller::Matrix::MakeLookAt({0, 0, -5}, {0, 0, 0}, {0, 1, 0});
69}
70
71std::shared_ptr<DlColorSource> SceneShader::shader(DlImageSampling sampling) {
72 FML_CHECK(scene_node_);
73
74 if (!scene_node_->node_) {
75 return nullptr;
76 }
77
78 // TODO(bdero): Gather the mutation log and include it in the scene color
79 // source.
80
81 auto source = std::make_shared<DlSceneColorSource>(
82 scene_node_->node_, camera_transform_.IsIdentity()
84 : camera_transform_);
85 // Just a sanity check, all scene shaders should be thread-safe
86 FML_DCHECK(source->isUIThreadSafe());
87 return source;
88}
89
90void SceneShader::Dispose() {
91 scene_node_ = nullptr;
92 ClearDartWrapper();
93}
94
95SceneShader::~SceneShader() = default;
96
97} // namespace flutter
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
SkBitmap source
Definition examples.cpp:28
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
static impeller::Matrix DefaultCameraTransform()
RefPtr< T > Ref(T *ptr)
Definition ref_ptr.h:237
float Scalar
Definition scalar.h:18
Definition ref_ptr.h:256
A 4x4 matrix using column-major storage.
Definition matrix.h:37
static constexpr Matrix MakePerspective(Radians fov_y, Scalar aspect_ratio, Scalar z_near, Scalar z_far)
Definition matrix.h:504
static constexpr Matrix MakeLookAt(Vector3 position, Vector3 target, Vector3 up)
Definition matrix.h:530