HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TIL_Region.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: TIL_Region.h (Tile Image Library, C++)
7  *
8  * COMMENTS:
9  * Handles arbitrary sized regions of planes, for algorithms that
10  * require more information than just a tile.
11  */
12 #ifndef TIL_REGION_H
13 #define TIL_REGION_H
14 
15 #include "TIL_API.h"
16 #include "TIL_Defines.h"
17 
18 #include <UT/UT_Lock.h>
19 #include <UT/UT_SmallObject.h>
20 #include <SYS/SYS_Types.h>
21 
22 class TIL_Plane;
23 class TIL_Tile;
24 class TIL_TileList;
25 
27 {
28  TIL_BLACK = 0,
31  TIL_HOLD_TOP = 0x4,
33  TIL_HOLD = 0xF
34 };
35 
37  : public UT_SmallObject<TIL_Region,
38  UT_SMALLOBJECT_CLEANPAGES_OFF, 32,
39  UT_SMALLOBJECT_THREADSAFE_ON, 1024>
40 {
41 public:
42  // Do NOT derive classes from this method, or add virtual functions.
43 
44  // region allocation routines.
45  static TIL_Region *allocRegion();
46  static void freeRegion(TIL_Region *&freeme);
47 
48 
49  void init(const TIL_Plane *parent, int input_index,
50  int array_index, float time, int xres, int yres,
51  int x1, int y1, int x2, int y2,
52  int bx1, int by1, int bx2, int by2,
54  int share_count = 1, int nid = 0,
55  bool output = false, int xpad = 0);
56 
57  void reset();
58 
59  // sets the image data to zero. Does not set the constant flags.
60  void clear();
61 
62  int getID() const { return myID; }
63  int getNodeID() const { return myNodeID; }
64 
65  // call to init and destroy (regions are ref-counted). If you supply your
66  // own memory regions, pass the pointers (you are responsible for freeing
67  // them, unlike the automatically alloced memory which is freed for you).
68  int open(void *regionlist[PLANE_MAX_VECTOR_SIZE] = 0);
69  int close();
70 
71  // info accessors
72 
73  // identification
74  const TIL_Plane *getParent() const { return myParent; }
75  int getInputRef() const { return myInputRef; }
76  int getArrayIndex() const { return myArrayIndex; }
77  float getTime() const { return myCookTime; }
78  void getRegionRes(int &x, int &y) const
79  { x=myXres; y=myYres; }
80  //
81  void getRegionBounds(int &x1, int &y1, int &x2, int &y2) const
82  { x1 = myX1+myXShift; y1 = myY1+myYShift;
83  x2 = myX2+myXShift; y2 = myY2+myYShift; }
84 
85  // for output regions, allows you to mark the region as filled.
86  void markFilled(bool filled = true) { myRemainingTiles = filled ? 0 : 1; }
87 
88  // tells you if the regions is completely filled.
89  int isFilled() const { return myRemainingTiles == 0; }
90  int remainingTiles() const { return myRemainingTiles; }
91  bool isInitialized() const { return myRegionInit; }
92 
93  bool workOnRegion();
94 
95  // tells you which tile needs to be cooked next, if 0 is returned,
96  // all the remaining tiles in the process of being cooked.
97  int getNextNeededTile(int &xoff,int &yoff,
98  int &xshift, int &yshift);
99 
100  // call when you're done filling the region with the tile recommended by
101  // getNextNeededTile.
102  void finishedTile(int xoff, int yoff);
103 
104  // checks to see if the region is still constant.
105  void checkConstant(const TIL_Tile *tile, int component);
106  bool isConstantChecked() const { return myConstantChecked; }
107  bool isConstant(bool force_check = false);
108  bool isConstantValue() const;
109  void getConstantColor(float color[4]) const;
110  // does not set the color for the region, only the constant flag & color.
111  void setConstantColor(float color[4]);
112 
113  // can't cook a tile that getNextNeededTile passed (likely due to a
114  // write lock on the tile held by another thread).
115  void rejectTile(int xoff, int yoff);
116 
117  // returns the data associated with index or component name 'compname'
118  void * getImageData(int index);
119  const void *getImageData(int index) const;
120 
121  void * getImageData(const char *compname);
122  const void *getImageData(const char *compname) const;
123 
124  void setImageData(void *data, int index, bool reference = true);
125 
126  // Returns the size, in bytes, of the image data. The result is the size
127  // for one component, not for all components.
128  exint getImageDataSizePerComponent() const;
129 
130  // Total memory size of this region (approx).
131  exint getMemSize();
132 
133  bool isSharedRegion() const { return myRegionShared; }
134  bool isSharedRegionDone() const { return myRegionUnshared; }
135  int getCurrentRefCount() const { return myRefCount; }
136  int getCurrentShareCount() const { return myShareCount; }
137  void unshareRegion();
138 
139  // Region hash routines - return this region's hash code.
140  unsigned getHash() const { return myHashCode; }
141 
142  // Return a hash code would correspond to the hash code of a region
143  // created with these parms.
144  static unsigned getHash(const TIL_Plane *plane, int aindex, int inref,
145  float t, int x1, int y1, int x2, int y2,
146  int xres, int yres, int nid, bool output);
147 
148  // Use these methods to get a tile list which corresponds to this region.
149  // The region should be equal to or less than the current tile size.
150  // Please note that the extra information in the tiles, such as the offset
151  // and other information, may not be accurate.
152  // Call cleanupTiles to free the tilelist. Do NOT call
153  // COP2_Node::releaseTile or freeTile on this tilelist!
154  TIL_TileList *getTilesFromRegion();
155  void cleanupTiles(TIL_TileList *&tiles);
156 
157  // sets the time to cook this region (mostly for output regions where you
158  // want to distribute the time spent filling it across all the tiles)
159  void setWorkTime(float cooktime) { myWorkTime = cooktime; }
160  float getWorkTime() const { return myWorkTime; }
161 
162 private:
163  TIL_Region();
164  ~TIL_Region();
165 
166  void fillOutsideData();
167  float fillOutsideBlack(unsigned char *region);
168  void fillOutsideHold(unsigned char *region);
169  void determineIfConstant();
170 
171 private:
172  // Parent plane (and allocation routine next ptr).
173  union {
176  };
177 
178  // more image id.
179  short myArrayIndex;
180  short myInputRef;
181  int myID;
182  int myNodeID;
183  float myCookTime;
184 
185  // parent image res
186  int myXres, myYres;
187 
188  // region coordinates
189  int myX1, myY1;
190  int myX2, myY2;
191 
192  // coordinates clipped to canvas bounds
193  int myRX1, myRY1;
194  int myRX2, myRY2;
195 
196  // coordinates clipped to (0,0)->(xres-1,yres-1)
197  int myBX1, myBY1;
198  int myBX2, myBY2;
199 
200  int myXShift, myYShift;
201 
202  // region image data
203  void *myRegion[PLANE_MAX_VECTOR_SIZE];
204  void *myRawRegion[PLANE_MAX_VECTOR_SIZE];
205  char myRegionAlloced[PLANE_MAX_VECTOR_SIZE];
206 
207  // cooperative cooking
208  UT_Lock myLock;
209  int myRefCount;
210  int myShareCount;
211 
212  int myTileOffX;
213  int myTileOffY;
214  int myTileX2;
215  int myTileY2;
216  int myTileXCount;
217  int myTileYCount;
218  int myRemainingTiles;
219  int myAvailableTiles;
220  int myTileStride;
221  unsigned char *myTileStates;
222  float myWorkTime;
223 
224  float myConstantColor[4];
225 
226  unsigned myHashCode;
227  unsigned int myRegionOutside :1,
228  myHold :4,
229  myConstantChecked : 1,
230  myConstantFlag :1,
231  myConstantColorSetR : 1,
232  myConstantColorSetG : 1,
233  myConstantColorSetB : 1,
234  myConstantColorSetA : 1,
235  myRegionInit :1,
236  myRegionWorkFlag : 1,
237  myRegionShared : 1,
238  myRegionUnshared : 1;
239 };
240 
241 #endif
GT_API const UT_StringHolder time
bool isInitialized() const
Definition: TIL_Region.h:91
int getID() const
Definition: TIL_Region.h:62
int getArrayIndex() const
Definition: TIL_Region.h:76
TIL_RegionExtend
Definition: TIL_Region.h:26
int64 exint
Definition: SYS_Types.h:125
unsigned getHash() const
Definition: TIL_Region.h:140
GLint y
Definition: glcorearb.h:103
void getRegionBounds(int &x1, int &y1, int &x2, int &y2) const
Definition: TIL_Region.h:81
void close() override
const TIL_Plane * getParent() const
Definition: TIL_Region.h:74
GLdouble GLdouble x2
Definition: glad.h:2349
int getCurrentShareCount() const
Definition: TIL_Region.h:136
float getTime() const
Definition: TIL_Region.h:77
TIL_Region * myNext
Definition: TIL_Region.h:175
int isFilled() const
Definition: TIL_Region.h:89
GLboolean reset
Definition: glad.h:5138
int open(float queuesize) override
int remainingTiles() const
Definition: TIL_Region.h:90
void setWorkTime(float cooktime)
Definition: TIL_Region.h:159
GLdouble y1
Definition: glad.h:2349
#define PLANE_MAX_VECTOR_SIZE
Definition: TIL_Defines.h:166
int getCurrentRefCount() const
Definition: TIL_Region.h:135
const TIL_Plane * myParent
Definition: TIL_Region.h:174
bool isConstantChecked() const
Definition: TIL_Region.h:106
GLint GLenum GLint x
Definition: glcorearb.h:409
void getRegionRes(int &x, int &y) const
Definition: TIL_Region.h:78
GLdouble t
Definition: glad.h:2397
int getInputRef() const
Definition: TIL_Region.h:75
GLuint color
Definition: glcorearb.h:1261
GLuint index
Definition: glcorearb.h:786
bool isSharedRegion() const
Definition: TIL_Region.h:133
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
float getWorkTime() const
Definition: TIL_Region.h:160
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate and *a name There is also one special expression reference
#define TIL_API
Definition: TIL_API.h:10
bool isSharedRegionDone() const
Definition: TIL_Region.h:134
int getNodeID() const
Definition: TIL_Region.h:63
Definition: format.h:1821
void markFilled(bool filled=true)
Definition: TIL_Region.h:86