forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
contents.h
107 lines (82 loc) · 3.61 KB
/
contents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <functional>
#include <memory>
#include <vector>
#include "flutter/fml/macros.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/rect.h"
#include "impeller/renderer/sampler_descriptor.h"
#include "impeller/renderer/snapshot.h"
#include "impeller/renderer/texture.h"
namespace impeller {
class ContentContext;
struct ContentContextOptions;
class Entity;
class Surface;
class RenderPass;
ContentContextOptions OptionsFromPass(const RenderPass& pass);
ContentContextOptions OptionsFromPassAndEntity(const RenderPass& pass,
const Entity& entity);
class Contents {
public:
Contents();
virtual ~Contents();
struct StencilCoverage {
enum class Type { kNone, kAppend, kRestore };
Type type = Type::kNone;
std::optional<Rect> coverage = std::nullopt;
};
/// @brief Create an entity that renders a given snapshot.
static std::optional<Entity> EntityFromSnapshot(
const std::optional<Snapshot>& snapshot,
BlendMode blend_mode = BlendMode::kSourceOver,
uint32_t stencil_depth = 0);
virtual bool Render(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) const = 0;
/// @brief Get the screen space bounding rectangle that this contents affects.
virtual std::optional<Rect> GetCoverage(const Entity& entity) const = 0;
/// @brief Given the current screen space bounding rectangle of the stencil,
/// return the expected stencil coverage after this draw call. This
/// should only be implemented for contents that may write to the
/// stencil buffer.
virtual StencilCoverage GetStencilCoverage(
const Entity& entity,
const std::optional<Rect>& current_stencil_coverage) const;
/// @brief Render this contents to a snapshot, respecting the entity's
/// transform, path, stencil depth, and blend mode.
/// The result texture size is always the size of
/// `GetCoverage(entity)`.
virtual std::optional<Snapshot> RenderToSnapshot(
const ContentContext& renderer,
const Entity& entity,
const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
bool msaa_enabled = true) const;
virtual bool ShouldRender(const Entity& entity,
const std::optional<Rect>& stencil_coverage) const;
/// @brief Return the color source's intrinsic size, if available.
///
/// For example, a gradient has a size based on its end and beginning points,
/// ignoring any tiling. Solid colors and runtime effects have no size.
std::optional<Size> ColorSourceSize() const { return color_source_size_; }
void SetColorSourceSize(Size size) { color_source_size_ = size; }
/// @brief Whether or not this contents can accept the opacity peephole
/// optimization.
///
/// By default all contents return false. Contents are responsible
/// for determining whether or not their own geometries intersect in
/// a way that makes accepting opacity impossible. It is always safe
/// to return false, especially if computing overlap would be
/// computationally expensive.
virtual bool CanAcceptOpacity(const Entity& entity) const;
/// @brief Inherit the provided opacity.
virtual void InheritOpacity(Scalar opacity);
protected:
private:
std::optional<Size> color_source_size_;
FML_DISALLOW_COPY_AND_ASSIGN(Contents);
};
} // namespace impeller