| 1 |
// Licensed to the .NET Foundation under one or more agreements. |
| 2 |
// The .NET Foundation licenses this file to you under the MIT license. |
| 3 |
// See the LICENSE file in the project root for more information. |
| 4 |
|
| 5 |
|
| 6 |
//------------------------------------------------------------------------------ |
| 7 |
// |
| 8 |
|
| 9 |
use std::cell::Cell; |
| 10 |
|
| 11 |
use typed_arena_nomut::Arena; |
| 12 |
|
| 13 |
// |
| 14 |
// Description: |
| 15 |
// Coverage buffer implementation |
| 16 |
#[cfg(debug_assertions)] |
| 17 |
use crate::aarasterizer::AssertActiveList; |
| 18 |
use crate::aarasterizer::CEdge; |
| 19 |
use crate::nullable_ref::Ref; |
| 20 |
use crate::types::*; |
| 21 |
//struct CEdge; |
| 22 |
//struct CInactiveEdge; |
| 23 |
|
| 24 |
//------------------------------------------------------------------------- |
| 25 |
// |
| 26 |
// TrapezoidalAA only supports 8x8 mode, so the shifts/masks are all |
| 27 |
// constants. Also, since we must be symmetrical, x and y shifts are |
| 28 |
// merged into one shift unlike the implementation in aarasterizer. |
| 29 |
// |
| 30 |
//------------------------------------------------------------------------- |
| 31 |
|
| 32 |
pub const c_nShift: INT = 3; |
| 33 |
pub const c_nShiftSize: INT = 8; |
| 34 |
pub const c_nShiftSizeSquared: INT = c_nShiftSize * c_nShiftSize; |
| 35 |
pub const c_nHalfShiftSize: INT = 4; |
| 36 |
pub const c_nShiftMask: INT = 7; |
| 37 |
//pub const c_rShiftSize: f32 = 8.0; |
| 38 |
//pub const c_rHalfShiftSize: f32 = 4.0; |
| 39 |
pub const c_rInvShiftSize: f32 = 1.0/8.0; |
| 40 |
pub const c_antiAliasMode: MilAntiAliasMode = MilAntiAliasMode::EightByEight; |
| 41 |
|
| 42 |
// |
| 43 |
// Interval coverage descriptor for our antialiased filler |
| 44 |
// |
| 45 |
|
| 46 |
pub struct CCoverageInterval<'a> |
| 47 |
{ |
| 48 |
pub m_pNext: Cell<Ref<'a, CCoverageInterval<'a>>>, // m_pNext interval (look for sentinel, not NULL) |
| 49 |
pub m_nPixelX: Cell<INT>, // Interval's left edge (m_pNext->X is the right edge) |
| 50 |
pub m_nCoverage: Cell<INT>, // Pixel coverage for interval |
| 51 |
} |
| 52 |
|
| 53 |
impl<'a> Default for CCoverageInterval<'a> { |
| 54 |
fn default() -> Self { |
| 55 |
Self { m_pNext: Cell::new(unsafe { Ref::null() } ), m_nPixelX: Default::default(), m_nCoverage: Default::default() } |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
// Define our on-stack storage use. The 'free' versions are nicely tuned |
| 60 |
// to avoid allocations in most common scenarios, while at the same time |
| 61 |
// not chewing up toooo much stack space. |
| 62 |
// |
| 63 |
// We make the debug versions small so that we hit the 'grow' cases more |
| 64 |
// frequently, for better testing: |
| 65 |
|
| 66 |
#[cfg(debug_assertions)] |
| 67 |
// Must be at least 6 now: 4 for the "minus4" logic in hwrasterizer.*, and then |
| 68 |
// 1 each for the head and tail sentinels (since their allocation doesn't use Grow). |
| 69 |
const INTERVAL_BUFFER_NUMBER: usize = 8; |
| 70 |
#[cfg(not(debug_assertions))] |
| 71 |
const INTERVAL_BUFFER_NUMBER: usize = 32; |
| 72 |
|
| 73 |
|
| 74 |
// |
| 75 |
// Allocator structure for the antialiased fill interval data |
| 76 |
// |
| 77 |
|
| 78 |
struct CCoverageIntervalBuffer<'a> |
| 79 |
{ |
| 80 |
m_pNext: Cell<Option<& 'a CCoverageIntervalBuffer<'a>>>, |
| 81 |
m_interval: [CCoverageInterval<'a>; INTERVAL_BUFFER_NUMBER], |
| 82 |
} |
| 83 |
|
| 84 |
impl<'a> Default for CCoverageIntervalBuffer<'a> { |
| 85 |
fn default() -> Self { |
| 86 |
Self { m_pNext: Cell::new(None), m_interval: Default::default() } |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
//------------------------------------------------------------------------------ |
| 91 |
// |
| 92 |
// Class: CCoverageBuffer |
| 93 |
// |
| 94 |
// Description: |
| 95 |
// Coverage buffer implementation that maintains coverage information |
| 96 |
// for one scanline. |
| 97 |
// |
| 98 |
// This implementation will maintain a linked list of intervals consisting |
| 99 |
// of x value in pixel space and a coverage value that applies for all pixels |
| 100 |
// between pInterval->X and pInterval->Next->X. |
| 101 |
// |
| 102 |
// For example, if we add the following interval (assuming 8x8 anti-aliasing) |
| 103 |
// to the coverage buffer: |
| 104 |
// _____ _____ _____ _____ |
| 105 |
// | | | | | |
| 106 |
// | ------------------- | |
| 107 |
// |_____|_____|_____|_____| |
| 108 |
// (0,0) (1,0) (2,0) (3,0) (4,0) |
| 109 |
// |
| 110 |
// Then we will get the following coverage buffer: |
| 111 |
// |
| 112 |
// m_nPixelX: INT_MIN | 0 | 1 | 3 | 4 | INT_MAX |
| 113 |
// m_nCoverage: 0 | 4 | 8 | 4 | 0 | 0xdeadbeef |
| 114 |
// m_pNext: -------->|---->|---->|---->|---->| NULL |
| 115 |
// |
| 116 |
//------------------------------------------------------------------------------ |
| 117 |
pub struct CCoverageBuffer<'a> |
| 118 |
{ |
| 119 |
/* |
| 120 |
public: |
| 121 |
// |
| 122 |
// Init/Destroy methods |
| 123 |
// |
| 124 |
|
| 125 |
VOID Initialize(); |
| 126 |
VOID Destroy(); |
| 127 |
|
| 128 |
// |
| 129 |
// Setup the buffer so that it can accept another scanline |
| 130 |
// |
| 131 |
|
| 132 |
VOID Reset(); |
| 133 |
|
| 134 |
// |
| 135 |
// Add a subpixel interval to the coverage buffer |
| 136 |
// |
| 137 |
|
| 138 |
HRESULT FillEdgesAlternating( |
| 139 |
__in_ecount(1) const CEdge *pEdgeActiveList, |
| 140 |
INT nSubpixelYCurrent |
| 141 |
); |
| 142 |
|
| 143 |
HRESULT FillEdgesWinding( |
| 144 |
__in_ecount(1) const CEdge *pEdgeActiveList, |
| 145 |
INT nSubpixelYCurrent |
| 146 |
); |
| 147 |
|
| 148 |
HRESULT AddInterval(INT nSubpixelXLeft, INT nSubpixelXRight); |
| 149 |
|
| 150 |
private: |
| 151 |
|
| 152 |
HRESULT Grow( |
| 153 |
__deref_out_ecount(1) CCoverageInterval **ppIntervalNew, |
| 154 |
__deref_out_ecount(1) CCoverageInterval **ppIntervalEndMinus4 |
| 155 |
); |
| 156 |
|
| 157 |
public:*/ |
| 158 |
pub m_pIntervalStart: Cell<Ref<'a, CCoverageInterval<'a>>>, // Points to list head entry |
| 159 |
|
| 160 |
//private: |
| 161 |
m_pIntervalNew: Cell<Ref<'a, CCoverageInterval<'a>>>, |
| 162 |
interval_new_index: Cell<usize>, |
| 163 |
|
| 164 |
// The Minus4 in the below variable refers to the position at which |
| 165 |
// we need to Grow the buffer. The buffer is grown once before an |
| 166 |
// AddInterval, so the Grow has to ensure that there are enough |
| 167 |
// intervals for the AddInterval worst case which is the following: |
| 168 |
// |
| 169 |
// 1 2 3 4 |
| 170 |
// *_____*_____ _____*_____* |
| 171 |
// | | | | | |
| 172 |
// | ---|-----------|--- | |
| 173 |
// |_____|_____|_____|_____| |
| 174 |
// |
| 175 |
// Note that the *'s above mark potentional insert points in the list, |
| 176 |
// so we need to ensure that at least 4 intervals can be allocated. |
| 177 |
// |
| 178 |
|
| 179 |
m_pIntervalEndMinus4: Cell<Ref<'a, CCoverageInterval<'a>>>, |
| 180 |
|
| 181 |
// Cache the next-to-last added interval to accelerate insertion. |
| 182 |
m_pIntervalLast: Cell<Ref<'a, CCoverageInterval<'a>>>, |
| 183 |
|
| 184 |
m_pIntervalBufferBuiltin: CCoverageIntervalBuffer<'a>, |
| 185 |
m_pIntervalBufferCurrent: Cell<Ref<'a, CCoverageIntervalBuffer<'a>>>, |
| 186 |
|
| 187 |
arena: Arena<CCoverageIntervalBuffer<'a>> |
| 188 |
|
| 189 |
// Disable instrumentation checks within all methods of this class |
| 190 |
//SET_MILINSTRUMENTATION_FLAGS(MILINSTRUMENTATIONFLAGS_DONOTHING); |
| 191 |
} |
| 192 |
|
| 193 |
impl<'a> Default for CCoverageBuffer<'a> { |
| 194 |
fn default() -> Self { |
| 195 |
Self { |
| 196 |
m_pIntervalStart: Cell::new(unsafe { Ref::null() }), |
| 197 |
m_pIntervalNew: Cell::new(unsafe { Ref::null() }), |
| 198 |
m_pIntervalEndMinus4: Cell::new(unsafe { Ref::null() }), |
| 199 |
m_pIntervalLast: Cell::new(unsafe { Ref::null() }), |
| 200 |
m_pIntervalBufferBuiltin: Default::default(), |
| 201 |
m_pIntervalBufferCurrent: unsafe { Cell::new(Ref::null()) }, |
| 202 |
arena: Arena::new(), |
| 203 |
interval_new_index: Cell::new(0), |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
// |
| 210 |
// Inlines |
| 211 |
// |
| 212 |
impl<'a> CCoverageBuffer<'a> { |
| 213 |
//------------------------------------------------------------------------- |
| 214 |
// |
| 215 |
// Function: CCoverageBuffer::AddInterval |
| 216 |
// |
| 217 |
// Synopsis: Add a subpixel resolution interval to the coverage buffer |
| 218 |
// |
| 219 |
//------------------------------------------------------------------------- |
| 220 |
pub fn AddInterval(&'a self, nSubpixelXLeft: INT, nSubpixelXRight: INT) -> HRESULT |
| 221 |
{ |
| 222 |
let hr: HRESULT = S_OK; |
| 223 |
let mut nPixelXNext: INT; |
| 224 |
let nPixelXLeft: INT; |
| 225 |
let nPixelXRight: INT; |
| 226 |
let nCoverageLeft: INT; // coverage from right edge of pixel for interval start |
| 227 |
let nCoverageRight: INT; // coverage from left edge of pixel for interval end |
| 228 |
|
| 229 |
let mut pInterval = self.m_pIntervalStart.get(); |
| 230 |
let mut pIntervalNew = self.m_pIntervalNew.get(); |
| 231 |
let mut interval_new_index = self.interval_new_index.get(); |
| 232 |
let mut pIntervalEndMinus4 = self.m_pIntervalEndMinus4.get(); |
| 233 |
|
| 234 |
// Make sure we have enough room to add two intervals if |
| 235 |
// necessary: |
| 236 |
|
| 237 |
if (pIntervalNew >= pIntervalEndMinus4) |
| 238 |
{ |
| 239 |
IFC!(self.Grow(&mut pIntervalNew, &mut pIntervalEndMinus4, &mut interval_new_index)); |
| 240 |
} |
| 241 |
|
| 242 |
// Convert interval to pixel space so that we can insert it |
| 243 |
// into the coverage buffer |
| 244 |
|
| 245 |
debug_assert!(nSubpixelXLeft < nSubpixelXRight); |
| 246 |
nPixelXLeft = nSubpixelXLeft >> c_nShift; |
| 247 |
nPixelXRight = nSubpixelXRight >> c_nShift; |
| 248 |
|
| 249 |
// Try to resume searching from the last searched interval. |
| 250 |
if self.m_pIntervalLast.get().m_nPixelX.get() < nPixelXLeft { |
| 251 |
pInterval = self.m_pIntervalLast.get(); |
| 252 |
} |
| 253 |
|
| 254 |
// Skip any intervals less than 'nPixelLeft': |
| 255 |
|
| 256 |
loop { |
| 257 |
let nextInterval = pInterval.m_pNext.get(); |
| 258 |
nPixelXNext = nextInterval.m_nPixelX.get(); |
| 259 |
if !(nPixelXNext < nPixelXLeft) { break } |
| 260 |
|
| 261 |
pInterval = nextInterval; |
| 262 |
} |
| 263 |
|
| 264 |
// Remember the found interval. |
| 265 |
self.m_pIntervalLast.set(pInterval); |
| 266 |
|
| 267 |
// Insert a new interval if necessary: |
| 268 |
|
| 269 |
if (nPixelXNext != nPixelXLeft) |
| 270 |
{ |
| 271 |
pIntervalNew.m_nPixelX.set(nPixelXLeft); |
| 272 |
pIntervalNew.m_nCoverage.set(pInterval.m_nCoverage.get()); |
| 273 |
|
| 274 |
pIntervalNew.m_pNext.set(pInterval.m_pNext.get()); |
| 275 |
pInterval.m_pNext.set(pIntervalNew); |
| 276 |
|
| 277 |
pInterval = pIntervalNew; |
| 278 |
|
| 279 |
interval_new_index += 1; |
| 280 |
pIntervalNew = Ref::new(&Ref::get_ref(self.m_pIntervalBufferCurrent.get()).m_interval[interval_new_index]) |
| 281 |
|
| 282 |
} |
| 283 |
else |
| 284 |
{ |
| 285 |
pInterval = (*pInterval).m_pNext.get(); |
| 286 |
} |
| 287 |
|
| 288 |
// |
| 289 |
// Compute coverage for left segment as shown by the *'s below |
| 290 |
// |
| 291 |
// |_____|_____|_____|_ |
| 292 |
// | | | | |
| 293 |
// | ***---------- | |
| 294 |
// |_____|_____|_____| |
| 295 |
// |
| 296 |
|
| 297 |
nCoverageLeft = c_nShiftSize - (nSubpixelXLeft & c_nShiftMask); |
| 298 |
|
| 299 |
// If nCoverageLeft == 0, then the value of nPixelXLeft is wrong |
| 300 |
// and should have been equal to nPixelXLeft+1. |
| 301 |
debug_assert!(nCoverageLeft > 0); |
| 302 |
|
| 303 |
// If we have partial coverage, then ensure that we have a position |
| 304 |
// for the end of the pixel |
| 305 |
|
| 306 |
if ((nCoverageLeft < c_nShiftSize || (nPixelXLeft == nPixelXRight)) |
| 307 |
&& nPixelXLeft + 1 != pInterval.m_pNext.get().m_nPixelX.get()) |
| 308 |
{ |
| 309 |
pIntervalNew.m_nPixelX.set(nPixelXLeft + 1); |
| 310 |
pIntervalNew.m_nCoverage.set(pInterval.m_nCoverage.get()); |
| 311 |
|
| 312 |
pIntervalNew.m_pNext.set(pInterval.m_pNext.get()); |
| 313 |
pInterval.m_pNext.set(pIntervalNew); |
| 314 |
|
| 315 |
interval_new_index += 1; |
| 316 |
pIntervalNew = Ref::new(&Ref::get_ref(self.m_pIntervalBufferCurrent.get()).m_interval[interval_new_index]) |
| 317 |
} |
| 318 |
|
| 319 |
// |
| 320 |
// If the interval only includes one pixel, then the coverage is |
| 321 |
// nSubpixelXRight - nSubpixelXLeft |
| 322 |
// |
| 323 |
|
| 324 |
if (nPixelXLeft == nPixelXRight) |
| 325 |
{ |
| 326 |
pInterval.m_nCoverage.set(pInterval.m_nCoverage.get() + nSubpixelXRight - nSubpixelXLeft); |
| 327 |
debug_assert!(pInterval.m_nCoverage.get() <= c_nShiftSize*c_nShiftSize); |
| 328 |
//goto Cleanup; |
| 329 |
|
| 330 |
//Cleanup: |
| 331 |
// Update the coverage buffer new interval |
| 332 |
self.interval_new_index.set(interval_new_index); |
| 333 |
self.m_pIntervalNew.set(pIntervalNew); |
| 334 |
return hr; |
| 335 |
} |
| 336 |
|
| 337 |
// Update coverage of current interval |
| 338 |
pInterval.m_nCoverage.set(pInterval.m_nCoverage.get() + nCoverageLeft); |
| 339 |
debug_assert!(pInterval.m_nCoverage.get() <= c_nShiftSize*c_nShiftSize); |
| 340 |
|
| 341 |
// Increase the coverage for any intervals between 'nPixelXLeft' |
| 342 |
// and 'nPixelXRight': |
| 343 |
|
| 344 |
loop { |
| 345 |
let nextInterval = pInterval.m_pNext.get(); |
| 346 |
(nPixelXNext = nextInterval.m_nPixelX.get()); |
| 347 |
|
| 348 |
if !(nPixelXNext < nPixelXRight) { |
| 349 |
break; |
| 350 |
} |
| 351 |
pInterval = nextInterval; |
| 352 |
pInterval.m_nCoverage.set(pInterval.m_nCoverage.get() + c_nShiftSize); |
| 353 |
debug_assert!(pInterval.m_nCoverage.get() <= c_nShiftSize*c_nShiftSize); |
| 354 |
} |
| 355 |
|
| 356 |
// Remember the found interval. |
| 357 |
self.m_pIntervalLast.set(pInterval); |
| 358 |
|
| 359 |
// Insert another new interval if necessary: |
| 360 |
|
| 361 |
if (nPixelXNext != nPixelXRight) |
| 362 |
{ |
| 363 |
pIntervalNew.m_nPixelX.set(nPixelXRight); |
| 364 |
pIntervalNew.m_nCoverage.set(pInterval.m_nCoverage.get() - c_nShiftSize); |
| 365 |
|
| 366 |
pIntervalNew.m_pNext.set(pInterval.m_pNext.get()); |
| 367 |
pInterval.m_pNext.set(pIntervalNew); |
| 368 |
|
| 369 |
pInterval = pIntervalNew; |
| 370 |
|
| 371 |
interval_new_index += 1; |
| 372 |
pIntervalNew = Ref::new(&Ref::get_ref(self.m_pIntervalBufferCurrent.get()).m_interval[interval_new_index]) |
| 373 |
} |
| 374 |
else |
| 375 |
{ |
| 376 |
pInterval = pInterval.m_pNext.get(); |
| 377 |
} |
| 378 |
|
| 379 |
// |
| 380 |
// Compute coverage for right segment as shown by the *'s below |
| 381 |
// |
| 382 |
// |_____|_____|_____|_ |
| 383 |
// | | | | |
| 384 |
// | ---------**** | |
| 385 |
// |_____|_____|_____| |
| 386 |
// |
| 387 |
|
| 388 |
nCoverageRight = nSubpixelXRight & c_nShiftMask; |
| 389 |
if (nCoverageRight > 0) |
| 390 |
{ |
| 391 |
if (nPixelXRight + 1 != (*(*pInterval).m_pNext.get()).m_nPixelX.get()) |
| 392 |
{ |
| 393 |
pIntervalNew.m_nPixelX.set(nPixelXRight + 1); |
| 394 |
pIntervalNew.m_nCoverage.set(pInterval.m_nCoverage.get()); |
| 395 |
|
| 396 |
pIntervalNew.m_pNext.set(pInterval.m_pNext.get()); |
| 397 |
pInterval.m_pNext.set(pIntervalNew); |
| 398 |
|
| 399 |
interval_new_index += 1; |
| 400 |
pIntervalNew = Ref::new(&Ref::get_ref(self.m_pIntervalBufferCurrent.get()).m_interval[interval_new_index]) |
| 401 |
} |
| 402 |
|
| 403 |
pInterval.m_nCoverage.set((*pInterval).m_nCoverage.get() + nCoverageRight); |
| 404 |
debug_assert!(pInterval.m_nCoverage.get() <= c_nShiftSize*c_nShiftSize); |
| 405 |
} |
| 406 |
|
| 407 |
//Cleanup: |
| 408 |
// Update the coverage buffer new interval |
| 409 |
self.interval_new_index.set(interval_new_index); |
| 410 |
self.m_pIntervalNew.set(pIntervalNew); |
| 411 |
|
| 412 |
return hr; |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
//------------------------------------------------------------------------- |
| 417 |
// |
| 418 |
// Function: CCoverageBuffer::FillEdgesAlternating |
| 419 |
// |
| 420 |
// Synopsis: |
| 421 |
// Given the active edge list for the current scan, do an alternate-mode |
| 422 |
// antialiased fill. |
| 423 |
// |
| 424 |
//------------------------------------------------------------------------- |
| 425 |
pub fn FillEdgesAlternating(&'a self, |
| 426 |
pEdgeActiveList: Ref<CEdge>, |
| 427 |
nSubpixelYCurrent: INT |
| 428 |
) -> HRESULT |
| 429 |
{ |
| 430 |
|
| 431 |
let hr: HRESULT = S_OK; |
| 432 |
let mut pEdgeStart: Ref<CEdge> = (*pEdgeActiveList).Next.get(); |
| 433 |
let mut pEdgeEnd: Ref<CEdge>; |
| 434 |
let mut nSubpixelXLeft: INT; |
| 435 |
let mut nSubpixelXRight: INT; |
| 436 |
|
| 437 |
ASSERTACTIVELIST!(pEdgeActiveList, nSubpixelYCurrent); |
| 438 |
|
| 439 |
while (pEdgeStart.X.get() != INT::MAX) |
| 440 |
{ |
| 441 |
pEdgeEnd = pEdgeStart.Next.get(); |
| 442 |
|
| 443 |
// We skip empty pairs: |
| 444 |
(nSubpixelXLeft = pEdgeStart.X.get()); |
| 445 |
if (nSubpixelXLeft != pEdgeEnd.X.get()) |
| 446 |
{ |
| 447 |
// We now know we have a non-empty interval. Skip any |
| 448 |
// empty interior pairs: |
| 449 |
|
| 450 |
while ({(nSubpixelXRight = pEdgeEnd.X.get()); pEdgeEnd.X == pEdgeEnd.Next.get().X}) |
| 451 |
{ |
| 452 |
pEdgeEnd = pEdgeEnd.Next.get().Next.get(); |
| 453 |
} |
| 454 |
|
| 455 |
debug_assert!((nSubpixelXLeft < nSubpixelXRight) && (nSubpixelXRight < INT::MAX)); |
| 456 |
|
| 457 |
IFC!(self.AddInterval(nSubpixelXLeft, nSubpixelXRight)); |
| 458 |
} |
| 459 |
|
| 460 |
// Prepare for the next iteration: |
| 461 |
pEdgeStart = pEdgeEnd.Next.get(); |
| 462 |
} |
| 463 |
|
| 464 |
//Cleanup: |
| 465 |
return hr |
| 466 |
|
| 467 |
} |
| 468 |
|
| 469 |
//------------------------------------------------------------------------- |
| 470 |
// |
| 471 |
// Function: CCoverageBuffer::FillEdgesWinding |
| 472 |
// |
| 473 |
// Synopsis: |
| 474 |
// Given the active edge list for the current scan, do an alternate-mode |
| 475 |
// antialiased fill. |
| 476 |
// |
| 477 |
//------------------------------------------------------------------------- |
| 478 |
pub fn FillEdgesWinding(&'a self, |
| 479 |
pEdgeActiveList: Ref<CEdge>, |
| 480 |
nSubpixelYCurrent: INT |
| 481 |
) -> HRESULT |
| 482 |
{ |
| 483 |
|
| 484 |
let hr: HRESULT = S_OK; |
| 485 |
let mut pEdgeStart: Ref<CEdge> = pEdgeActiveList.Next.get(); |
| 486 |
let mut pEdgeEnd: Ref<CEdge>; |
| 487 |
let mut nSubpixelXLeft: INT; |
| 488 |
let mut nSubpixelXRight: INT; |
| 489 |
let mut nWindingValue: INT; |
| 490 |
|
| 491 |
ASSERTACTIVELIST!(pEdgeActiveList, nSubpixelYCurrent); |
| 492 |
|
| 493 |
while (pEdgeStart.X.get() != INT::MAX) |
| 494 |
{ |
| 495 |
pEdgeEnd = pEdgeStart.Next.get(); |
| 496 |
|
| 497 |
nWindingValue = pEdgeStart.WindingDirection; |
| 498 |
while ({nWindingValue += pEdgeEnd.WindingDirection; nWindingValue != 0}) |
| 499 |
{ |
| 500 |
pEdgeEnd = pEdgeEnd.Next.get(); |
| 501 |
} |
| 502 |
|
| 503 |
debug_assert!(pEdgeEnd.X.get() != INT::MAX); |
| 504 |
|
| 505 |
// We skip empty pairs: |
| 506 |
|
| 507 |
if ({nSubpixelXLeft = pEdgeStart.X.get(); nSubpixelXLeft != pEdgeEnd.X.get()}) |
| 508 |
{ |
| 509 |
// We now know we have a non-empty interval. Skip any |
| 510 |
// empty interior pairs: |
| 511 |
|
| 512 |
while ({nSubpixelXRight = pEdgeEnd.X.get(); nSubpixelXRight == pEdgeEnd.Next.get().X.get()}) |
| 513 |
{ |
| 514 |
pEdgeStart = pEdgeEnd.Next.get(); |
| 515 |
pEdgeEnd = pEdgeStart.Next.get(); |
| 516 |
|
| 517 |
nWindingValue = pEdgeStart.WindingDirection; |
| 518 |
while ({nWindingValue += pEdgeEnd.WindingDirection; nWindingValue != 0}) |
| 519 |
{ |
| 520 |
pEdgeEnd = pEdgeEnd.Next.get(); |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
debug_assert!((nSubpixelXLeft < nSubpixelXRight) && (nSubpixelXRight < INT::MAX)); |
| 525 |
|
| 526 |
IFC!(self.AddInterval(nSubpixelXLeft, nSubpixelXRight)); |
| 527 |
} |
| 528 |
|
| 529 |
// Prepare for the next iteration: |
| 530 |
|
| 531 |
pEdgeStart = pEdgeEnd.Next.get(); |
| 532 |
} |
| 533 |
|
| 534 |
//Cleanup: |
| 535 |
return hr;//RRETURN(hr); |
| 536 |
} |
| 537 |
|
| 538 |
//------------------------------------------------------------------------- |
| 539 |
// |
| 540 |
// Function: CCoverageBuffer::Initialize |
| 541 |
// |
| 542 |
// Synopsis: Set the coverage buffer to a valid initial state |
| 543 |
// |
| 544 |
//------------------------------------------------------------------------- |
| 545 |
pub fn Initialize(&'a self) |
| 546 |
{ |
| 547 |
self.m_pIntervalBufferBuiltin.m_interval[0].m_nPixelX.set(INT::MIN); |
| 548 |
self.m_pIntervalBufferBuiltin.m_interval[0].m_nCoverage.set(0); |
| 549 |
self.m_pIntervalBufferBuiltin.m_interval[0].m_pNext.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[1])); |
| 550 |
|
| 551 |
self.m_pIntervalBufferBuiltin.m_interval[1].m_nPixelX.set(INT::MAX); |
| 552 |
self.m_pIntervalBufferBuiltin.m_interval[1].m_nCoverage.set(0xdeadbeef); |
| 553 |
self.m_pIntervalBufferBuiltin.m_interval[1].m_pNext.set(unsafe { Ref::null() }); |
| 554 |
|
| 555 |
self.m_pIntervalBufferBuiltin.m_pNext.set(None); |
| 556 |
self.m_pIntervalBufferCurrent.set(Ref::new(&self.m_pIntervalBufferBuiltin)); |
| 557 |
|
| 558 |
self.m_pIntervalStart.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[0])); |
| 559 |
self.m_pIntervalNew.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[2])); |
| 560 |
self.interval_new_index.set(2); |
| 561 |
self.m_pIntervalEndMinus4.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[INTERVAL_BUFFER_NUMBER - 4])); |
| 562 |
self.m_pIntervalLast.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[1])); |
| 563 |
} |
| 564 |
|
| 565 |
//------------------------------------------------------------------------- |
| 566 |
// |
| 567 |
// Function: CCoverageBuffer::Destroy |
| 568 |
// |
| 569 |
// Synopsis: Free all allocated buffers |
| 570 |
// |
| 571 |
//------------------------------------------------------------------------- |
| 572 |
pub fn Destroy(&mut self) |
| 573 |
{ |
| 574 |
// Free the linked-list of allocations (skipping 'm_pIntervalBufferBuiltin', |
| 575 |
// which is built into the class): |
| 576 |
|
| 577 |
|
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
//------------------------------------------------------------------------- |
| 582 |
// |
| 583 |
// Function: CCoverageBuffer::Reset |
| 584 |
// |
| 585 |
// Synopsis: Reset the coverage buffer |
| 586 |
// |
| 587 |
//------------------------------------------------------------------------- |
| 588 |
pub fn Reset(&'a self) |
| 589 |
{ |
| 590 |
// Reset our coverage structure. Point the head back to the tail, |
| 591 |
// and reset where the next new entry will be placed: |
| 592 |
|
| 593 |
self.m_pIntervalBufferBuiltin.m_interval[0].m_pNext.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[1])); |
| 594 |
|
| 595 |
self.m_pIntervalBufferCurrent.set(Ref::new(&self.m_pIntervalBufferBuiltin)); |
| 596 |
self.m_pIntervalNew.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[2])); |
| 597 |
self.interval_new_index.set(2); |
| 598 |
self.m_pIntervalEndMinus4.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[INTERVAL_BUFFER_NUMBER - 4])); |
| 599 |
self.m_pIntervalLast.set(Ref::new(&self.m_pIntervalBufferBuiltin.m_interval[1])); |
| 600 |
} |
| 601 |
|
| 602 |
//------------------------------------------------------------------------- |
| 603 |
// |
| 604 |
// Function: CCoverageBuffer::Grow |
| 605 |
// |
| 606 |
// Synopsis: |
| 607 |
// Grow our interval buffer. |
| 608 |
// |
| 609 |
//------------------------------------------------------------------------- |
| 610 |
fn Grow(&'a self, |
| 611 |
ppIntervalNew: &mut Ref<'a, CCoverageInterval<'a>>, |
| 612 |
ppIntervalEndMinus4: &mut Ref<'a, CCoverageInterval<'a>>, |
| 613 |
interval_new_index: &mut usize |
| 614 |
) -> HRESULT |
| 615 |
{ |
| 616 |
let hr: HRESULT = S_OK; |
| 617 |
let pIntervalBufferNew = (*self.m_pIntervalBufferCurrent.get()).m_pNext.get(); |
| 618 |
|
| 619 |
let pIntervalBufferNew = pIntervalBufferNew.unwrap_or_else(|| |
| 620 |
{ |
| 621 |
let pIntervalBufferNew = self.arena.alloc(Default::default()); |
| 622 |
|
| 623 |
(*pIntervalBufferNew).m_pNext.set(None); |
| 624 |
(*self.m_pIntervalBufferCurrent.get()).m_pNext.set(Some(pIntervalBufferNew)); |
| 625 |
pIntervalBufferNew |
| 626 |
}); |
| 627 |
|
| 628 |
self.m_pIntervalBufferCurrent.set(Ref::new(pIntervalBufferNew)); |
| 629 |
|
| 630 |
self.m_pIntervalNew.set(Ref::new(&(*pIntervalBufferNew).m_interval[2])); |
| 631 |
self.interval_new_index.set(2); |
| 632 |
self.m_pIntervalEndMinus4.set(Ref::new(&(*pIntervalBufferNew).m_interval[INTERVAL_BUFFER_NUMBER - 4])); |
| 633 |
|
| 634 |
*ppIntervalNew = self.m_pIntervalNew.get(); |
| 635 |
*ppIntervalEndMinus4 = self.m_pIntervalEndMinus4.get(); |
| 636 |
*interval_new_index = 2; |
| 637 |
|
| 638 |
return hr; |
| 639 |
} |
| 640 |
|
| 641 |
} |
| 642 |
/* |
| 643 |
impl<'a> Drop for CCoverageBuffer<'a> { |
| 644 |
fn drop(&mut self) { |
| 645 |
self.Destroy(); |
| 646 |
} |
| 647 |
}*/ |