Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(585)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/ShapeResultBloberizer.cpp

Issue 2714413003: Remove GlyphBuffer (Closed)
Patch Set: format Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/fonts/shaping/ShapeResultBloberizer.h"
6
7 #include "platform/fonts/Font.h"
8 #include "platform/fonts/shaping/CachingWordShaper.h"
9 #include "platform/text/TextRun.h"
10
11 namespace blink {
12
13 ShapeResultBloberizer::ShapeResultBloberizer(const Font& font,
14 float deviceScaleFactor,
15 Type type)
16 : m_font(font), m_deviceScaleFactor(deviceScaleFactor), m_type(type) {}
17
18 bool ShapeResultBloberizer::hasPendingVerticalOffsets() const {
19 // We exclusively store either horizontal/x-only ofssets -- in which case
20 // m_offsets.size == size, or vertical/xy offsets -- in which case
21 // m_offsets.size == size * 2.
22 DCHECK(m_pendingGlyphs.size() == m_pendingOffsets.size() ||
23 m_pendingGlyphs.size() * 2 == m_pendingOffsets.size());
24 return m_pendingGlyphs.size() != m_pendingOffsets.size();
25 }
26
27 void ShapeResultBloberizer::commitPendingRun() {
28 if (m_pendingGlyphs.isEmpty())
29 return;
30
31 const auto pendingRotation = blobRotation(m_pendingFontData);
32 if (pendingRotation != m_builderRotation) {
33 // The pending run rotation doesn't match the current blob; start a new
34 // blob.
35 commitPendingBlob();
36 m_builderRotation = pendingRotation;
37 }
38
39 SkPaint runPaint;
40 runPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
41 m_pendingFontData->platformData().setupPaint(&runPaint, m_deviceScaleFactor,
42 &m_font);
43
44 const auto runSize = m_pendingGlyphs.size();
45 const auto& buffer = hasPendingVerticalOffsets()
46 ? m_builder.allocRunPos(runPaint, runSize)
47 : m_builder.allocRunPosH(runPaint, runSize, 0);
48
49 std::copy(m_pendingGlyphs.begin(), m_pendingGlyphs.end(), buffer.glyphs);
50 std::copy(m_pendingOffsets.begin(), m_pendingOffsets.end(), buffer.pos);
51
52 m_builderRunCount += 1;
53 m_pendingGlyphs.shrink(0);
54 m_pendingOffsets.shrink(0);
55 }
56
57 void ShapeResultBloberizer::commitPendingBlob() {
58 if (!m_builderRunCount)
59 return;
60
61 m_blobs.emplace_back(m_builder.make(), m_builderRotation);
62 m_builderRunCount = 0;
63 }
64
65 const ShapeResultBloberizer::BlobBuffer& ShapeResultBloberizer::blobs() {
66 commitPendingRun();
67 commitPendingBlob();
68 DCHECK(m_pendingGlyphs.isEmpty());
69 DCHECK_EQ(m_builderRunCount, 0u);
70
71 return m_blobs;
72 }
73
74 ShapeResultBloberizer::BlobRotation ShapeResultBloberizer::blobRotation(
75 const SimpleFontData* fontData) {
76 // For vertical upright text we need to compensate the inherited 90deg CW
77 // rotation (using a 90deg CCW rotation).
78 return (fontData->platformData().isVerticalAnyUpright() &&
79 fontData->verticalData())
80 ? BlobRotation::CCWRotation
81 : BlobRotation::NoRotation;
82 }
83
84 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698