SkISize SkPatchUtils::GetLevelOfDetail(const SkPoint cubics[12], const SkMatrix* matrix) { // Approximate length of each cubic. SkPoint pts[kNumPtsCubic]; SkPatchUtils::getTopCubic(cubics, pts); matrix->mapPoints(pts, kNumPtsCubic); SkScalar topLength = approx_arc_length(pts, kNumPtsCubic); SkPatchUtils::getBottomCubic(cubics, pts); matrix->mapPoints(pts, kNumPtsCubic); SkScalar bottomLength = approx_arc_length(pts, kNumPtsCubic); SkPatchUtils::getLeftCubic(cubics, pts); matrix->mapPoints(pts, kNumPtsCubic); SkScalar leftLength = approx_arc_length(pts, kNumPtsCubic); SkPatchUtils::getRightCubic(cubics, pts); matrix->mapPoints(pts, kNumPtsCubic); SkScalar rightLength = approx_arc_length(pts, kNumPtsCubic); // Level of detail per axis, based on the larger side between top and bottom or left and right int lodX = static_cast<int>(SkMaxScalar(topLength, bottomLength) / kPartitionSize); int lodY = static_cast<int>(SkMaxScalar(leftLength, rightLength) / kPartitionSize); return SkISize::Make(SkMax32(8, lodX), SkMax32(8, lodY)); }
static void toString(const void* text, size_t byteLen, SkPaint::TextEncoding enc, SkString* str) { // FIXME: this code appears to be untested - and probably unused - and probably wrong switch (enc) { case SkPaint::kUTF8_TextEncoding: str->appendf("\"%.*s\"%s", SkMax32(byteLen, 32), (const char*) text, byteLen > 32 ? "..." : ""); break; case SkPaint::kUTF16_TextEncoding: str->appendf("\"%.*ls\"%s", SkMax32(byteLen, 32), (const wchar_t*) text, byteLen > 64 ? "..." : ""); break; case SkPaint::kUTF32_TextEncoding: str->appendf("\"%.*ls\"%s", SkMax32(byteLen, 32), (const wchar_t*) text, byteLen > 128 ? "..." : ""); break; case SkPaint::kGlyphID_TextEncoding: str->append("<glyphs>"); break; default: SkASSERT(false); break; } }
static unsigned color_dist16(uint16_t a, uint16_t b) { unsigned dr = SkAbs32(SkPacked16ToR32(a) - SkPacked16ToR32(b)); unsigned dg = SkAbs32(SkPacked16ToG32(a) - SkPacked16ToG32(b)); unsigned db = SkAbs32(SkPacked16ToB32(a) - SkPacked16ToB32(b)); return SkMax32(dr, SkMax32(dg, db)); }
static uint16_t lighten_modeproc16_255(SkPMColor src, uint16_t dst) { SkASSERT(require_255(src)); unsigned r = SkMax32(SkPacked32ToR16(src), SkGetPackedR16(dst)); unsigned g = SkMax32(SkPacked32ToG16(src), SkGetPackedG16(dst)); unsigned b = SkMax32(SkPacked32ToB16(src), SkGetPackedB16(dst)); return SkPackRGB16(r, g, b); }
uint32_t* SkWriter32::reserve(size_t size) { SkASSERT(SkAlign4(size) == size); if (fSingleBlock) { uint32_t* ptr = (uint32_t*)(fSingleBlock + fSize); fSize += size; SkASSERT(fSize <= fSingleBlockSize); return ptr; } Block* block = fTail; if (NULL == block) { SkASSERT(NULL == fHead); fHead = fTail = block = Block::Create(SkMax32(size, fMinSize)); } else if (block->available() < size) { fTail = Block::Create(SkMax32(size, fMinSize)); block->fNext = fTail; block = fTail; } fSize += size; return block->alloc(size); }
void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { SkASSERT(!bounds.isEmpty()); SkIRect dilatedBounds = bounds; dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); dilatedBounds.offset(fInfo.fOffset); if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) { return; } // Note: SkIRects are non-inclusive of the right() column and bottom() row, // hence the "-1"s in the computations of maxTileX and maxTileY. int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fInfo.fTileInterval.width(), fXTileCount - 1), 0); int maxTileX = SkMax32(SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInterval.width(), fXTileCount - 1), 0); int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fInfo.fTileInterval.height(), fYTileCount -1), 0); int maxTileY = SkMax32(SkMin32((dilatedBounds.bottom() -1) / fInfo.fTileInterval.height(), fYTileCount -1), 0); for (int x = minTileX; x <= maxTileX; x++) { for (int y = minTileY; y <= maxTileY; y++) { this->tile(x, y).push(data); } } fInsertionCount++; }
void SkTileGrid::insert(void* data, const SkRect& fbounds, bool) { SkASSERT(!fbounds.isEmpty()); SkIRect dilatedBounds; if (fbounds.isLargest()) { // Dilating the largest SkIRect will overflow. Other nearly-largest rects may overflow too, // but we don't make active use of them like we do the largest. dilatedBounds.setLargest(); } else { fbounds.roundOut(&dilatedBounds); dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); dilatedBounds.offset(fInfo.fOffset); } const SkIRect gridBounds = { 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.height() * fYTiles }; if (!SkIRect::Intersects(dilatedBounds, gridBounds)) { return; } // Note: SkIRects are non-inclusive of the right() column and bottom() row, // hence the "-1"s in the computations of maxX and maxY. int minX = SkMax32(0, SkMin32(dilatedBounds.left() / fInfo.fTileInterval.width(), fXTiles - 1)); int minY = SkMax32(0, SkMin32(dilatedBounds.top() / fInfo.fTileInterval.height(), fYTiles - 1)); int maxX = SkMax32(0, SkMin32((dilatedBounds.right() - 1) / fInfo.fTileInterval.width(), fXTiles - 1)); int maxY = SkMax32(0, SkMin32((dilatedBounds.bottom() - 1) / fInfo.fTileInterval.height(), fYTiles - 1)); Entry entry = { fCount++, data }; for (int y = minY; y <= maxY; y++) { for (int x = minX; x <= maxX; x++) { fTiles[y * fXTiles + x].push(entry); } } }
/** Trim A/B/C down so that they are all <= 32bits and then call SkFindUnitQuadRoots() */ static int Sk64FindFixedQuadRoots(const Sk64& A, const Sk64& B, const Sk64& C, SkFixed roots[2]) { int na = A.shiftToMake32(); int nb = B.shiftToMake32(); int nc = C.shiftToMake32(); int shift = SkMax32(na, SkMax32(nb, nc)); SkASSERT(shift >= 0); return SkFindUnitQuadRoots(A.getShiftRight(shift), B.getShiftRight(shift), C.getShiftRight(shift), roots); }
// returns 0..255 static unsigned color_dist32(SkPMColor c, U8CPU r, U8CPU g, U8CPU b) { SkASSERT(r <= 0xFF); SkASSERT(g <= 0xFF); SkASSERT(b <= 0xFF); unsigned dr = SkAbs32(SkGetPackedR32(c) - r); unsigned dg = SkAbs32(SkGetPackedG32(c) - g); unsigned db = SkAbs32(SkGetPackedB32(c) - b); return SkMax32(dr, SkMax32(dg, db)); }
// returns 0..31 static unsigned color_dist16(uint16_t c, unsigned r, unsigned g, unsigned b) { SkASSERT(r <= SK_R16_MASK); SkASSERT(g <= SK_G16_MASK); SkASSERT(b <= SK_B16_MASK); unsigned dr = SkAbs32(SkGetPackedR16(c) - r); unsigned dg = SkAbs32(SkGetPackedG16(c) - g) >> (SK_G16_BITS - SK_R16_BITS); unsigned db = SkAbs32(SkGetPackedB16(c) - b); return SkMax32(dr, SkMax32(dg, db)); }
// returns 0..15 static unsigned color_dist4444(uint16_t c, unsigned r, unsigned g, unsigned b) { SkASSERT(r <= 0xF); SkASSERT(g <= 0xF); SkASSERT(b <= 0xF); unsigned dr = SkAbs32(SkGetPackedR4444(c) - r); unsigned dg = SkAbs32(SkGetPackedG4444(c) - g); unsigned db = SkAbs32(SkGetPackedB4444(c) - b); return SkMax32(dr, SkMax32(dg, db)); }
void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool printing) { if (paintingDisabled()) return; if (width <= 0) return; int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); SkRect r; r.fLeft = WebCoreFloatToSkScalar(pt.x()); // Avoid anti-aliasing lines. Currently, these are always horizontal. r.fTop = WebCoreFloatToSkScalar(floorf(pt.y())); r.fRight = r.fLeft + WebCoreFloatToSkScalar(width); r.fBottom = r.fTop + SkIntToScalar(thickness); SkPaint paint; platformContext()->setupPaintForFilling(&paint); // Text lines are drawn using the stroke color. paint.setColor(platformContext()->effectiveStrokeColor()); platformContext()->canvas()->drawRect(r, paint); platformContext()->didDrawRect(r, paint); }
void GraphicsContext::drawLineForText(const IntPoint& pt, int width, bool printing) { if (paintingDisabled()) return; if (width <= 0) return; platformContext()->prepareForSoftwareDraw(); int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); SkRect r; r.fLeft = SkIntToScalar(pt.x()); r.fTop = SkIntToScalar(pt.y()); r.fRight = r.fLeft + SkIntToScalar(width); r.fBottom = r.fTop + SkIntToScalar(thickness); SkPaint paint; platformContext()->setupPaintForFilling(&paint); // Text lines are drawn using the stroke color. paint.setColor(platformContext()->effectiveStrokeColor()); platformContext()->canvas()->drawRect(r, paint); }
SkGLTextCache::Strike::Strike(Strike* next, int width, int height) { fStrikeWidth = SkNextPow2(SkMax32(kMinStrikeWidth, width)); fStrikeHeight = SkNextPow2(height); fGlyphCount = 0; fNextFreeOffsetX = 0; fNext = next; fStrikeWidthShift = SkNextLog2(fStrikeWidth); fStrikeHeightShift = SkNextLog2(fStrikeHeight); if (next) { SkASSERT(next->fStrikeHeight == fStrikeHeight); } // create an empty texture to receive glyphs fTexName = 0; glGenTextures(1, &fTexName); glBindTexture(GL_TEXTURE_2D, fTexName); glTexImage2D(GL_TEXTURE_2D, 0, gTextTextureFormat, fStrikeWidth, fStrikeHeight, 0, gTextTextureFormat, gTextTextureType, NULL); SK_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); SK_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); SK_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); SK_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); }
void SkProgressView::onDraw(SkCanvas* canvas) { if (fMax == 0) return; SkFixed percent; if (fInterp) { SkScalar x; if (fInterp->timeToValues(SkTime::GetMSecs(), &x) == SkInterpolator::kFreezeEnd_Result) { delete fInterp; fInterp = NULL; } percent = (SkFixed)x; // now its 16.8 percent = SkMax32(0, SkMin32(percent, fMax << 8)); // now its pinned percent = SkFixedDiv(percent, fMax << 8); // now its 0.16 this->inval(NULL); } else { U16CPU value = SkMax32(0, SkMin32(fValue, fMax)); percent = SkFixedDiv(value, fMax); } SkRect r; SkPaint p; r.set(0, 0, this->width(), this->height()); p.setAntiAlias(true); r.fRight = r.fLeft + SkScalarMul(r.width(), SkFixedToScalar(percent)); p.setStyle(SkPaint::kFill_Style); p.setColor(SK_ColorDKGRAY); p.setShader(fOnShader); canvas->drawRect(r, p); p.setColor(SK_ColorWHITE); p.setShader(fOffShader); r.fLeft = r.fRight; r.fRight = this->width() - SK_Scalar1; if (r.width() > 0) canvas->drawRect(r, p); }
static void pack3xHToLCD32(const SkBitmap& src, const SkMask& dst) { SkASSERT(SkBitmap::kA8_Config == src.config()); SkASSERT(SkMask::kLCD32_Format == dst.fFormat); const int width = dst.fBounds.width(); const int height = dst.fBounds.height(); SkPMColor* dstP = (SkPMColor*)dst.fImage; size_t dstRB = dst.fRowBytes; for (int y = 0; y < height; ++y) { const uint8_t* srcP = src.getAddr8(0, y); for (int x = 0; x < width; ++x) { unsigned r = *srcP++; unsigned g = *srcP++; unsigned b = *srcP++; unsigned a = SkMax32(SkMax32(r, g), b); dstP[x] = SkPackARGB32(a, r, g, b); } dstP = (SkPMColor*)((char*)dstP + dstRB); } }
void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { SkASSERT(!bounds.isEmpty()); SkIRect dilatedBounds = bounds; dilatedBounds.outset(1,1); // Consideration for filtering and AA if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) { return; } int minTileX = SkMax32(SkMin32(dilatedBounds.left() / fTileWidth, fXTileCount - 1), 0); int maxTileX = SkMax32(SkMin32(dilatedBounds.right() / fTileWidth, fXTileCount - 1), 0); int minTileY = SkMax32(SkMin32(dilatedBounds.top() / fTileHeight, fYTileCount -1), 0); int maxTileY = SkMax32(SkMin32(dilatedBounds.bottom() / fTileHeight, fYTileCount -1), 0); for (int x = minTileX; x <= maxTileX; x++) { for (int y = minTileY; y <= maxTileY; y++) { this->tile(x, y).push(data); } } fInsertionCount++; }
void* ThreadSafePipeController::requestBlock(size_t minRequest, size_t *actual) { if (fBlock) { // Save the previous block for later PipeBlock previousBloc(fBlock, fBytesWritten); fBlockList.push(previousBloc); } int32_t blockSize = SkMax32(SkToS32(minRequest), kMinBlockSize); fBlock = fAllocator.allocThrow(blockSize); fBytesWritten = 0; *actual = blockSize; return fBlock; }
void SkGridView::moveSelectionUp() { if (fSource) { int index = fCurrIndex; if (index < 0) // no selection index = fSource->countRows() - 1; else index = SkMax32(index - 1, 0); this->setSelection(index); } }
void SkRGBToHSV(U8CPU r, U8CPU g, U8CPU b, SkScalar hsv[3]) { SkASSERT(hsv); unsigned min = SkMin32(r, SkMin32(g, b)); unsigned max = SkMax32(r, SkMax32(g, b)); unsigned delta = max - min; SkScalar v = ByteToScalar(max); SkASSERT(v >= 0 && v <= SK_Scalar1); if (0 == delta) { // we're a shade of gray hsv[0] = 0; hsv[1] = 0; hsv[2] = v; return; } SkScalar s = ByteDivToScalar(delta, max); SkASSERT(s >= 0 && s <= SK_Scalar1); SkScalar h; if (r == max) { h = ByteDivToScalar(g - b, delta); } else if (g == max) { h = SkIntToScalar(2) + ByteDivToScalar(b - r, delta); } else { // b == max h = SkIntToScalar(4) + ByteDivToScalar(r - g, delta); } h *= 60; if (h < 0) { h += SkIntToScalar(360); } SkASSERT(h >= 0 && h < SkIntToScalar(360)); hsv[0] = h; hsv[1] = s; hsv[2] = v; }
static void blit_lcd16_opaque(SkPMColor dst[], const uint16_t src[], SkPMColor color, int width) { int srcR = SkGetPackedR32(color); int srcG = SkGetPackedG32(color); int srcB = SkGetPackedB32(color); for (int i = 0; i < width; i++) { uint16_t mask = src[i]; if (0 == mask) { continue; } SkPMColor d = dst[i]; /* We want all of these in 5bits, hence the shifts in case one of them * (green) is 6bits. */ int maskR = SkGetPackedR16(mask) >> (SK_R16_BITS - 5); int maskG = SkGetPackedG16(mask) >> (SK_G16_BITS - 5); int maskB = SkGetPackedB16(mask) >> (SK_B16_BITS - 5); // Now upscale them to 0..256, so we can use SkAlphaBlend maskR = upscale31To32(maskR); maskG = upscale31To32(maskG); maskB = upscale31To32(maskB); int maskA = SkMax32(SkMax32(maskR, maskG), maskB); int dstA = SkGetPackedA32(d); int dstR = SkGetPackedR32(d); int dstG = SkGetPackedG32(d); int dstB = SkGetPackedB32(d); dst[i] = SkPackARGB32(blend32(0xFF, dstA, maskA), blend32(srcR, dstR, maskR), blend32(srcG, dstG, maskG), blend32(srcB, dstB, maskB)); } }
void SkPatchGrid::draw(SkCanvas* canvas, SkPaint& paint) { int* maxCols = new int[fCols]; int* maxRows = new int[fRows]; memset(maxCols, 0, fCols * sizeof(int)); memset(maxRows, 0, fRows * sizeof(int)); // Get the maximum level of detail per axis for each row and column for (int y = 0; y < fRows; y++) { for (int x = 0; x < fCols; x++) { SkPoint cubics[12]; this->getPatch(x, y, cubics, NULL, NULL); SkMatrix matrix = canvas->getTotalMatrix(); SkISize lod = SkPatchUtils::GetLevelOfDetail(cubics, &matrix); maxCols[x] = SkMax32(maxCols[x], lod.width()); maxRows[y] = SkMax32(maxRows[y], lod.height()); } } // Draw the patches by generating their geometry with the maximum level of detail per axis. for (int x = 0; x < fCols; x++) { for (int y = 0; y < fRows; y++) { SkPoint cubics[12]; SkPoint texCoords[4]; SkColor colors[4]; this->getPatch(x, y, cubics, colors, texCoords); SkPatchUtils::VertexData data; if (SkPatchUtils::getVertexData(&data, cubics, fModeFlags & kColors_VertexType ? colors : NULL, fModeFlags & kTexs_VertexType ? texCoords : NULL, maxCols[x], maxRows[y])) { canvas->drawVertices(SkCanvas::kTriangles_VertexMode, data.fVertexCount, data.fPoints, data.fTexCoords, data.fColors, fXferMode, data.fIndices, data.fIndexCount, paint); } } } delete[] maxCols; delete[] maxRows; }
static void test_srcover_hack(skiatest::Reporter* reporter) { /* Here's the idea. Can we ensure that when we blend on top of an opaque dst, that the result always stay's opaque (i.e. exactly 255)? */ unsigned i; int opaqueCounter0 = 0; int opaqueCounter1 = 0; int opaqueCounter2 = 0; for (i = 0; i <= 255; i++) { unsigned result0 = test_srcover0(0xFF, i); unsigned result1 = test_srcover1(0xFF, i); unsigned result2 = test_srcover2(0xFF, i); opaqueCounter0 += (result0 == 0xFF); opaqueCounter1 += (result1 == 0xFF); opaqueCounter2 += (result2 == 0xFF); } #if 0 SkDebugf("---- opaque test: [%d %d %d]\n", opaqueCounter0, opaqueCounter1, opaqueCounter2); #endif // we acknowledge that technique0 does not always return opaque REPORTER_ASSERT(reporter, opaqueCounter0 == 256); REPORTER_ASSERT(reporter, opaqueCounter1 == 256); REPORTER_ASSERT(reporter, opaqueCounter2 == 256); // Now ensure that we never over/underflow a byte for (i = 0; i <= 255; i++) { for (unsigned dst = 0; dst <= 255; dst++) { unsigned r0 = test_srcover0(dst, i); unsigned r1 = test_srcover1(dst, i); unsigned r2 = test_srcover2(dst, i); unsigned max = SkMax32(dst, i); // ignore the known failure if (dst != 255) { REPORTER_ASSERT(reporter, r0 <= 255 && r0 >= max); } REPORTER_ASSERT(reporter, r1 <= 255 && r1 >= max); REPORTER_ASSERT(reporter, r2 <= 255 && r2 >= max); #if 0 // this shows where r1 (faster) differs from r2 (more exact) if (r1 != r2) { SkDebugf("--- dst=%d i=%d r1=%d r2=%d exact=%g\n", dst, i, r1, r2, i + dst - dst*i/255.0f); } #endif } } }
static void blit_lcd32_opaque(SkPMColor dst[], const uint32_t src[], SkPMColor color, int width) { int srcR = SkGetPackedR32(color); int srcG = SkGetPackedG32(color); int srcB = SkGetPackedB32(color); for (int i = 0; i < width; i++) { uint32_t mask = src[i]; if (0 == mask) { continue; } SkPMColor d = dst[i]; int maskR = SkGetPackedR32(mask); int maskG = SkGetPackedG32(mask); int maskB = SkGetPackedB32(mask); // Now upscale them to 0..256, so we can use SkAlphaBlend maskR = SkAlpha255To256(maskR); maskG = SkAlpha255To256(maskG); maskB = SkAlpha255To256(maskB); int maskA = SkMax32(SkMax32(maskR, maskG), maskB); int dstA = SkGetPackedA32(d); int dstR = SkGetPackedR32(d); int dstG = SkGetPackedG32(d); int dstB = SkGetPackedB32(d); dst[i] = SkPackARGB32(SkAlphaBlend(0xFF, dstA, maskA), SkAlphaBlend(srcR, dstR, maskR), SkAlphaBlend(srcG, dstG, maskG), SkAlphaBlend(srcB, dstB, maskB)); } }
static void toString(const void* text, size_t len, SkPaint::TextEncoding enc, SkString* str) { switch (enc) { case SkPaint::kUTF8_TextEncoding: str->printf("\"%.*s\"%s", SkMax32(len, 32), text, len > 32 ? "..." : ""); break; case SkPaint::kUTF16_TextEncoding: str->printf("\"%.*S\"%s", SkMax32(len, 32), text, len > 64 ? "..." : ""); break; case SkPaint::kUTF32_TextEncoding: str->printf("\"%.*S\"%s", SkMax32(len, 32), text, len > 128 ? "..." : ""); break; case SkPaint::kGlyphID_TextEncoding: str->set("<glyphs>"); break; default: SkASSERT(false); break; } }
virtual void onDraw(SkCanvas*) { int n = (int)(N * this->innerLoopScale()); n = SkMax32(1, n); for (int i = 0; i < n; i++) { SkPicture picture; SkCanvas* pCanvas = picture.beginRecording(PICTURE_WIDTH, PICTURE_HEIGHT); recordCanvas(pCanvas); // we don't need to draw the picture as the endRecording step will // do the work of transferring the recorded content into a playback // object. picture.endRecording(); } }
bool SkListView::moveSelectionUp() { if (fSource) { int index = fCurrIndex; if (index < 0) // no selection index = fSource->countRecords() - 1; else index = SkMax32(index - 1, 0); if (fCurrIndex != index) { this->setSelection(index); return true; } } return false; }
static void print(const SkTDArray<DrawType>& expected, const SkTDArray<DrawType>& actual) { SkDebugf("\n\nexpected %d --- actual %d\n", expected.count(), actual.count()); int max = SkMax32(expected.count(), actual.count()); for (int i = 0; i < max; ++i) { if (i < expected.count()) { SkDebugf("%16s, ", SkDrawCommand::GetCommandString(expected[i])); } else { SkDebugf("%16s, ", " "); } if (i < actual.count()) { SkDebugf("%s\n", SkDrawCommand::GetCommandString(actual[i])); } else { SkDebugf("\n"); } } SkDebugf("\n\n"); SkASSERT(0); }
SkChunkAlloc::Block* SkChunkAlloc::newBlock(size_t bytes, AllocFailType ftype) { Block* block = fPool; if (block && bytes <= block->fFreeSize) { fPool = block->fNext; return block; } size_t size = SkMax32((int32_t)bytes, (int32_t)fMinSize); block = (Block*)sk_malloc_flags(sizeof(Block) + size, ftype == kThrow_AllocFailType ? SK_MALLOC_THROW : 0); if (block) { // block->fNext = fBlock; block->fFreeSize = size; block->fFreePtr = block->startOfData(); fTotalCapacity += size; } return block; }
void SkSliderView::onDraw(SkCanvas* canvas) { this->INHERITED::onDraw(canvas); U16CPU value = SkMax32(0, SkMin32(fValue, fMax)); SkRect r; SkPaint p; r.set(0, 0, this->width(), this->height()); p.setAntiAliasOn(true); p.setStyle(SkPaint::kStroke_Style); p.setStrokeWidth(SK_Scalar1); r.inset(SK_Scalar1/2, SK_Scalar1/2); canvas->drawRect(r, p); if (fMax) { SkFixed percent = SkFixedDiv(value, fMax); r.inset(SK_Scalar1/2, SK_Scalar1/2); r.fRight = r.fLeft + SkScalarMul(r.width(), SkFixedToScalar(percent)); p.setStyle(SkPaint::kFill_Style); setgrad(&p, r); canvas->drawRect(r, p); } #if 0 r.set(0, 0, this->width(), this->height()); r.inset(SK_Scalar1, SK_Scalar1); r.inset(r.width()/2, 0); p.setColor(SK_ColorBLACK); canvas->drawLine(*(SkPoint*)&r.fLeft, *(SkPoint*)&r.fRight, p); #endif }