summaryrefslogtreecommitdiffstats
path: root/gfx
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-05-13 14:36:06 +0000
committerMoonchild <moonchild@palemoon.org>2020-05-20 13:54:11 +0000
commit85b89ee754ea34156ea2c760265e0445121c8ab9 (patch)
treedd96212f2a0e10cb841f991696c7cdbf75f00fb1 /gfx
parent9c006089e10285486fc9b71f1f128202f584fca5 (diff)
downloadUXP-85b89ee754ea34156ea2c760265e0445121c8ab9.tar
UXP-85b89ee754ea34156ea2c760265e0445121c8ab9.tar.gz
UXP-85b89ee754ea34156ea2c760265e0445121c8ab9.tar.lz
UXP-85b89ee754ea34156ea2c760265e0445121c8ab9.tar.xz
UXP-85b89ee754ea34156ea2c760265e0445121c8ab9.zip
Issue #80 - Split out GetShapedWord template function
Diffstat (limited to 'gfx')
-rw-r--r--gfx/thebes/gfxFont-Impl.h80
-rw-r--r--gfx/thebes/gfxFont.cpp66
-rw-r--r--gfx/thebes/gfxTextRun.h1
-rw-r--r--gfx/thebes/moz.build1
4 files changed, 84 insertions, 64 deletions
diff --git a/gfx/thebes/gfxFont-Impl.h b/gfx/thebes/gfxFont-Impl.h
new file mode 100644
index 000000000..0dd84a882
--- /dev/null
+++ b/gfx/thebes/gfxFont-Impl.h
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef GFX_FONT_IMPL_H
+#define GFX_FONT_IMPL_H
+
+#ifdef __GNUC__
+#define GFX_MAYBE_UNUSED __attribute__((unused))
+#else
+#define GFX_MAYBE_UNUSED
+#endif
+
+template<typename T>
+gfxShapedWord*
+gfxFont::GetShapedWord(DrawTarget *aDrawTarget,
+ const T *aText,
+ uint32_t aLength,
+ uint32_t aHash,
+ Script aRunScript,
+ bool aVertical,
+ int32_t aAppUnitsPerDevUnit,
+ uint32_t aFlags,
+ gfxTextPerfMetrics *aTextPerf GFX_MAYBE_UNUSED)
+{
+ // if the cache is getting too big, flush it and start over
+ uint32_t wordCacheMaxEntries =
+ gfxPlatform::GetPlatform()->WordCacheMaxEntries();
+ if (mWordCache->Count() > wordCacheMaxEntries) {
+ NS_WARNING("flushing shaped-word cache");
+ ClearCachedWords();
+ }
+
+ // if there's a cached entry for this word, just return it
+ CacheHashKey key(aText, aLength, aHash,
+ aRunScript,
+ aAppUnitsPerDevUnit,
+ aFlags);
+
+ CacheHashEntry *entry = mWordCache->PutEntry(key);
+ if (!entry) {
+ NS_WARNING("failed to create word cache entry - expect missing text");
+ return nullptr;
+ }
+ gfxShapedWord* sw = entry->mShapedWord.get();
+
+ if (sw) {
+ sw->ResetAge();
+#ifndef RELEASE_OR_BETA
+ if (aTextPerf) {
+ aTextPerf->current.wordCacheHit++;
+ }
+#endif
+ return sw;
+ }
+
+#ifndef RELEASE_OR_BETA
+ if (aTextPerf) {
+ aTextPerf->current.wordCacheMiss++;
+ }
+#endif
+
+ sw = gfxShapedWord::Create(aText, aLength, aRunScript, aAppUnitsPerDevUnit,
+ aFlags);
+ entry->mShapedWord.reset(sw);
+ if (!sw) {
+ NS_WARNING("failed to create gfxShapedWord - expect missing text");
+ return nullptr;
+ }
+
+ DebugOnly<bool> ok =
+ ShapeText(aDrawTarget, aText, 0, aLength, aRunScript, aVertical, sw);
+
+ NS_WARNING_ASSERTION(ok, "failed to shape word - expect garbled text");
+
+ return sw;
+}
+
+#endif // GFX_FONT_IMPL_H \ No newline at end of file
diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp
index 16274c801..a73252759 100644
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gfxFont.h"
+#include "gfxFont-Impl.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/DebugOnly.h"
@@ -2544,70 +2545,7 @@ IsBoundarySpace(char16_t aChar, char16_t aNextChar)
#define GFX_MAYBE_UNUSED
#endif
-template<typename T>
-gfxShapedWord*
-gfxFont::GetShapedWord(DrawTarget *aDrawTarget,
- const T *aText,
- uint32_t aLength,
- uint32_t aHash,
- Script aRunScript,
- bool aVertical,
- int32_t aAppUnitsPerDevUnit,
- uint32_t aFlags,
- gfxTextPerfMetrics *aTextPerf GFX_MAYBE_UNUSED)
-{
- // if the cache is getting too big, flush it and start over
- uint32_t wordCacheMaxEntries =
- gfxPlatform::GetPlatform()->WordCacheMaxEntries();
- if (mWordCache->Count() > wordCacheMaxEntries) {
- NS_WARNING("flushing shaped-word cache");
- ClearCachedWords();
- }
-
- // if there's a cached entry for this word, just return it
- CacheHashKey key(aText, aLength, aHash,
- aRunScript,
- aAppUnitsPerDevUnit,
- aFlags);
-
- CacheHashEntry *entry = mWordCache->PutEntry(key);
- if (!entry) {
- NS_WARNING("failed to create word cache entry - expect missing text");
- return nullptr;
- }
- gfxShapedWord* sw = entry->mShapedWord.get();
-
- if (sw) {
- sw->ResetAge();
-#ifndef RELEASE_OR_BETA
- if (aTextPerf) {
- aTextPerf->current.wordCacheHit++;
- }
-#endif
- return sw;
- }
-
-#ifndef RELEASE_OR_BETA
- if (aTextPerf) {
- aTextPerf->current.wordCacheMiss++;
- }
-#endif
-
- sw = gfxShapedWord::Create(aText, aLength, aRunScript, aAppUnitsPerDevUnit,
- aFlags);
- entry->mShapedWord.reset(sw);
- if (!sw) {
- NS_WARNING("failed to create gfxShapedWord - expect missing text");
- return nullptr;
- }
-
- DebugOnly<bool> ok =
- ShapeText(aDrawTarget, aText, 0, aLength, aRunScript, aVertical, sw);
-
- NS_WARNING_ASSERTION(ok, "failed to shape word - expect garbled text");
-
- return sw;
-}
+/* GetShapedWord is in gfxFont-Impl.h */
bool
gfxFont::CacheHashEntry::KeyEquals(const KeyTypePointer aKey) const
diff --git a/gfx/thebes/gfxTextRun.h b/gfx/thebes/gfxTextRun.h
index c3673785c..3c9ded1dc 100644
--- a/gfx/thebes/gfxTextRun.h
+++ b/gfx/thebes/gfxTextRun.h
@@ -11,6 +11,7 @@
#include "nsString.h"
#include "gfxPoint.h"
#include "gfxFont.h"
+#include "gfxFont-Impl.h"
#include "gfxFontConstants.h"
#include "nsTArray.h"
#include "gfxSkipChars.h"
diff --git a/gfx/thebes/moz.build b/gfx/thebes/moz.build
index b2396bceb..4201dea29 100644
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -17,6 +17,7 @@ EXPORTS += [
'gfxDrawable.h',
'gfxEnv.h',
'gfxFailure.h',
+ 'gfxFont-Impl.h',
'gfxFont.h',
'gfxFontConstants.h',
'gfxFontEntry.h',