Blender V4.3
image_partial_update.cc File Reference
#include <optional>
#include "BKE_image.hh"
#include "BKE_image_partial_update.hh"
#include "DNA_image_types.h"
#include "IMB_imbuf_types.hh"
#include "BLI_bit_vector.hh"
#include "BLI_listbase.h"
#include "BLI_vector.hh"

Go to the source code of this file.

Classes

struct  blender::bke::image::partial_update::PartialUpdateUserImpl
 
struct  blender::bke::image::partial_update::TileChangeset
 Dirty chunks of an ImageTile. More...
 
struct  blender::bke::image::partial_update::Changeset
 Changeset keeping track of changes for an image. More...
 
struct  blender::bke::image::partial_update::PartialUpdateRegisterImpl
 Partial update changes stored inside the image runtime. More...
 

Namespaces

namespace  blender
 
namespace  blender::bke
 
namespace  blender::bke::image
 
namespace  blender::bke::image::partial_update
 

Typedefs

using blender::bke::image::partial_update::ChangesetID = int64_t
 

Functions

static int blender::bke::image::partial_update::chunk_number_for_pixel (int pixel_offset)
 get the chunk number for the give pixel coordinate.
 
static PartialUpdateUser * blender::bke::image::partial_update::wrap (PartialUpdateUserImpl *user)
 
static PartialUpdateUserImplblender::bke::image::partial_update::unwrap (PartialUpdateUser *user)
 
static PartialUpdateRegister * blender::bke::image::partial_update::wrap (PartialUpdateRegisterImpl *partial_update_register)
 
static PartialUpdateRegisterImplblender::bke::image::partial_update::unwrap (PartialUpdateRegister *partial_update_register)
 
static PartialUpdateRegister * blender::bke::image::partial_update::image_partial_update_register_ensure (Image *image)
 
ePartialUpdateCollectResult blender::bke::image::partial_update::BKE_image_partial_update_collect_changes (Image *image, PartialUpdateUser *user)
 collect the partial update since the last request.
 
ePartialUpdateIterResult blender::bke::image::partial_update::BKE_image_partial_update_get_next_change (PartialUpdateUser *user, PartialUpdateRegion *r_region)
 
PartialUpdateUser * BKE_image_partial_update_create (const Image *image)
 Create a new PartialUpdateUser. An Object that contains data to use partial updates.
 
void BKE_image_partial_update_free (PartialUpdateUser *user)
 free a partial update user.
 
void BKE_image_partial_update_register_free (Image *image)
 
void BKE_image_partial_update_mark_region (Image *image, const ImageTile *image_tile, const ImBuf *image_buffer, const rcti *updated_region)
 Mark a region of the image to update.
 
void BKE_image_partial_update_mark_full_update (Image *image)
 Mark the whole image to be updated.
 

Variables

constexpr int blender::bke::image::partial_update::CHUNK_SIZE = 256
 Size of chunks to track changes.
 
constexpr int blender::bke::image::partial_update::MAX_HISTORY_LEN = 4
 Max number of changesets to keep in history.
 
constexpr ChangesetID blender::bke::image::partial_update::UnknownChangesetID = -1
 

Detailed Description

To reduce the overhead of image processing this file contains a mechanism to detect areas of the image that are changed. These areas are organized in chunks. Changes that happen over time are organized in changesets.

A common use case is to update #GPUTexture for drawing where only that part is uploaded that only changed.

Usage:

Image *image = ...;
ImBuf *image_buffer = ...;
// Partial_update_user should be kept for the whole session where the changes needs to be
// tracked. Keep this instance alive as long as you need to track image changes.
PartialUpdateUser *partial_update_user = BKE_image_partial_update_create(image);
...
switch (BKE_image_partial_update_collect_changes(image, image_buffer))
{
case ePartialUpdateCollectResult::FullUpdateNeeded:
// Unable to do partial updates. Perform a full update.
break;
case ePartialUpdateCollectResult::PartialChangesDetected:
PartialUpdateRegion change;
while (BKE_image_partial_update_get_next_change(partial_update_user, &change) ==
ePartialUpdateIterResult::ChangeAvailable){
// Do something with the change.
}
case ePartialUpdateCollectResult::NoChangesDetected:
break;
}
...
// Free partial_update_user.
BKE_image_partial_update_free(partial_update_user);
PartialUpdateUser * BKE_image_partial_update_create(const Image *image)
Create a new PartialUpdateUser. An Object that contains data to use partial updates.
ePartialUpdateCollectResult BKE_image_partial_update_collect_changes(Image *image, PartialUpdateUser *user)
collect the partial update since the last request.
ePartialUpdateIterResult BKE_image_partial_update_get_next_change(PartialUpdateUser *user, PartialUpdateRegion *r_region)

Definition in file image_partial_update.cc.

Function Documentation

◆ BKE_image_partial_update_create()

PartialUpdateUser * BKE_image_partial_update_create ( const Image * image)

Create a new PartialUpdateUser. An Object that contains data to use partial updates.

Definition at line 543 of file image_partial_update.cc.

References image(), UNUSED_VARS, and blender::bke::image::partial_update::wrap().

Referenced by image_get_gpu_texture(), and blender::bke::image::partial_update::ImagePartialUpdateTest::SetUp().

◆ BKE_image_partial_update_free()

void BKE_image_partial_update_free ( PartialUpdateUser * user)

◆ BKE_image_partial_update_mark_full_update()

◆ BKE_image_partial_update_mark_region()

◆ BKE_image_partial_update_register_free()

void BKE_image_partial_update_register_free ( Image * image)