|
7 | 7 |
|
8 | 8 | #include "flutter/lib/ui/painting/fragment_shader.h"
|
9 | 9 |
|
| 10 | +#include "flutter/display_list/display_list_color_source.h" |
| 11 | +#include "flutter/display_list/display_list_tile_mode.h" |
10 | 12 | #include "flutter/lib/ui/dart_wrapper.h"
|
11 | 13 | #include "flutter/lib/ui/painting/fragment_program.h"
|
12 | 14 | #include "flutter/lib/ui/ui_dart_state.h"
|
@@ -61,6 +63,27 @@ bool ReusableFragmentShader::ValidateSamplers() {
|
61 | 63 | return true;
|
62 | 64 | }
|
63 | 65 |
|
| 66 | +void ReusableFragmentShader::SetImageSampler(Dart_Handle index_handle, |
| 67 | + Dart_Handle image_handle) { |
| 68 | + uint64_t index = tonic::DartConverter<uint64_t>::FromDart(index_handle); |
| 69 | + CanvasImage* image = |
| 70 | + tonic::DartConverter<CanvasImage*>::FromDart(image_handle); |
| 71 | + if (index >= samplers_.size()) { |
| 72 | + Dart_ThrowException(tonic::ToDart("Sampler index out of bounds")); |
| 73 | + } |
| 74 | + |
| 75 | + // TODO(115794): Once the DlImageSampling enum is replaced, expose the |
| 76 | + // sampling options as a new default parameter for users. |
| 77 | + samplers_[index] = std::make_shared<DlImageColorSource>( |
| 78 | + image->image(), DlTileMode::kClamp, DlTileMode::kClamp, |
| 79 | + DlImageSampling::kNearestNeighbor, nullptr); |
| 80 | + |
| 81 | + auto* uniform_floats = |
| 82 | + reinterpret_cast<float*>(uniform_data_->writable_data()); |
| 83 | + uniform_floats[float_count_ + 2 * index] = image->width(); |
| 84 | + uniform_floats[float_count_ + 2 * index + 1] = image->height(); |
| 85 | +} |
| 86 | + |
64 | 87 | void ReusableFragmentShader::SetSampler(Dart_Handle index_handle,
|
65 | 88 | Dart_Handle sampler_handle) {
|
66 | 89 | uint64_t index = tonic::DartConverter<uint64_t>::FromDart(index_handle);
|
|
0 commit comments