From 7db9fe65b2bb099e9dc41f79cc15b6a7a142bed6 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 11 Apr 2011 11:57:54 +0000 Subject: [PATCH] code style git-svn-id: http://skia.googlecode.com/svn/trunk@1096 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkGraphics.cpp | 246 +------------------------------------------ src/core/SkScalerContext.cpp | 122 ++++++++++----------- 2 files changed, 58 insertions(+), 310 deletions(-) diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp index 40f0ea3..8638504 100644 --- a/src/core/SkGraphics.cpp +++ b/src/core/SkGraphics.cpp @@ -37,48 +37,8 @@ #include "SkUtils.h" #include "SkXfermode.h" -#if 0 - -#define SK_SORT_TEMPLATE_TYPE int -#define SK_SORT_TEMPLATE_NAME sort_int -#define SK_SORT_TEMPLATE_CMP(a, b) ((a) - (b)) -#include "SkSortTemplate.h" - -#define SK_SORT_TEMPLATE_TYPE int* -#define SK_SORT_TEMPLATE_NAME sort_intptr -#define SK_SORT_TEMPLATE_CMP(a, b) (*(a) - *(b)) -#include "SkSortTemplate.h" - -static void test_sort() -{ - int array[] = { 4, 3, 7, 5, 2, 5, 1, 2, 9, 6, 7, 4, 5, 3, 1, 0 }; - int* ptr[SK_ARRAY_COUNT(array)]; - int i, N = SK_ARRAY_COUNT(array) - 1; - - for (i = 0; i < N; i++) - printf(" %d", array[i]); - printf("\n"); - - for (i = 0; i < N; i++) - ptr[i] = &array[i]; - sort_intptr(ptr, N); - for (i = 0; i < N; i++) - printf(" %d", *ptr[i]); - printf("\n"); - - sort_int(array, N); - for (i = 0; i < N; i++) - printf(" %d", array[i]); - printf("\n"); - -} -#endif - -#define SPEED_TESTx - #define typesizeline(type) { #type , sizeof(type) } - #ifdef BUILD_EMBOSS_TABLE extern void SkEmbossMask_BuildTable(); #endif @@ -87,65 +47,6 @@ static void test_sort() extern void SkRadialGradient_BuildTable(); #endif -#define BIG_LOOP_COUNT 1000000 -#define TEXT_LOOP_COUNT 1000 - -#ifdef SPEED_TEST -static int test_s64(int i) -{ - Sk64 a, b, c; - - c.set(0); - a.set(i); - b.setMul(i, i); - a.add(b); - a.add(c); - return c.getFixed(); -} - -static int test_native_64(int i) -{ - int16_t a, b, c; - - c = 0; - a = i; - b = (int64_t)i * i; - a += b; - a += c; - return (int)(c >> 16); -} - -static void test_drawText(SkBitmap::Config config, SkColor color) -{ - SkBitmap bm; - - bm.setConfig(config, 320, 240); - bm.allocPixels(); - - SkCanvas canvas(bm); - SkPaint paint; - - paint.setAntiAlias(true); - paint.setTextSize(SkIntToScalar(12)); - paint.setColor(color); - - SkScalar x = SkIntToScalar(20); - SkScalar y = SkIntToScalar(100); - const char* text = "Hamburgefons"; - size_t len = strlen(text); - - // draw once to populate the cache - canvas.drawText(text, len, x, y, paint); - - SkMSec now = SkTime::GetMSecs(); - for (int i = 0; i < TEXT_LOOP_COUNT; i++) - canvas.drawText(text, len, x, y, paint); - printf("----------- Config: %d, Color=%x, CPS = %g\n", config, color, - len * TEXT_LOOP_COUNT * 1000.0 / (SkTime::GetMSecs() - now)); -} - -#endif - void SkGraphics::Init() { SkGlobals::Init(); @@ -210,154 +111,9 @@ void SkGraphics::Init() { } #endif - - if (false) // test asm fixmul - { - int j; - SkMSec now = SkTime::GetMSecs(); - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkFixedMul_portable(0x8000, 0x150000); - } - SkMSec now2 = SkTime::GetMSecs(); - printf("-------- SkFixedMul_portable = %d\n", now2 - now); - - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkFixedMul(0x8000, 0x150000); - } - printf("-------- SkFixedMul = %d\n", SkTime::GetMSecs() - now2); - - SkRandom rand; - for (j = 0; j < 10000; j++) { - SkFixed a = rand.nextS() >> 8; - SkFixed b = rand.nextS() >> 8; - SkFixed c1 = SkFixedMul_portable(a, b); - SkFixed c2 = SkFixedMul(a, b); - if (SkAbs32(c1 - c2) > 1) - printf("------ FixMul disagreement: (%x %x) slow=%x fast=%x\n", a, b, c1, c2); - } - } - - if (false) // test asm fractmul - { - int j; - SkMSec now = SkTime::GetMSecs(); - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkFractMul_portable(0x800000, 0x1500000); - } - SkMSec now2 = SkTime::GetMSecs(); - printf("-------- SkFractMul_portable = %d\n", now2 - now); - - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkFractMul(0x800000, 0x1500000); - } - printf("-------- SkFractMul = %d\n", SkTime::GetMSecs() - now2); - - SkRandom rand; - for (j = 0; j < 10000; j++) { - SkFixed a = rand.nextS() >> 1; - SkFixed b = rand.nextS() >> 1; - SkFixed c1 = SkFractMul_portable(a, b); - SkFixed c2 = SkFractMul(a, b); - if (SkAbs32(c1 - c2) > 1) - printf("------ FractMul disagreement: (%x %x) slow=%x fast=%x\n", a, b, c1, c2); - } - } - - if (false) // test asm clz - { - int j; - SkMSec now = SkTime::GetMSecs(); - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkCLZ_portable(now); - } - SkMSec now2 = SkTime::GetMSecs(); - printf("-------- SkCLZ_portable = %d\n", now2 - now); - - for (j = 0; j < BIG_LOOP_COUNT; j++) { - (void)SkCLZ(now); - } - printf("-------- SkCLZ = %d\n", SkTime::GetMSecs() - now2); - - SkRandom rand; - for (j = 0; j < 10000; j++) { - uint32_t a = rand.nextU(); - int c1 = SkCLZ_portable(a); - int c2 = SkCLZ(a); - if (c1 != c2) - printf("------ CLZ disagreement: (%x) slow=%x fast=%x\n", a, c1, c2); - } - } - -#ifdef SPEED_TEST - if (false) { - int i; - int (*proc)(int); - - static const struct { - int (*proc)(int); - const char* name; - } gList[] = { - { test_s64, "Sk64" }, - { test_native_64, "native" } - }; - - for (size_t j = 0; j < SK_ARRAY_COUNT(gList); j++) { - SkMSec now = SkTime::GetMSecs(); - proc = gList[j].proc; - for (i = 0; i < BIG_LOOP_COUNT; i++) { - proc(i); - } - printf("-------- %s = %d\n", gList[j].name, SkTime::GetMSecs() - now); - } - } -#endif - - if (false) { - size_t i, size = 480; - char* buffer = (char*)sk_malloc_throw(size); - uint16_t* buffer16 = (uint16_t*)buffer; - uint32_t* buffer32 = (uint32_t*)buffer; - - SkMSec now = SkTime::GetMSecs(); - for (i = 0; i < 100000; i++) { - sk_memset16(buffer16, (uint16_t)i, size >> 1); - } - SkMSec now2 = SkTime::GetMSecs(); - for (i = 0; i < 100000; i++) { - sk_memset16_portable(buffer16, (uint16_t)i, size >> 1); - } - SkMSec now3 = SkTime::GetMSecs(); - printf("----------- memset16: native %d, portable %d\n", now2 - now, now3 - now2); - - now = SkTime::GetMSecs(); - for (i = 0; i < 100000; i++) { - sk_memset32(buffer32, i, size >> 2); - } - now2 = SkTime::GetMSecs(); - for (i = 0; i < 100000; i++) { - sk_memset32_portable(buffer32, i, size >> 2); - } - now3 = SkTime::GetMSecs(); - printf("----------- memset32: native %d, portable %d\n", now2 - now, now3 - now2); - - sk_free(buffer); - } - -#ifdef SPEED_TEST - if (false) { - test_drawText(SkBitmap::kARGB_8888_Config, SK_ColorBLACK); - test_drawText(SkBitmap::kARGB_8888_Config, SK_ColorRED); - test_drawText(SkBitmap::kRGB_565_Config, SK_ColorBLACK); - test_drawText(SkBitmap::kRGB_565_Config, SK_ColorRED); - } -#endif - -// if (true) { -// test_sort(); -// } } -//////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// #include "SkGlyphCache.h" diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index ff8e168..6b5f663 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -27,10 +27,6 @@ #include "SkStroke.h" #include "SkThread.h" -#ifdef SK_DEBUG -// #define TRACK_MISSING_CHARS -#endif - #define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3) static const uint8_t* gBlackGammaTable; @@ -49,14 +45,14 @@ size_t SkGlyph::computeImageSize() const { const size_t size = this->rowBytes() * fHeight; switch (fMaskFormat) { - case SkMask::kHorizontalLCD_Format: - return SkAlign4(size) + sizeof(uint32_t) * ((fWidth + 2) * fHeight); - case SkMask::kVerticalLCD_Format: - return SkAlign4(size) + sizeof(uint32_t) * (fWidth * (fHeight + 2)); - case SkMask::k3D_Format: - return 3 * size; - default: - return size; + case SkMask::kHorizontalLCD_Format: + return SkAlign4(size) + sizeof(uint32_t) * ((fWidth + 2) * fHeight); + case SkMask::kVerticalLCD_Format: + return SkAlign4(size) + sizeof(uint32_t) * (fWidth * (fHeight + 2)); + case SkMask::k3D_Format: + return 3 * size; + default: + return size; } } @@ -154,14 +150,16 @@ SkScalerContext::SkScalerContext(const SkDescriptor* desc) #ifdef DUMP_REC desc->assertChecksum(); - SkDebugf("SkScalarContext checksum %x count %d length %d\n", desc->getChecksum(), desc->getCount(), desc->getLength()); + SkDebugf("SkScalarContext checksum %x count %d length %d\n", + desc->getChecksum(), desc->getCount(), desc->getLength()); SkDebugf(" textsize %g prescale %g preskew %g post [%g %g %g %g]\n", rec->fTextSize, rec->fPreScaleX, rec->fPreSkewX, rec->fPost2x2[0][0], rec->fPost2x2[0][1], rec->fPost2x2[1][0], rec->fPost2x2[1][1]); SkDebugf(" frame %g miter %g hints %d framefill %d format %d join %d\n", rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill, rec->fMaskFormat, rec->fStrokeJoin); - SkDebugf(" pathEffect %x maskFilter %x\n", desc->findEntry(kPathEffect_SkDescriptorTag, NULL), + SkDebugf(" pathEffect %x maskFilter %x\n", + desc->findEntry(kPathEffect_SkDescriptorTag, NULL), desc->findEntry(kMaskFilter_SkDescriptorTag, NULL)); #endif @@ -452,8 +450,9 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) { draw.drawPath(devPath, paint); } - if (lcdMode) + if (lcdMode) { glyph->expandA8ToLCD(); + } } else { this->getGlyphContext(*glyph)->generateImage(*glyph); } @@ -501,28 +500,26 @@ void SkScalerContext::getImage(const SkGlyph& origGlyph) { (fRec.fFlags & (kGammaForBlack_Flag | kGammaForWhite_Flag)) != 0) { const uint8_t* table = (fRec.fFlags & kGammaForBlack_Flag) ? gBlackGammaTable : gWhiteGammaTable; - if (NULL != table) - { + if (NULL != table) { uint8_t* dst = (uint8_t*)origGlyph.fImage; unsigned rowBytes = origGlyph.rowBytes(); - for (int y = origGlyph.fHeight - 1; y >= 0; --y) - { - for (int x = origGlyph.fWidth - 1; x >= 0; --x) + for (int y = origGlyph.fHeight - 1; y >= 0; --y) { + for (int x = origGlyph.fWidth - 1; x >= 0; --x) { dst[x] = table[dst[x]]; + } dst += rowBytes; } } } } -void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) -{ +void SkScalerContext::getPath(const SkGlyph& glyph, SkPath* path) { this->internalGetPath(glyph, NULL, path, NULL); } -void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* mx, SkPaint::FontMetrics* my) -{ +void SkScalerContext::getFontMetrics(SkPaint::FontMetrics* mx, + SkPaint::FontMetrics* my) { this->generateFontMetrics(mx, my); } @@ -530,16 +527,15 @@ SkUnichar SkScalerContext::generateGlyphToChar(uint16_t glyph) { return 0; } -/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, SkPath* devPath, SkMatrix* fillToDevMatrix) -{ +void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, + SkPath* devPath, SkMatrix* fillToDevMatrix) { SkPath path; this->getGlyphContext(glyph)->generatePath(glyph, &path); - if (fRec.fFrameWidth > 0 || fPathEffect != NULL) - { + if (fRec.fFrameWidth > 0 || fPathEffect != NULL) { // need the path in user-space, with only the point-size applied // so that our stroking and effects will operate the same way they // would if the user had extracted the path themself, and then @@ -554,16 +550,15 @@ void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, Sk SkScalar width = fRec.fFrameWidth; - if (fPathEffect) - { + if (fPathEffect) { SkPath effectPath; - if (fPathEffect->filterPath(&effectPath, localPath, &width)) + if (fPathEffect->filterPath(&effectPath, localPath, &width)) { localPath.swap(effectPath); + } } - if (width > 0) - { + if (width > 0) { SkStroke stroker; SkPath outline; @@ -576,41 +571,42 @@ void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath, Sk } // now return stuff to the caller - if (fillToDevMatrix) + if (fillToDevMatrix) { *fillToDevMatrix = matrix; - - if (devPath) + } + if (devPath) { localPath.transform(matrix, devPath); - - if (fillPath) + } + if (fillPath) { fillPath->swap(localPath); - } - else // nothing tricky to do - { - if (fillToDevMatrix) + } + } else { // nothing tricky to do + if (fillToDevMatrix) { fillToDevMatrix->reset(); - - if (devPath) - { - if (fillPath == NULL) + } + if (devPath) { + if (fillPath == NULL) { devPath->swap(path); - else + } else { *devPath = path; + } } - if (fillPath) + if (fillPath) { fillPath->swap(path); + } } - if (devPath) + if (devPath) { devPath->updateBoundsCache(); - if (fillPath) + } + if (fillPath) { fillPath->updateBoundsCache(); + } } -void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const -{ +void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const { dst->reset(); dst->setScaleX(fPost2x2[0][0]); dst->setSkewX( fPost2x2[0][1]); @@ -618,23 +614,20 @@ void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const dst->setScaleY(fPost2x2[1][1]); } -void SkScalerContext::Rec::getLocalMatrix(SkMatrix* m) const -{ +void SkScalerContext::Rec::getLocalMatrix(SkMatrix* m) const { m->setScale(SkScalarMul(fTextSize, fPreScaleX), fTextSize); - if (fPreSkewX) + if (fPreSkewX) { m->postSkew(fPreSkewX, 0); + } } -void SkScalerContext::Rec::getSingleMatrix(SkMatrix* m) const -{ +void SkScalerContext::Rec::getSingleMatrix(SkMatrix* m) const { this->getLocalMatrix(m); // now concat the device matrix - { - SkMatrix deviceMatrix; - this->getMatrixFrom2x2(&deviceMatrix); - m->postConcat(deviceMatrix); - } + SkMatrix deviceMatrix; + this->getMatrixFrom2x2(&deviceMatrix); + m->postConcat(deviceMatrix); } /////////////////////////////////////////////////////////////////////////////// @@ -673,8 +666,7 @@ protected: extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); -SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) -{ +SkScalerContext* SkScalerContext::Create(const SkDescriptor* desc) { SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); if (NULL == c) { c = SkFontHost::CreateScalerContext(desc); -- 2.7.4