Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_MemoryBuffer.h « intern « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fd90e5fcb5ad5df20c11eda01e01274c999f09a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor: 
 *		Jeroen Bakker 
 *		Monique Dewanchand
 */

class MemoryBuffer;

#ifndef _COM_MemoryBuffer_h_
#define _COM_MemoryBuffer_h_

#include "COM_ExecutionGroup.h"
#include "BLI_rect.h"
#include "COM_MemoryProxy.h"
extern "C" {
	#include "BLI_threads.h"
}
#include <vector>

/**
  * @brief state of a memory buffer
  * @ingroup Memory
  */
typedef enum MemoryBufferState {
	/** @brief memory has been allocated on creator device and CPU machine, but kernel has not been executed */
	COM_MB_ALLOCATED = 1,
	/** @brief memory is available for use, content has been created */
	COM_MB_AVAILABLE = 2,
	/** @brief chunk is consolidated from other chunks. special state.*/
	COM_MB_TEMPORARILY = 6
} MemoryBufferState;

class MemoryProxy;

/**
  * @brief a MemoryBuffer contains access to the data of a chunk
  */
class MemoryBuffer {
private:
	/**
	  * @brief proxy of the memory (same for all chunks in the same buffer)
	  */
	MemoryProxy * memoryProxy;
	
	/**
	  * @brief the type of buffer COM_DT_VALUE, COM_DT_VECTOR, COM_DT_COLOR
	  */
	DataType datatype;
	
	
	/**
	  * @brief region of this buffer inside reative to the MemoryProxy
	  */
	rcti rect;
	
	/**
	  * brief refers to the chunknumber within the executiongroup where related to the MemoryProxy
	  * @see memoryProxy
	  */
	unsigned int chunkNumber;
	
	/**
	  * @brief width of the chunk
	  */
	unsigned int chunkWidth;
	
	/**
	  * @brief state of the buffer
	  */
	MemoryBufferState state;
	
	/**
	  * @brief the actual float buffer/data
	  */
	float *buffer;

public:
	/**
	  * @brief construct new MemoryBuffer for a chunk
	  */
	MemoryBuffer(MemoryProxy *memoryProxy, unsigned int chunkNumber, rcti *rect);
	
	/**
	  * @brief construct new temporarily MemoryBuffer for an area
	  */
	MemoryBuffer(MemoryProxy *memoryProxy, rcti *rect);
	
	/**
	  * @brief destructor
	  */
	~MemoryBuffer();
	
	/**
	  * @brief read the ChunkNumber of this MemoryBuffer
	  */
	unsigned int getChunkNumber() {return this->chunkNumber;}
	
	/**
	  * @brief get the data of this MemoryBuffer
	  * @note buffer should already be available in memory
	  */
	float *getBuffer() {return this->buffer;}
	
	/**
	  * @brief after execution the state will be set to available by calling this method
	  */
	void setCreatedState() {
		this->state = COM_MB_AVAILABLE;
	}
	
	void read(float result[4], int x, int y);
	void writePixel(int x, int y, const float color[4]);
	void readCubic(float result[4], float x, float y);
	void readEWA(float result[4], float fx, float fy, float dx, float dy);
	
	/**
	  * @brief is this MemoryBuffer a temporarily buffer (based on an area, not on a chunk)
	  */
	inline const bool isTemporarily() const {return this->state == COM_MB_TEMPORARILY;}
	
	/**
	  * @brief add the content from otherBuffer to this MemoryBuffer
	  * @param otherBuffer source buffer
	  */
	void copyContentFrom(MemoryBuffer *otherBuffer);
	
	/**
	  * @brief get the rect of this MemoryBuffer
	  */
	rcti *getRect() {return &this->rect;}
	
	/**
	  * @brief get the width of this MemoryBuffer
	  */
	int getWidth() const;
	
	/**
	  * @brief get the height of this MemoryBuffer
	  */
	int getHeight() const;
	
	/**
	  * @brief clear the buffer. Make all pixels black transparant.
	  */
	void clear();
	
	MemoryBuffer *duplicate();
	
	float *convertToValueBuffer();
private:
	unsigned int determineBufferSize();
};

#endif