9 #include <unordered_map>
11 #include "flutter/fml/build_config.h"
12 #include "flutter/fml/hash_combine.h"
13 #include "flutter/fml/logging.h"
14 #include "flutter/fml/macros.h"
24 #include "impeller/entity/checkerboard.frag.h"
25 #include "impeller/entity/checkerboard.vert.h"
26 #endif // IMPELLER_DEBUG
28 #include "impeller/entity/blend.frag.h"
29 #include "impeller/entity/blend.vert.h"
30 #include "impeller/entity/border_mask_blur.frag.h"
31 #include "impeller/entity/border_mask_blur.vert.h"
32 #include "impeller/entity/clip.frag.h"
33 #include "impeller/entity/clip.vert.h"
34 #include "impeller/entity/color_matrix_color_filter.frag.h"
35 #include "impeller/entity/color_matrix_color_filter.vert.h"
36 #include "impeller/entity/conical_gradient_fill.frag.h"
37 #include "impeller/entity/glyph_atlas.frag.h"
38 #include "impeller/entity/glyph_atlas.vert.h"
39 #include "impeller/entity/glyph_atlas_color.frag.h"
40 #include "impeller/entity/gradient_fill.vert.h"
41 #include "impeller/entity/linear_gradient_fill.frag.h"
42 #include "impeller/entity/linear_to_srgb_filter.frag.h"
43 #include "impeller/entity/linear_to_srgb_filter.vert.h"
44 #include "impeller/entity/morphology_filter.frag.h"
45 #include "impeller/entity/morphology_filter.vert.h"
46 #include "impeller/entity/points.comp.h"
47 #include "impeller/entity/porter_duff_blend.frag.h"
48 #include "impeller/entity/porter_duff_blend.vert.h"
49 #include "impeller/entity/radial_gradient_fill.frag.h"
50 #include "impeller/entity/rrect_blur.frag.h"
51 #include "impeller/entity/rrect_blur.vert.h"
52 #include "impeller/entity/solid_fill.frag.h"
53 #include "impeller/entity/solid_fill.vert.h"
54 #include "impeller/entity/srgb_to_linear_filter.frag.h"
55 #include "impeller/entity/srgb_to_linear_filter.vert.h"
56 #include "impeller/entity/sweep_gradient_fill.frag.h"
57 #include "impeller/entity/texture_fill.frag.h"
58 #include "impeller/entity/texture_fill.vert.h"
59 #include "impeller/entity/tiled_texture_fill.frag.h"
60 #include "impeller/entity/uv.comp.h"
61 #include "impeller/entity/vertices.frag.h"
62 #include "impeller/entity/yuv_to_rgb_filter.frag.h"
63 #include "impeller/entity/yuv_to_rgb_filter.vert.h"
65 #include "impeller/entity/gaussian_blur.vert.h"
66 #include "impeller/entity/gaussian_blur_noalpha_decal.frag.h"
67 #include "impeller/entity/gaussian_blur_noalpha_nodecal.frag.h"
69 #include "impeller/entity/position_color.vert.h"
73 #include "impeller/entity/conical_gradient_ssbo_fill.frag.h"
74 #include "impeller/entity/linear_gradient_ssbo_fill.frag.h"
75 #include "impeller/entity/radial_gradient_ssbo_fill.frag.h"
76 #include "impeller/entity/sweep_gradient_ssbo_fill.frag.h"
78 #include "impeller/entity/advanced_blend.vert.h"
79 #include "impeller/entity/advanced_blend_color.frag.h"
80 #include "impeller/entity/advanced_blend_colorburn.frag.h"
81 #include "impeller/entity/advanced_blend_colordodge.frag.h"
82 #include "impeller/entity/advanced_blend_darken.frag.h"
83 #include "impeller/entity/advanced_blend_difference.frag.h"
84 #include "impeller/entity/advanced_blend_exclusion.frag.h"
85 #include "impeller/entity/advanced_blend_hardlight.frag.h"
86 #include "impeller/entity/advanced_blend_hue.frag.h"
87 #include "impeller/entity/advanced_blend_lighten.frag.h"
88 #include "impeller/entity/advanced_blend_luminosity.frag.h"
89 #include "impeller/entity/advanced_blend_multiply.frag.h"
90 #include "impeller/entity/advanced_blend_overlay.frag.h"
91 #include "impeller/entity/advanced_blend_saturation.frag.h"
92 #include "impeller/entity/advanced_blend_screen.frag.h"
93 #include "impeller/entity/advanced_blend_softlight.frag.h"
95 #include "impeller/entity/framebuffer_blend.vert.h"
96 #include "impeller/entity/framebuffer_blend_color.frag.h"
97 #include "impeller/entity/framebuffer_blend_colorburn.frag.h"
98 #include "impeller/entity/framebuffer_blend_colordodge.frag.h"
99 #include "impeller/entity/framebuffer_blend_darken.frag.h"
100 #include "impeller/entity/framebuffer_blend_difference.frag.h"
101 #include "impeller/entity/framebuffer_blend_exclusion.frag.h"
102 #include "impeller/entity/framebuffer_blend_hardlight.frag.h"
103 #include "impeller/entity/framebuffer_blend_hue.frag.h"
104 #include "impeller/entity/framebuffer_blend_lighten.frag.h"
105 #include "impeller/entity/framebuffer_blend_luminosity.frag.h"
106 #include "impeller/entity/framebuffer_blend_multiply.frag.h"
107 #include "impeller/entity/framebuffer_blend_overlay.frag.h"
108 #include "impeller/entity/framebuffer_blend_saturation.frag.h"
109 #include "impeller/entity/framebuffer_blend_screen.frag.h"
110 #include "impeller/entity/framebuffer_blend_softlight.frag.h"
112 #ifdef IMPELLER_ENABLE_OPENGLES
113 #include "impeller/entity/texture_fill_external.frag.h"
114 #endif // IMPELLER_ENABLE_OPENGLES
116 #if IMPELLER_ENABLE_3D
122 #ifdef IMPELLER_DEBUG
123 using CheckerboardPipeline =
124 RenderPipelineT<CheckerboardVertexShader, CheckerboardFragmentShader>;
125 #endif // IMPELLER_DEBUG
135 ConicalGradientFillFragmentShader>;
140 LinearGradientSsboFillFragmentShader>;
143 ConicalGradientSsboFillFragmentShader>;
146 RadialGradientSsboFillFragmentShader>;
149 SweepGradientSsboFillFragmentShader>;
161 GaussianBlurNoalphaDecalFragmentShader>;
164 GaussianBlurNoalphaNodecalFragmentShader>;
169 MorphologyFilterFragmentShader>;
172 ColorMatrixColorFilterFragmentShader>;
175 LinearToSrgbFilterFragmentShader>;
178 SrgbToLinearFilterFragmentShader>;
196 AdvancedBlendColorFragmentShader>;
199 AdvancedBlendColorburnFragmentShader>;
202 AdvancedBlendColordodgeFragmentShader>;
204 AdvancedBlendDarkenFragmentShader>;
207 AdvancedBlendDifferenceFragmentShader>;
210 AdvancedBlendExclusionFragmentShader>;
213 AdvancedBlendHardlightFragmentShader>;
218 AdvancedBlendLightenFragmentShader>;
221 AdvancedBlendLuminosityFragmentShader>;
224 AdvancedBlendMultiplyFragmentShader>;
227 AdvancedBlendOverlayFragmentShader>;
230 AdvancedBlendSaturationFragmentShader>;
232 AdvancedBlendScreenFragmentShader>;
235 AdvancedBlendSoftlightFragmentShader>;
239 FramebufferBlendColorFragmentShader>;
242 FramebufferBlendColorburnFragmentShader>;
245 FramebufferBlendColordodgeFragmentShader>;
248 FramebufferBlendDarkenFragmentShader>;
251 FramebufferBlendDifferenceFragmentShader>;
254 FramebufferBlendExclusionFragmentShader>;
257 FramebufferBlendHardlightFragmentShader>;
260 FramebufferBlendHueFragmentShader>;
263 FramebufferBlendLightenFragmentShader>;
266 FramebufferBlendLuminosityFragmentShader>;
269 FramebufferBlendMultiplyFragmentShader>;
272 FramebufferBlendOverlayFragmentShader>;
275 FramebufferBlendSaturationFragmentShader>;
278 FramebufferBlendScreenFragmentShader>;
281 FramebufferBlendSoftlightFragmentShader>;
287 #ifdef IMPELLER_ENABLE_OPENGLES
288 using TextureExternalPipeline =
290 #endif // IMPELLER_ENABLE_OPENGLES
315 return fml::HashCombine(
342 class RenderTargetCache;
347 std::shared_ptr<Context> context,
348 std::shared_ptr<TypographerContext> typographer_context,
349 std::shared_ptr<RenderTargetAllocator> render_target_allocator =
nullptr);
355 #if IMPELLER_ENABLE_3D
356 std::shared_ptr<scene::SceneContext> GetSceneContext()
const;
357 #endif // IMPELLER_ENABLE_3D
361 #ifdef IMPELLER_DEBUG
362 std::shared_ptr<Pipeline<PipelineDescriptor>> GetCheckerboardPipeline(
364 return GetPipeline(checkerboard_pipelines_, opts);
366 #endif // IMPELLER_DEBUG
370 return GetPipeline(linear_gradient_fill_pipelines_, opts);
373 std::shared_ptr<Pipeline<PipelineDescriptor>>
376 return GetPipeline(linear_gradient_ssbo_fill_pipelines_, opts);
379 std::shared_ptr<Pipeline<PipelineDescriptor>>
382 return GetPipeline(radial_gradient_ssbo_fill_pipelines_, opts);
385 std::shared_ptr<Pipeline<PipelineDescriptor>>
388 return GetPipeline(conical_gradient_ssbo_fill_pipelines_, opts);
391 std::shared_ptr<Pipeline<PipelineDescriptor>>
394 return GetPipeline(sweep_gradient_ssbo_fill_pipelines_, opts);
399 return GetPipeline(radial_gradient_fill_pipelines_, opts);
404 return GetPipeline(conical_gradient_fill_pipelines_, opts);
409 return GetPipeline(rrect_blur_pipelines_, opts);
414 return GetPipeline(sweep_gradient_fill_pipelines_, opts);
419 return GetPipeline(solid_fill_pipelines_, opts);
424 return GetPipeline(texture_blend_pipelines_, opts);
429 return GetPipeline(texture_pipelines_, opts);
432 #ifdef IMPELLER_ENABLE_OPENGLES
433 std::shared_ptr<Pipeline<PipelineDescriptor>> GetTextureExternalPipeline(
437 return GetPipeline(texture_external_pipelines_, opts);
439 #endif // IMPELLER_ENABLE_OPENGLES
443 return GetPipeline(position_uv_pipelines_, opts);
448 return GetPipeline(tiled_texture_pipelines_, opts);
453 return GetPipeline(gaussian_blur_noalpha_decal_pipelines_, opts);
458 return GetPipeline(gaussian_blur_noalpha_nodecal_pipelines_, opts);
463 return GetPipeline(border_mask_blur_pipelines_, opts);
468 return GetPipeline(morphology_filter_pipelines_, opts);
471 std::shared_ptr<Pipeline<PipelineDescriptor>>
473 return GetPipeline(color_matrix_color_filter_pipelines_, opts);
478 return GetPipeline(linear_to_srgb_filter_pipelines_, opts);
483 return GetPipeline(srgb_to_linear_filter_pipelines_, opts);
488 return GetPipeline(clip_pipelines_, opts);
493 return GetPipeline(glyph_atlas_pipelines_, opts);
498 return GetPipeline(glyph_atlas_color_pipelines_, opts);
503 return GetPipeline(geometry_color_pipelines_, opts);
508 return GetPipeline(yuv_to_rgb_filter_pipelines_, opts);
513 return GetPipeline(porter_duff_blend_pipelines_, opts);
520 return GetPipeline(blend_color_pipelines_, opts);
525 return GetPipeline(blend_colorburn_pipelines_, opts);
530 return GetPipeline(blend_colordodge_pipelines_, opts);
535 return GetPipeline(blend_darken_pipelines_, opts);
540 return GetPipeline(blend_difference_pipelines_, opts);
545 return GetPipeline(blend_exclusion_pipelines_, opts);
550 return GetPipeline(blend_hardlight_pipelines_, opts);
555 return GetPipeline(blend_hue_pipelines_, opts);
560 return GetPipeline(blend_lighten_pipelines_, opts);
565 return GetPipeline(blend_luminosity_pipelines_, opts);
570 return GetPipeline(blend_multiply_pipelines_, opts);
575 return GetPipeline(blend_overlay_pipelines_, opts);
580 return GetPipeline(blend_saturation_pipelines_, opts);
585 return GetPipeline(blend_screen_pipelines_, opts);
590 return GetPipeline(blend_softlight_pipelines_, opts);
594 std::shared_ptr<Pipeline<PipelineDescriptor>>
597 return GetPipeline(framebuffer_blend_color_pipelines_, opts);
600 std::shared_ptr<Pipeline<PipelineDescriptor>>
603 return GetPipeline(framebuffer_blend_colorburn_pipelines_, opts);
606 std::shared_ptr<Pipeline<PipelineDescriptor>>
609 return GetPipeline(framebuffer_blend_colordodge_pipelines_, opts);
612 std::shared_ptr<Pipeline<PipelineDescriptor>>
615 return GetPipeline(framebuffer_blend_darken_pipelines_, opts);
618 std::shared_ptr<Pipeline<PipelineDescriptor>>
621 return GetPipeline(framebuffer_blend_difference_pipelines_, opts);
624 std::shared_ptr<Pipeline<PipelineDescriptor>>
627 return GetPipeline(framebuffer_blend_exclusion_pipelines_, opts);
630 std::shared_ptr<Pipeline<PipelineDescriptor>>
633 return GetPipeline(framebuffer_blend_hardlight_pipelines_, opts);
639 return GetPipeline(framebuffer_blend_hue_pipelines_, opts);
642 std::shared_ptr<Pipeline<PipelineDescriptor>>
645 return GetPipeline(framebuffer_blend_lighten_pipelines_, opts);
648 std::shared_ptr<Pipeline<PipelineDescriptor>>
651 return GetPipeline(framebuffer_blend_luminosity_pipelines_, opts);
654 std::shared_ptr<Pipeline<PipelineDescriptor>>
657 return GetPipeline(framebuffer_blend_multiply_pipelines_, opts);
660 std::shared_ptr<Pipeline<PipelineDescriptor>>
663 return GetPipeline(framebuffer_blend_overlay_pipelines_, opts);
666 std::shared_ptr<Pipeline<PipelineDescriptor>>
669 return GetPipeline(framebuffer_blend_saturation_pipelines_, opts);
672 std::shared_ptr<Pipeline<PipelineDescriptor>>
675 return GetPipeline(framebuffer_blend_screen_pipelines_, opts);
678 std::shared_ptr<Pipeline<PipelineDescriptor>>
681 return GetPipeline(framebuffer_blend_softlight_pipelines_, opts);
687 return point_field_compute_pipelines_;
693 return uv_compute_pipelines_;
707 std::shared_ptr<Texture>
MakeSubpass(
const std::string& label,
710 bool msaa_enabled =
true)
const;
713 return lazy_glyph_atlas_;
717 return render_target_cache_;
721 std::shared_ptr<Context> context_;
722 std::shared_ptr<LazyGlyphAtlas> lazy_glyph_atlas_;
734 #ifdef IMPELLER_DEBUG
735 mutable Variants<CheckerboardPipeline> checkerboard_pipelines_;
736 #endif // IMPELLER_DEBUG
738 mutable Variants<SolidFillPipeline> solid_fill_pipelines_;
739 mutable Variants<LinearGradientFillPipeline> linear_gradient_fill_pipelines_;
740 mutable Variants<RadialGradientFillPipeline> radial_gradient_fill_pipelines_;
741 mutable Variants<ConicalGradientFillPipeline>
742 conical_gradient_fill_pipelines_;
743 mutable Variants<SweepGradientFillPipeline> sweep_gradient_fill_pipelines_;
744 mutable Variants<LinearGradientSSBOFillPipeline>
745 linear_gradient_ssbo_fill_pipelines_;
746 mutable Variants<RadialGradientSSBOFillPipeline>
747 radial_gradient_ssbo_fill_pipelines_;
748 mutable Variants<ConicalGradientSSBOFillPipeline>
749 conical_gradient_ssbo_fill_pipelines_;
750 mutable Variants<SweepGradientSSBOFillPipeline>
751 sweep_gradient_ssbo_fill_pipelines_;
752 mutable Variants<RRectBlurPipeline> rrect_blur_pipelines_;
753 mutable Variants<BlendPipeline> texture_blend_pipelines_;
754 mutable Variants<TexturePipeline> texture_pipelines_;
755 #ifdef IMPELLER_ENABLE_OPENGLES
756 mutable Variants<TextureExternalPipeline> texture_external_pipelines_;
757 #endif // IMPELLER_ENABLE_OPENGLES
758 mutable Variants<PositionUVPipeline> position_uv_pipelines_;
759 mutable Variants<TiledTexturePipeline> tiled_texture_pipelines_;
760 mutable Variants<GaussianBlurDecalPipeline>
761 gaussian_blur_noalpha_decal_pipelines_;
762 mutable Variants<GaussianBlurPipeline>
763 gaussian_blur_noalpha_nodecal_pipelines_;
764 mutable Variants<BorderMaskBlurPipeline> border_mask_blur_pipelines_;
765 mutable Variants<MorphologyFilterPipeline> morphology_filter_pipelines_;
766 mutable Variants<ColorMatrixColorFilterPipeline>
767 color_matrix_color_filter_pipelines_;
768 mutable Variants<LinearToSrgbFilterPipeline> linear_to_srgb_filter_pipelines_;
769 mutable Variants<SrgbToLinearFilterPipeline> srgb_to_linear_filter_pipelines_;
770 mutable Variants<ClipPipeline> clip_pipelines_;
771 mutable Variants<GlyphAtlasPipeline> glyph_atlas_pipelines_;
772 mutable Variants<GlyphAtlasColorPipeline> glyph_atlas_color_pipelines_;
773 mutable Variants<GeometryColorPipeline> geometry_color_pipelines_;
774 mutable Variants<YUVToRGBFilterPipeline> yuv_to_rgb_filter_pipelines_;
775 mutable Variants<PorterDuffBlendPipeline> porter_duff_blend_pipelines_;
777 mutable Variants<BlendColorPipeline> blend_color_pipelines_;
778 mutable Variants<BlendColorBurnPipeline> blend_colorburn_pipelines_;
779 mutable Variants<BlendColorDodgePipeline> blend_colordodge_pipelines_;
780 mutable Variants<BlendDarkenPipeline> blend_darken_pipelines_;
781 mutable Variants<BlendDifferencePipeline> blend_difference_pipelines_;
782 mutable Variants<BlendExclusionPipeline> blend_exclusion_pipelines_;
783 mutable Variants<BlendHardLightPipeline> blend_hardlight_pipelines_;
784 mutable Variants<BlendHuePipeline> blend_hue_pipelines_;
785 mutable Variants<BlendLightenPipeline> blend_lighten_pipelines_;
786 mutable Variants<BlendLuminosityPipeline> blend_luminosity_pipelines_;
787 mutable Variants<BlendMultiplyPipeline> blend_multiply_pipelines_;
788 mutable Variants<BlendOverlayPipeline> blend_overlay_pipelines_;
789 mutable Variants<BlendSaturationPipeline> blend_saturation_pipelines_;
790 mutable Variants<BlendScreenPipeline> blend_screen_pipelines_;
791 mutable Variants<BlendSoftLightPipeline> blend_softlight_pipelines_;
793 mutable Variants<FramebufferBlendColorPipeline>
794 framebuffer_blend_color_pipelines_;
795 mutable Variants<FramebufferBlendColorBurnPipeline>
796 framebuffer_blend_colorburn_pipelines_;
797 mutable Variants<FramebufferBlendColorDodgePipeline>
798 framebuffer_blend_colordodge_pipelines_;
799 mutable Variants<FramebufferBlendDarkenPipeline>
800 framebuffer_blend_darken_pipelines_;
801 mutable Variants<FramebufferBlendDifferencePipeline>
802 framebuffer_blend_difference_pipelines_;
803 mutable Variants<FramebufferBlendExclusionPipeline>
804 framebuffer_blend_exclusion_pipelines_;
805 mutable Variants<FramebufferBlendHardLightPipeline>
806 framebuffer_blend_hardlight_pipelines_;
807 mutable Variants<FramebufferBlendHuePipeline>
808 framebuffer_blend_hue_pipelines_;
809 mutable Variants<FramebufferBlendLightenPipeline>
810 framebuffer_blend_lighten_pipelines_;
811 mutable Variants<FramebufferBlendLuminosityPipeline>
812 framebuffer_blend_luminosity_pipelines_;
813 mutable Variants<FramebufferBlendMultiplyPipeline>
814 framebuffer_blend_multiply_pipelines_;
815 mutable Variants<FramebufferBlendOverlayPipeline>
816 framebuffer_blend_overlay_pipelines_;
817 mutable Variants<FramebufferBlendSaturationPipeline>
818 framebuffer_blend_saturation_pipelines_;
819 mutable Variants<FramebufferBlendScreenPipeline>
820 framebuffer_blend_screen_pipelines_;
821 mutable Variants<FramebufferBlendSoftLightPipeline>
822 framebuffer_blend_softlight_pipelines_;
823 mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
824 point_field_compute_pipelines_;
825 mutable std::shared_ptr<Pipeline<ComputePipelineDescriptor>>
826 uv_compute_pipelines_;
834 template <
class TypedPipeline>
835 std::shared_ptr<Pipeline<PipelineDescriptor>> GetPipeline(
836 Variants<TypedPipeline>& container,
846 if (
auto found = container.find(opts); found != container.end()) {
847 return found->second->WaitAndGet();
850 auto prototype = container.find(default_options_);
853 FML_CHECK(prototype != container.end());
855 auto pipeline = prototype->second->WaitAndGet();
860 auto variant_future = pipeline->CreateVariant(
861 [&opts, variants_count = container.size()](PipelineDescriptor& desc) {
862 opts.ApplyToPipelineDescriptor(desc);
864 SPrintF(
"%s V#%zu", desc.GetLabel().c_str(), variants_count));
866 auto variant = std::make_unique<TypedPipeline>(std::move(variant_future));
867 auto variant_pipeline = variant->WaitAndGet();
868 container[opts] = std::move(variant);
869 return variant_pipeline;
872 bool is_valid_ =
false;
873 std::shared_ptr<Tessellator> tessellator_;
874 #if IMPELLER_ENABLE_3D
875 std::shared_ptr<scene::SceneContext> scene_context_;
876 #endif // IMPELLER_ENABLE_3D
877 std::shared_ptr<RenderTargetAllocator> render_target_cache_;
878 bool wireframe_ =
false;