Blender  V3.3
image_partial_updater.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation. */
3 
8 #pragma once
9 
10 #include "BKE_image.h"
12 
14  struct PartialUpdateUser *user;
15  const struct Image *image;
16 
20  void ensure_image(const Image *new_image)
21  {
22  if (!is_valid(new_image)) {
23  free();
24  create(new_image);
25  }
26  }
27 
29  {
30  free();
31  }
32 
33  private:
39  bool is_valid(const Image *new_image) const
40  {
41  if (image != new_image) {
42  return false;
43  }
44 
45  return user != nullptr;
46  }
47 
48  void create(const Image *new_image)
49  {
50  BLI_assert(user == nullptr);
52  image = new_image;
53  }
54 
55  void free()
56  {
57  if (user != nullptr) {
59  user = nullptr;
60  image = nullptr;
61  }
62  }
63 };
struct PartialUpdateUser * BKE_image_partial_update_create(const struct Image *image)
Create a new PartialUpdateUser. An Object that contains data to use partial updates.
void BKE_image_partial_update_free(struct PartialUpdateUser *user)
free a partial update user.
#define BLI_assert(a)
Definition: BLI_assert.h:46
bool is_valid
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.
struct PartialUpdateUser * user
const struct Image * image
void ensure_image(const Image *new_image)
Ensure that there is a partial update user for the given image.