Blender V4.3
tile_highlight.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "tile_highlight.h"
10
11#include "MEM_guardedalloc.h"
12
13#include "BLI_hash.hh"
14
15#include "RE_pipeline.h"
16
17namespace blender::render {
18
19TilesHighlight::Tile::Tile(const RenderResult *result) : rect(result->tilerect) {}
20
21TilesHighlight::Tile::Tile(const int x, const int y, const int width, const int height)
22{
23 BLI_rcti_init(&rect, x, x + width, y, y + height);
24}
25
26uint64_t TilesHighlight::Tile::hash() const
27{
28 return get_default_hash(rect.xmin, rect.xmax, rect.ymin, rect.ymax);
29}
30
31void TilesHighlight::highlight_tile_for_result(const RenderResult *result)
32{
33 const Tile tile(result);
34 highlight_tile(tile);
35}
36
37void TilesHighlight::unhighlight_tile_for_result(const RenderResult *result)
38{
39 const Tile tile(result);
40 unhighlight_tile(tile);
41}
42
43void TilesHighlight::highlight_tile(const int x, const int y, const int width, const int height)
44{
45 const Tile tile(x, y, width, height);
46 highlight_tile(tile);
47}
48
49void TilesHighlight::unhighlight_tile(const int x, const int y, const int width, const int height)
50{
51 const Tile tile(x, y, width, height);
52 unhighlight_tile(tile);
53}
54
55void TilesHighlight::highlight_tile(const Tile &tile)
56{
57 std::unique_lock lock(mutex_);
58
59 highlighted_tiles_set_.add(tile);
60 did_tiles_change_ = true;
61}
62
63void TilesHighlight::unhighlight_tile(const Tile &tile)
64{
65 std::unique_lock lock(mutex_);
66
67 highlighted_tiles_set_.remove(tile);
68 did_tiles_change_ = true;
69}
70
71void TilesHighlight::clear()
72{
73 std::unique_lock lock(mutex_);
74
75 highlighted_tiles_set_.clear();
76 cached_highlighted_tiles_.clear_and_shrink();
77}
78
79Span<rcti> TilesHighlight::get_all_highlighted_tiles() const
80{
81 std::unique_lock lock(mutex_);
82
83 /* Updated cached flat list if needed. */
84 if (did_tiles_change_) {
85 if (highlighted_tiles_set_.is_empty()) {
86 cached_highlighted_tiles_.clear_and_shrink();
87 }
88 else {
89 cached_highlighted_tiles_.reserve(highlighted_tiles_set_.size());
90 for (const Tile &tile : highlighted_tiles_set_) {
91 cached_highlighted_tiles_.append(tile.rect);
92 }
93 }
94
95 did_tiles_change_ = false;
96 }
97
98 return cached_highlighted_tiles_;
99}
100
101} // namespace blender::render
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.c:418
Read Guarded memory(de)allocation.
volatile int lock
ccl_global const KernelWorkTile * tile
uint64_t get_default_hash(const T &v)
Definition BLI_hash.hh:219
unsigned __int64 uint64_t
Definition stdint.h:90