Blender V5.3
COM_cached_mask.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <cstdint>
8#include <memory>
9#include <string>
10
11#include "BLI_map.hh"
13
14#include "DNA_mask_types.h"
15
17#include "COM_result.hh"
18
19namespace blender::compositor {
20
21class Context;
22
23/* ------------------------------------------------------------------------------------------------
24 * Cached Mask Key.
25 */
27 public:
34 int frame;
37
38 CachedMaskKey(const Domain &domain,
39 float aspect_ratio,
40 bool use_feather,
41 bool srgb_to_linear,
42 int frame,
45
46 uint64_t hash() const;
47 friend bool operator==(const CachedMaskKey &a, const CachedMaskKey &b) = default;
48};
49
50/* -------------------------------------------------------------------------------------------------
51 * Cached Mask.
52 *
53 * A cached resource that computes and caches a result containing the result of evaluating the
54 * given mask ID on a space that spans the given size, parameterized by the given parameters. */
55class CachedMask : public CachedResource {
56 public:
58
59 CachedMask(Context &context,
60 Mask *mask,
61 const Domain &domain,
62 int frame,
63 float aspect_ratio,
64 bool use_feather,
65 int motion_blur_samples,
66 float motion_blur_shutter,
67 bool srgb_to_linear);
68
70};
71
72/* ------------------------------------------------------------------------------------------------
73 * Cached Mask Container.
74 */
76 private:
78
79 /* A map that stores the update counts of the masks at the moment they were cached. */
80 Map<std::string, uint64_t> update_counts_;
81
82 public:
83 void reset() override;
84
85 /* Check if the given mask ID has changed since the last time it was retrieved through its
86 * recalculate flag, and if so, invalidate its corresponding cached mask and reset the
87 * recalculate flag to ready it to track the next change. Then, check if there is an available
88 * CachedMask cached resource with the given parameters in the container, if one exists, return
89 * it, otherwise, return a newly created one and add it to the container. In both cases, tag the
90 * cached resource as needed to keep it cached for the next evaluation. */
91 Result &get(Context &context,
92 Mask *mask,
93 const Domain &domain,
94 float aspect_ratio,
95 bool use_feather,
96 int frame,
97 int motion_blur_samples,
98 float motion_blur_shutter,
99 bool srgb_to_linear);
100};
101
102} // namespace blender::compositor
Result & get(Context &context, Mask *mask, const Domain &domain, float aspect_ratio, bool use_feather, int frame, int motion_blur_samples, float motion_blur_shutter, bool srgb_to_linear)
friend bool operator==(const CachedMaskKey &a, const CachedMaskKey &b)=default
CachedMaskKey(const Domain &domain, float aspect_ratio, bool use_feather, bool srgb_to_linear, int frame, int motion_blur_samples, float motion_blur_shutter)
CachedMask(Context &context, Mask *mask, const Domain &domain, int frame, float aspect_ratio, bool use_feather, int motion_blur_samples, float motion_blur_shutter, bool srgb_to_linear)
unsigned __int64 uint64_t
Definition BKE_text.h:91