Flutter Engine
The 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
5#include "flutter/lib/ui/painting/image_shader.h"
6#include "flutter/lib/ui/painting/image_filter.h"
7
8#include "flutter/lib/ui/painting/display_list_image_gpu.h"
9#include "flutter/lib/ui/ui_dart_state.h"
14
15using tonic::ToDart;
16
17namespace flutter {
18
20
22 auto res = fml::MakeRefCounted<ImageShader>();
23 res->AssociateWithDartWrapper(wrapper);
24}
25
29 int filter_quality_index,
30 Dart_Handle matrix_handle) {
31 // CanvasImage should have already checked for a UI thread safe image.
32 if (!image || !image->image()->isUIThreadSafe()) {
33 return ToDart("ImageShader constructor called with non-genuine Image.");
34 }
35
36 image_ = image->image();
37 tonic::Float64List matrix4(matrix_handle);
38 SkMatrix local_matrix = ToSkMatrix(matrix4);
39 matrix4.Release();
40 sampling_is_locked_ = filter_quality_index >= 0;
41 DlImageSampling sampling =
42 sampling_is_locked_ ? ImageFilter::SamplingFromIndex(filter_quality_index)
44 cached_shader_ = std::make_shared<DlImageColorSource>(
45 image_, tmx, tmy, sampling, &local_matrix);
46 FML_DCHECK(cached_shader_->isUIThreadSafe());
47 return Dart_Null();
48}
49
50std::shared_ptr<DlColorSource> ImageShader::shader(DlImageSampling sampling) {
51 if (sampling_is_locked_ || sampling == cached_shader_->sampling()) {
52 return cached_shader_;
53 }
54 return cached_shader_->with_sampling(sampling);
55}
56
58 return image_->width();
59}
60
62 return image_->height();
63}
64
66 cached_shader_.reset();
67 image_.reset();
69}
70
71ImageShader::ImageShader() = default;
72
74
75} // namespace flutter
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)
struct _Dart_Handle * Dart_Handle
Definition dart_api.h:258
DART_EXPORT Dart_Handle Dart_Null(void)
#define IMPLEMENT_WRAPPERTYPEINFO(LibraryName, ClassName)
sk_sp< SkImage > image
Definition examples.cpp:29
#define FML_DCHECK(condition)
Definition logging.h:103
SkMatrix ToSkMatrix(const tonic::Float64List &matrix4)
Definition matrix.cc:32
Dart_Handle ToDart(const T &object)
SkTileMode tmy
SkTileMode tmx