From: benjaminwagner Date: Wed, 24 Feb 2016 16:29:11 +0000 (-0800) Subject: Revert of Simple cleanups related to SkFixed. (patchset #4 id:120001 of https://coder... X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~1858 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c2d35d851365bb89f392fe2dd7af57e169de26b7;p=platform%2Fupstream%2FlibSkiaSharp.git Revert of Simple cleanups related to SkFixed. (patchset #4 id:120001 of https://codereview.chromium.org/1683743005/ ) Reason for revert: New test is failing on Windows. Original issue's description: > Cleanups related to SkFixed. > > Remove SK_FixedNaN. It does not seem to be supported or used anywhere in Skia, Chromium, Android, or Google3, (except accidentally by TwoPtRadial::kDontDrawT). I think supporting it would erase any benefit of SkFixed over float. > > Remove SkBitmapFilter::lookup. It does not appear to be used anywhere in Skia, Chromium, Android, or Google3. > > Fix a bug in SkPaint::breakText that limited it to ~5kB of text. Now it can handle more than 1GB. > > BUG=skia:4632 > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1683743005 > > Committed: https://skia.googlesource.com/skia/+/7ea5cb18389db11a94175de95c9db2b44972630c TBR=mtklein@google.com,reed@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:4632 Review URL: https://codereview.chromium.org/1724283003 --- diff --git a/include/core/SkFixed.h b/include/core/SkFixed.h index 1541e32..f6dd3d6 100644 --- a/include/core/SkFixed.h +++ b/include/core/SkFixed.h @@ -22,6 +22,7 @@ typedef int32_t SkFixed; #define SK_FixedHalf (1 << 15) #define SK_FixedMax (0x7FFFFFFF) #define SK_FixedMin (-SK_FixedMax) +#define SK_FixedNaN ((int) 0x80000000) #define SK_FixedPI (0x3243F) #define SK_FixedSqrt2 (92682) #define SK_FixedTanPIOver8 (0x6A0A) diff --git a/include/core/SkRect.h b/include/core/SkRect.h index 3ebe099..4f649b7 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -463,7 +463,8 @@ struct SK_API SkRect { /** * Returns true iff all values in the rect are finite. If any are - * infinite or NaN then this returns false. + * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this + * returns false. */ bool isFinite() const { float accum = 0; diff --git a/samplecode/SampleText.cpp b/samplecode/SampleText.cpp index 87ca914..f5f8dbe 100644 --- a/samplecode/SampleText.cpp +++ b/samplecode/SampleText.cpp @@ -27,6 +27,41 @@ #include "SkStream.h" #include "SkXMLParser.h" +static void test_breakText() { + SkPaint paint; + const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; + size_t length = strlen(text); + SkScalar width = paint.measureText(text, length); + + SkScalar mm = 0; + SkScalar nn = 0; + for (SkScalar w = 0; w <= width; w += SK_Scalar1) { + SkScalar m; + size_t n = paint.breakText(text, length, w, &m); + + SkASSERT(n <= length); + SkASSERT(m <= width); + + if (n == 0) { + SkASSERT(m == 0); + } else { + // now assert that we're monotonic + if (n == nn) { + SkASSERT(m == mm); + } else { + SkASSERT(n > nn); + SkASSERT(m > mm); + } + } + nn = SkIntToScalar((unsigned int)n); + mm = m; + } + + SkDEBUGCODE(size_t length2 =) paint.breakText(text, length, width, &mm); + SkASSERT(length2 == length); + SkASSERT(mm == width); +} + static const struct { const char* fName; uint32_t fFlags; @@ -74,6 +109,8 @@ public: TextSpeedView() { fHints = 0; fClickX = 0; + + test_breakText(); } protected: diff --git a/src/core/SkBitmapFilter.h b/src/core/SkBitmapFilter.h index ca3e093..6fa8edd 100644 --- a/src/core/SkBitmapFilter.h +++ b/src/core/SkBitmapFilter.h @@ -28,6 +28,15 @@ public: } virtual ~SkBitmapFilter() {} + SkFixed lookup(float x) const { + if (!fPrecomputed) { + precomputeTable(); + } + int filter_idx = int(sk_float_abs(x * fLookupMultiplier)); + SkASSERT(filter_idx < SKBITMAP_FILTER_TABLE_SIZE); + return fFilterTable[filter_idx]; + } + SkScalar lookupScalar(float x) const { if (!fPrecomputed) { precomputeTable(); @@ -58,16 +67,19 @@ protected: float fLookupMultiplier; mutable bool fPrecomputed; + mutable SkFixed fFilterTable[SKBITMAP_FILTER_TABLE_SIZE]; mutable SkScalar fFilterTableScalar[SKBITMAP_FILTER_TABLE_SIZE]; private: void precomputeTable() const { fPrecomputed = true; + SkFixed *ftp = fFilterTable; SkScalar *ftpScalar = fFilterTableScalar; for (int x = 0; x < SKBITMAP_FILTER_TABLE_SIZE; ++x) { float fx = ((float)x + .5f) * this->width() / SKBITMAP_FILTER_TABLE_SIZE; float filter_value = evaluate(fx); *ftpScalar++ = filter_value; + *ftp++ = SkFloatToFixed(filter_value); } } }; diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 638e251..d3384a6 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -925,7 +925,7 @@ size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth, GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(false); const int xyIndex = paint.isVerticalText() ? 1 : 0; // use 64bits for our accumulator, to avoid overflowing 16.16 - Sk48Dot16 max = SkScalarTo48Dot16(maxWidth); + Sk48Dot16 max = SkScalarToFixed(maxWidth); Sk48Dot16 width = 0; SkAutoKern autokern; diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h index 954b096..f468de8 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient.h +++ b/src/effects/gradients/SkTwoPointConicalGradient.h @@ -15,7 +15,6 @@ // Should only be initialized once via init(). Immutable afterwards. struct TwoPtRadial { enum { - // This value is outside the range SK_FixedMin to SK_FixedMax. kDontDrawT = 0x80000000 }; diff --git a/tests/PaintBreakTextTest.cpp b/tests/PaintBreakTextTest.cpp deleted file mode 100644 index 67a1d2f..0000000 --- a/tests/PaintBreakTextTest.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2011-2016 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkPaint.h" -#include "Test.h" - -static void test_monotonic(skiatest::Reporter* reporter, - const SkPaint& paint, - const char* msg) { - const char* text = "sdfkljAKLDFJKEWkldfjlk#$%&sdfs.dsj"; - const size_t length = strlen(text); - const SkScalar width = paint.measureText(text, length); - - SkScalar mm = 0; - size_t nn = 0; - const SkScalar step = SkMaxScalar(width / 10, SK_Scalar1); - for (SkScalar w = 0; w <= width; w += step) { - SkScalar m; - const size_t n = paint.breakText(text, length, w, &m); - - REPORTER_ASSERT_MESSAGE(reporter, n <= length, msg); - REPORTER_ASSERT_MESSAGE(reporter, m <= width, msg); - - if (n == 0) { - REPORTER_ASSERT_MESSAGE(reporter, m == 0, msg); - } else { - // now assert that we're monotonic - if (n == nn) { - REPORTER_ASSERT_MESSAGE(reporter, m == mm, msg); - } else { - REPORTER_ASSERT_MESSAGE(reporter, n > nn, msg); - REPORTER_ASSERT_MESSAGE(reporter, m > mm, msg); - } - } - nn = n; - mm = m; - } -} - -static void test_eq_measure_text(skiatest::Reporter* reporter, - const SkPaint& paint, - const char* msg) { - const char* text = "The ultimate measure of a man is not where he stands in moments of comfort " - "and convenience, but where he stands at times of challenge and controversy."; - const size_t length = strlen(text); - const SkScalar width = paint.measureText(text, length); - - SkScalar mm; - const size_t length2 = paint.breakText(text, length, width, &mm); - REPORTER_ASSERT_MESSAGE(reporter, length2 == length, msg); - REPORTER_ASSERT_MESSAGE(reporter, mm == width, msg); -} - -static void test_long_text(skiatest::Reporter* reporter, - const SkPaint& paint, - const char* msg) { - static const int kSize = 16 * 1024; - SkAutoMalloc block(kSize); - memset(block.get(), 'a', kSize - 1); - char* text = static_cast(block.get()); - text[kSize - 1] = '\0'; - const SkScalar width = paint.measureText(text, kSize); - - SkScalar mm; - const size_t length = paint.breakText(text, kSize, width, &mm); - REPORTER_ASSERT_MESSAGE(reporter, length == kSize, msg); - REPORTER_ASSERT_MESSAGE(reporter, mm == width, msg); -} - -DEF_TEST(PaintBreakText, reporter) { - SkPaint paint; - test_monotonic(reporter, paint, "default"); - test_eq_measure_text(reporter, paint, "default"); - test_long_text(reporter, paint, "default"); - paint.setTextSize(SkIntToScalar(1 << 17)); - test_monotonic(reporter, paint, "huge text size"); - test_eq_measure_text(reporter, paint, "huge text size"); - paint.setTextSize(0); - test_monotonic(reporter, paint, "zero text size"); - paint.setVerticalText(true); - paint.setTextSize(SkIntToScalar(100)); - test_monotonic(reporter, paint, "vertical"); - test_eq_measure_text(reporter, paint, "vertical"); -}