Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c7ea8bbf
authored
Feb 03, 2020
by
ibaker
Committed by
Oliver Woodman
Feb 03, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Reduce the number of allocations in SubtitlePainter.setupTextLayout
PiperOrigin-RevId: 292877661
parent
3a702cf5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
24 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
View file @
c7ea8bbf
...
...
@@ -242,7 +242,10 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@RequiresNonNull
(
"cueText"
)
private
void
setupTextLayout
()
{
CharSequence
cueText
=
this
.
cueText
;
SpannableStringBuilder
cueText
=
this
.
cueText
instanceof
SpannableStringBuilder
?
(
SpannableStringBuilder
)
this
.
cueText
:
new
SpannableStringBuilder
(
this
.
cueText
);
int
parentWidth
=
parentRight
-
parentLeft
;
int
parentHeight
=
parentBottom
-
parentTop
;
...
...
@@ -260,40 +263,36 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// Remove embedded styling or font size if requested.
if
(!
applyEmbeddedStyles
)
{
cueText
=
cueText
.
toString
();
// Equivalent to erasing all spans.
// Remove all spans, regardless of type.
for
(
Object
span
:
cueText
.
getSpans
(
0
,
cueText
.
length
(),
Object
.
class
))
{
cueText
.
removeSpan
(
span
);
}
}
else
if
(!
applyEmbeddedFontSizes
)
{
SpannableStringBuilder
newCueText
=
new
SpannableStringBuilder
(
cueText
);
int
cueLength
=
newCueText
.
length
();
AbsoluteSizeSpan
[]
absSpans
=
newCueText
.
getSpans
(
0
,
cueLength
,
AbsoluteSizeSpan
.
class
);
RelativeSizeSpan
[]
relSpans
=
newCueText
.
getSpans
(
0
,
cueLength
,
RelativeSizeSpan
.
class
);
AbsoluteSizeSpan
[]
absSpans
=
cueText
.
getSpans
(
0
,
cueText
.
length
(),
AbsoluteSizeSpan
.
class
);
for
(
AbsoluteSizeSpan
absSpan
:
absSpans
)
{
newC
ueText
.
removeSpan
(
absSpan
);
c
ueText
.
removeSpan
(
absSpan
);
}
RelativeSizeSpan
[]
relSpans
=
cueText
.
getSpans
(
0
,
cueText
.
length
(),
RelativeSizeSpan
.
class
);
for
(
RelativeSizeSpan
relSpan
:
relSpans
)
{
newC
ueText
.
removeSpan
(
relSpan
);
c
ueText
.
removeSpan
(
relSpan
);
}
cueText
=
newCueText
;
}
else
{
// Apply embedded styles & font size.
if
(
cueTextSizePx
>
0
)
{
// Use a SpannableStringBuilder encompassing the whole cue text to apply the default
// cueTextSizePx.
SpannableStringBuilder
newCueText
=
new
SpannableStringBuilder
(
cueText
);
newCueText
.
setSpan
(
// Use an AbsoluteSizeSpan encompassing the whole text to apply the default cueTextSizePx.
cueText
.
setSpan
(
new
AbsoluteSizeSpan
((
int
)
cueTextSizePx
),
/* start= */
0
,
/* end= */
newC
ueText
.
length
(),
/* end= */
c
ueText
.
length
(),
Spanned
.
SPAN_PRIORITY
);
cueText
=
newCueText
;
}
}
// Remove embedded font color to not destroy edges, otherwise it overrides edge color.
SpannableStringBuilder
cueTextEdge
=
new
SpannableStringBuilder
(
cueText
);
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_OUTLINE
)
{
int
cueLength
=
cueTextEdge
.
length
();
ForegroundColorSpan
[]
foregroundColorSpans
=
cueTextEdge
.
getSpans
(
0
,
cue
Length
,
ForegroundColorSpan
.
class
);
cueTextEdge
.
getSpans
(
0
,
cue
TextEdge
.
length
()
,
ForegroundColorSpan
.
class
);
for
(
ForegroundColorSpan
foregroundColorSpan
:
foregroundColorSpans
)
{
cueTextEdge
.
removeSpan
(
foregroundColorSpan
);
}
...
...
@@ -306,13 +305,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
if
(
Color
.
alpha
(
backgroundColor
)
>
0
)
{
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_NONE
||
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_DROP_SHADOW
)
{
SpannableStringBuilder
newCueText
=
new
SpannableStringBuilder
(
cueText
);
newCueText
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
0
,
newCueText
.
length
(),
Spanned
.
SPAN_PRIORITY
);
cueText
=
newCueText
;
cueText
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
0
,
cueText
.
length
(),
Spanned
.
SPAN_PRIORITY
);
}
else
{
cueTextEdge
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
...
...
@@ -499,4 +493,5 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// equals methods, so we perform one explicitly here.
return
first
==
second
||
(
first
!=
null
&&
first
.
equals
(
second
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment