Flutter Engine
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/ui_dart_state.h"
13 
14 using tonic::ToDart;
15 
16 namespace flutter {
17 
18 static void ImageShader_constructor(Dart_NativeArguments args) {
20 }
21 
23 
24 #define FOR_EACH_BINDING(V) V(ImageShader, initWithImage)
25 
27 
28 void ImageShader::RegisterNatives(tonic::DartLibraryNatives* natives) {
29  natives->Register(
30  {{"ImageShader_constructor", ImageShader_constructor, 1, true},
32 }
33 
35  return fml::MakeRefCounted<ImageShader>();
36 }
37 
39  SkTileMode tmx,
40  SkTileMode tmy,
41  int filter_quality_index,
42  const tonic::Float64List& matrix4) {
43  if (!image) {
44  Dart_ThrowException(
45  ToDart("ImageShader constructor called with non-genuine Image."));
46  return;
47  }
48  sk_image_ = UIDartState::CreateGPUObject(image->image());
49  tmx_ = tmx;
50  tmy_ = tmy;
51  local_matrix_ = ToSkMatrix(matrix4);
52  if (filter_quality_index >= 0) {
53  cached_sampling_ = ImageFilter::SamplingFromIndex(filter_quality_index);
54  sampling_is_locked_ = true;
55  } else {
56  sampling_is_locked_ = false;
57  }
58 }
59 
60 sk_sp<SkShader> ImageShader::shader(SkSamplingOptions sampling) {
61  if (sampling_is_locked_) {
62  sampling = cached_sampling_;
63  }
64  if (!cached_shader_.skia_object() || cached_sampling_ != sampling) {
65  cached_sampling_ = sampling;
66  cached_shader_ =
67  UIDartState::CreateGPUObject(sk_image_.skia_object()->makeShader(
68  tmx_, tmy_, sampling, &local_matrix_));
69  }
70  return cached_shader_.skia_object();
71 }
72 
73 ImageShader::ImageShader() = default;
74 
75 ImageShader::~ImageShader() = default;
76 
77 } // namespace flutter
G_BEGIN_DECLS FlValue * args
~ImageShader() override
static void ImageShader_constructor(Dart_NativeArguments args)
Definition: image_shader.cc:18
void DartCallConstructor(Sig func, Dart_NativeArguments args)
Definition: dart_args.h:218
#define DART_NATIVE_CALLBACK(CLASS, METHOD)
IMPLEMENT_WRAPPERTYPEINFO(ui, Scene)
sk_sp< SkShader > shader(SkSamplingOptions) override
Definition: image_shader.cc:60
sk_sp< SkiaObjectType > skia_object() const
void initWithImage(CanvasImage *image, SkTileMode tmx, SkTileMode tmy, int filter_quality_index, const tonic::Float64List &matrix4)
Definition: image_shader.cc:38
static SkSamplingOptions SamplingFromIndex(int filterQualityIndex)
Definition: image_filter.cc:50
static fml::RefPtr< ImageShader > Create()
Definition: image_shader.cc:34
#define DART_REGISTER_NATIVE(CLASS, METHOD)
Dart_Handle ToDart(const T &object)
SkMatrix ToSkMatrix(const tonic::Float64List &matrix4)
Definition: matrix.cc:20
static flutter::SkiaGPUObject< T > CreateGPUObject(sk_sp< T > object)
sk_sp< SkImage > image() const
Definition: image.h:37
#define FOR_EACH_BINDING(V)
Definition: image_shader.cc:24