Blender V5.0
COM_cached_image.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"
12
13#include "GPU_texture.hh"
14
15#include "DNA_image_types.h"
16
17#include "RE_pipeline.h"
18
20#include "COM_result.hh"
21
22namespace blender::compositor {
23
24class Context;
25
26/* ------------------------------------------------------------------------------------------------
27 * Cached Image Key.
28 */
30 public:
32 std::string pass_name;
33
35
36 uint64_t hash() const;
37};
38
39bool operator==(const CachedImageKey &a, const CachedImageKey &b);
40
41/* -------------------------------------------------------------------------------------------------
42 * Cached Image.
43 *
44 * A cached resource that computes and caches a result containing the contents of the image with
45 * the given image user. */
47 public:
49
50 private:
51 /* For GPU, the result wraps an external GPU texture that is generated by the IMB module and
52 * stored in this member to be freed when the cached resource is deleted. */
53 blender::gpu::Texture *texture_ = nullptr;
54
55 public:
56 CachedImage(Context &context, Image *image, ImageUser *image_user, const char *pass_name);
57
59
60 private:
61 /* Populates the meta data of the image. */
62 void populate_meta_data(const RenderResult *render_result, const ImageUser &image_user);
63};
64
65/* ------------------------------------------------------------------------------------------------
66 * Cached Image Container.
67 */
69 private:
71
72 /* A map that stores the update counts of the images at the moment they were cached. */
73 Map<std::string, uint64_t> update_counts_;
74
75 public:
76 void reset() override;
77
78 /* Check if the given image has changed since it was cached, and if so, invalidate its cache
79 * entry. Then, check if there is an available CachedImage cached resource with the given image
80 * user and pass_name in the container, if one exists, return it, otherwise, return a newly
81 * created one and add it to the container. In both cases, tag the cached resource as needed to
82 * keep it cached for the next evaluation. */
83 Result get(Context &context, Image *image, const ImageUser *image_user, const char *pass_name);
84};
85
86} // namespace blender::compositor
unsigned long long int uint64_t
Result get(Context &context, Image *image, const ImageUser *image_user, const char *pass_name)
CachedImageKey(ImageUser image_user, std::string pass_name)
CachedImage(Context &context, Image *image, ImageUser *image_user, const char *pass_name)
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)