Blender V4.5
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:
31 const int layer_index;
32 const std::string pass_name;
33 const std::string view_name;
34 const int frame;
35
37 const std::string pass_name,
38 const std::string view_name,
39 const int frame);
40
41 uint64_t hash() const;
42};
43
44bool operator==(const CachedImageKey &a, const CachedImageKey &b);
45
46/* -------------------------------------------------------------------------------------------------
47 * Cached Image.
48 *
49 * A cached resource that computes and caches a result containing the contents of the image with
50 * the given image user. */
52 public:
54
55 private:
56 /* For GPU, the result wraps an external GPU texture that is generated by the IMB module and
57 * stored in this member to be freed when the cached resource is deleted. */
58 GPUTexture *texture_ = nullptr;
59
60 public:
61 CachedImage(Context &context, Image *image, ImageUser *image_user, const char *pass_name);
62
64
65 private:
66 /* Populates the meta data of the image. */
67 void populate_meta_data(const RenderResult *render_result, const ImageUser &image_user);
68};
69
70/* ------------------------------------------------------------------------------------------------
71 * Cached Image Container.
72 */
74 private:
76
77 /* A map that stores the update counts of the images at the moment they were cached. */
78 Map<std::string, uint64_t> update_counts_;
79
80 public:
81 void reset() override;
82
83 /* Check if the given image has changed since it was cached, and if so, invalidate its cache
84 * entry. Then, check if there is an available CachedImage cached resource with the given image
85 * user and pass_name in the container, if one exists, return it, otherwise, return a newly
86 * created one and add it to the container. In both cases, tag the cached resource as needed to
87 * keep it cached for the next evaluation. */
88 Result get(Context &context, Image *image, const ImageUser *image_user, const char *pass_name);
89};
90
91} // namespace blender::compositor
unsigned long long int uint64_t
Result get(Context &context, Image *image, const ImageUser *image_user, const char *pass_name)
CachedImageKey(const int layer_index, const std::string pass_name, const std::string view_name, const int frame)
CachedImage(Context &context, Image *image, ImageUser *image_user, const char *pass_name)
bool operator==(const BokehKernelKey &a, const BokehKernelKey &b)