Flutter Engine
 
Loading...
Searching...
No Matches
image_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
7
15
16using tonic::ToDart;
17
18namespace flutter {
19
21
22void ImageShader::Create(Dart_Handle wrapper) {
23 auto res = fml::MakeRefCounted<ImageShader>();
24 res->AssociateWithDartWrapper(wrapper);
25}
26
28 DlTileMode tmx,
29 DlTileMode tmy,
30 int filter_quality_index,
31 Dart_Handle matrix_handle) {
32 // CanvasImage should have already checked for a UI thread safe image.
33 if (!image || !image->image()->isUIThreadSafe()) {
34 return ToDart("ImageShader constructor called with non-genuine Image.");
35 }
36
37 image_ = image->image();
38 tonic::Float64List matrix4(matrix_handle);
39 DlMatrix local_matrix = ToDlMatrix(matrix4);
40 matrix4.Release();
41 sampling_is_locked_ = filter_quality_index >= 0;
42 DlImageSampling sampling =
43 sampling_is_locked_ ? ImageFilter::SamplingFromIndex(filter_quality_index)
45 cached_shader_ =
46 DlColorSource::MakeImage(image_, tmx, tmy, sampling, &local_matrix);
47 FML_DCHECK(cached_shader_->isUIThreadSafe());
48 return Dart_Null();
49}
50
51std::shared_ptr<DlColorSource> ImageShader::shader(DlImageSampling sampling) {
52 const DlImageColorSource* image_shader = cached_shader_->asImage();
53 FML_DCHECK(image_shader);
54 if (sampling_is_locked_ || sampling == image_shader->sampling()) {
55 return cached_shader_;
56 }
57 return image_shader->WithSampling(sampling);
58}
59
61 return image_->width();
62}
63
65 return image_->height();
66}
67
69 cached_shader_.reset();
70 image_.reset();
72}
73
74ImageShader::ImageShader() = default;
75
77
78} // namespace flutter
static std::shared_ptr< DlColorSource > MakeImage(const sk_sp< const DlImage > &image, DlTileMode horizontal_tile_mode, DlTileMode vertical_tile_mode, DlImageSampling sampling=DlImageSampling::kLinear, const DlMatrix *matrix=nullptr)
DlImageSampling sampling() const
std::shared_ptr< DlColorSource > WithSampling(DlImageSampling sampling) const
static DlImageSampling SamplingFromIndex(int filterQualityIndex)
std::shared_ptr< DlColorSource > shader(DlImageSampling) override
~ImageShader() override
Dart_Handle initWithImage(CanvasImage *image, DlTileMode tmx, DlTileMode tmy, int filter_quality_index, Dart_Handle matrix_handle)
static void Create(Dart_Handle wrapper)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
FlutterVulkanImage * image
#define FML_DCHECK(condition)
Definition logging.h:122
DlMatrix ToDlMatrix(const SkMatrix &matrix)
Dart_Handle ToDart(const T &object)
FlutterVulkanImageHandle image
Definition embedder.h:931
A 4x4 matrix using column-major storage.
Definition matrix.h:37