1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkAlphaRuns.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2006 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 +#include "SkAntiRun.h" 1.14 +#include "SkUtils.h" 1.15 + 1.16 +void SkAlphaRuns::reset(int width) { 1.17 + SkASSERT(width > 0); 1.18 + 1.19 +#ifdef SK_DEBUG 1.20 + sk_memset16((uint16_t*)fRuns, (uint16_t)(-42), width); 1.21 +#endif 1.22 + fRuns[0] = SkToS16(width); 1.23 + fRuns[width] = 0; 1.24 + fAlpha[0] = 0; 1.25 + 1.26 + SkDEBUGCODE(fWidth = width;) 1.27 + SkDEBUGCODE(this->validate();) 1.28 +} 1.29 + 1.30 +#ifdef SK_DEBUG 1.31 + void SkAlphaRuns::assertValid(int y, int maxStep) const { 1.32 + int max = (y + 1) * maxStep - (y == maxStep - 1); 1.33 + 1.34 + const int16_t* runs = fRuns; 1.35 + const uint8_t* alpha = fAlpha; 1.36 + 1.37 + while (*runs) { 1.38 + SkASSERT(*alpha <= max); 1.39 + alpha += *runs; 1.40 + runs += *runs; 1.41 + } 1.42 + } 1.43 + 1.44 + void SkAlphaRuns::dump() const { 1.45 + const int16_t* runs = fRuns; 1.46 + const uint8_t* alpha = fAlpha; 1.47 + 1.48 + SkDebugf("Runs"); 1.49 + while (*runs) { 1.50 + int n = *runs; 1.51 + 1.52 + SkDebugf(" %02x", *alpha); 1.53 + if (n > 1) { 1.54 + SkDebugf(",%d", n); 1.55 + } 1.56 + alpha += n; 1.57 + runs += n; 1.58 + } 1.59 + SkDebugf("\n"); 1.60 + } 1.61 + 1.62 + void SkAlphaRuns::validate() const { 1.63 + SkASSERT(fWidth > 0); 1.64 + 1.65 + int count = 0; 1.66 + const int16_t* runs = fRuns; 1.67 + 1.68 + while (*runs) { 1.69 + SkASSERT(*runs > 0); 1.70 + count += *runs; 1.71 + SkASSERT(count <= fWidth); 1.72 + runs += *runs; 1.73 + } 1.74 + SkASSERT(count == fWidth); 1.75 + } 1.76 +#endif