summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkulshin <kulshin@chromium.org>2016-02-19 13:36:33 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-19 21:37:12 +0000
commitfeee7f74e0a0cd60d91c1aa3a3968432f1177768 (patch)
tree3211f1d23b4669d2538d95ac9f57e2b6523ba86c
parente7059cfb59c86cb549d2b29cc020b38f1d157d96 (diff)
downloadchromium_src-feee7f74e0a0cd60d91c1aa3a3968432f1177768.zip
chromium_src-feee7f74e0a0cd60d91c1aa3a3968432f1177768.tar.gz
chromium_src-feee7f74e0a0cd60d91c1aa3a3968432f1177768.tar.bz2
Make hud layer initialize its own font.
Make hud layer initialize its own font, rather than relying on a pre-set shared global. This fixes the crash in issue 577663, and as a bonus, allows us to eventually bypass hud font loading if the hud isn't being displayed. BUG=577663 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1714653002 Cr-Commit-Position: refs/heads/master@{#376539}
-rw-r--r--cc/layers/heads_up_display_layer.cc18
-rw-r--r--cc/layers/heads_up_display_layer.h6
-rw-r--r--cc/layers/heads_up_display_layer_impl.cc28
-rw-r--r--cc/layers/heads_up_display_layer_impl.h5
-rw-r--r--content/child/font_warmup_win.cc5
-rw-r--r--ui/gfx/BUILD.gn2
-rw-r--r--ui/gfx/gfx.gyp2
-rw-r--r--ui/gfx/hud_font.cc25
-rw-r--r--ui/gfx/hud_font.h20
9 files changed, 51 insertions, 60 deletions
diff --git a/cc/layers/heads_up_display_layer.cc b/cc/layers/heads_up_display_layer.cc
index fe2aa55..a34ca42 100644
--- a/cc/layers/heads_up_display_layer.cc
+++ b/cc/layers/heads_up_display_layer.cc
@@ -19,7 +19,14 @@ scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create(
}
HeadsUpDisplayLayer::HeadsUpDisplayLayer(const LayerSettings& settings)
- : Layer(settings) {
+ : Layer(settings),
+ typeface_(skia::AdoptRef(
+ SkTypeface::CreateFromName("times new roman", SkTypeface::kNormal))) {
+ if (!typeface_) {
+ typeface_ = skia::AdoptRef(
+ SkTypeface::CreateFromName("monospace", SkTypeface::kBold));
+ }
+ DCHECK(typeface_.get());
SetIsDrawable(true);
UpdateDrawsContent(HasDrawableContent());
}
@@ -67,4 +74,13 @@ void HeadsUpDisplayLayer::SetTypeForProtoSerialization(
proto->set_type(proto::LayerNode::HEADS_UP_DISPLAY_LAYER);
}
+void HeadsUpDisplayLayer::PushPropertiesTo(LayerImpl* layer) {
+ Layer::PushPropertiesTo(layer);
+ TRACE_EVENT0("cc", "HeadsUpDisplayLayer::PushPropertiesTo");
+ HeadsUpDisplayLayerImpl* layer_impl =
+ static_cast<HeadsUpDisplayLayerImpl*>(layer);
+
+ layer_impl->SetHUDTypeface(typeface_);
+}
+
} // namespace cc
diff --git a/cc/layers/heads_up_display_layer.h b/cc/layers/heads_up_display_layer.h
index 554d33e..23b3407a 100644
--- a/cc/layers/heads_up_display_layer.h
+++ b/cc/layers/heads_up_display_layer.h
@@ -11,6 +11,7 @@
#include "base/memory/scoped_ptr.h"
#include "cc/base/cc_export.h"
#include "cc/layers/layer.h"
+#include "third_party/skia/include/core/SkTypeface.h"
namespace cc {
@@ -30,6 +31,9 @@ class CC_EXPORT HeadsUpDisplayLayer : public Layer {
void SetTypeForProtoSerialization(proto::LayerNode* proto) const override;
+ // Layer overrides.
+ void PushPropertiesTo(LayerImpl* layer) override;
+
protected:
explicit HeadsUpDisplayLayer(const LayerSettings& settings);
bool HasDrawableContent() const override;
@@ -37,6 +41,8 @@ class CC_EXPORT HeadsUpDisplayLayer : public Layer {
private:
~HeadsUpDisplayLayer() override;
+ skia::RefPtr<SkTypeface> typeface_;
+
DISALLOW_COPY_AND_ASSIGN(HeadsUpDisplayLayer);
};
diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc
index 035ebc9..55e13e7 100644
--- a/cc/layers/heads_up_display_layer_impl.cc
+++ b/cc/layers/heads_up_display_layer_impl.cc
@@ -32,7 +32,6 @@
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/gfx/hud_font.h"
namespace cc {
@@ -74,15 +73,10 @@ double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl,
int id)
: LayerImpl(tree_impl, id),
- typeface_(gfx::GetHudTypeface()),
internal_contents_scale_(1.f),
fps_graph_(60.0, 80.0),
paint_time_graph_(16.0, 48.0),
fade_step_(0) {
- if (!typeface_) {
- typeface_ = skia::AdoptRef(
- SkTypeface::CreateFromName("monospace", SkTypeface::kBold));
- }
}
HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
@@ -224,6 +218,25 @@ gfx::Rect HeadsUpDisplayLayerImpl::GetEnclosingRectInTargetSpace() const {
return GetScaledEnclosingRectInTargetSpace(internal_contents_scale_);
}
+void HeadsUpDisplayLayerImpl::SetHUDTypeface(
+ const skia::RefPtr<SkTypeface>& typeface) {
+ if (typeface_ == typeface)
+ return;
+
+ DCHECK(typeface_.get() == nullptr);
+ typeface_ = typeface;
+ NoteLayerPropertyChanged();
+}
+
+void HeadsUpDisplayLayerImpl::PushPropertiesTo(LayerImpl* layer) {
+ LayerImpl::PushPropertiesTo(layer);
+
+ HeadsUpDisplayLayerImpl* layer_impl =
+ static_cast<HeadsUpDisplayLayerImpl*>(layer);
+
+ layer_impl->SetHUDTypeface(typeface_);
+}
+
void HeadsUpDisplayLayerImpl::UpdateHudContents() {
const LayerTreeDebugState& debug_state = layer_tree_impl()->debug_state();
@@ -275,6 +288,7 @@ void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) {
int HeadsUpDisplayLayerImpl::MeasureText(SkPaint* paint,
const std::string& text,
int size) const {
+ DCHECK(typeface_.get());
const bool anti_alias = paint->isAntiAlias();
paint->setAntiAlias(true);
paint->setTextSize(size);
@@ -291,6 +305,7 @@ void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
int size,
int x,
int y) const {
+ DCHECK(typeface_.get());
const bool anti_alias = paint->isAntiAlias();
paint->setAntiAlias(true);
@@ -643,6 +658,7 @@ void HeadsUpDisplayLayerImpl::DrawDebugRect(
SkColor fill_color,
float stroke_width,
const std::string& label_text) const {
+ DCHECK(typeface_.get());
gfx::Rect debug_layer_rect =
gfx::ScaleToEnclosingRect(rect.rect, 1.0 / internal_contents_scale_,
1.0 / internal_contents_scale_);
diff --git a/cc/layers/heads_up_display_layer_impl.h b/cc/layers/heads_up_display_layer_impl.h
index 07e4bed..dfe9b0d 100644
--- a/cc/layers/heads_up_display_layer_impl.h
+++ b/cc/layers/heads_up_display_layer_impl.h
@@ -50,6 +50,11 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
bool IsAnimatingHUDContents() const { return fade_step_ > 0; }
+ void SetHUDTypeface(const skia::RefPtr<SkTypeface>& typeface);
+
+ // LayerImpl overrides.
+ void PushPropertiesTo(LayerImpl* layer) override;
+
private:
class Graph {
public:
diff --git a/content/child/font_warmup_win.cc b/content/child/font_warmup_win.cc
index 0769155..33d1807 100644
--- a/content/child/font_warmup_win.cc
+++ b/content/child/font_warmup_win.cc
@@ -30,7 +30,6 @@
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkTypeface_win.h"
-#include "ui/gfx/hud_font.h"
namespace content {
@@ -494,14 +493,12 @@ void WarmupDirectWrite() {
// code to use these objects after warmup.
SetDefaultSkiaFactory(GetPreSandboxWarmupFontMgr());
- // We need to warm up *some* font for DirectWrite. We also need to pass one
- // down for the CC HUD code, so use the same one here. Note that we don't use
+ // We need to warm up *some* font for DirectWrite. Note that we don't use
// a monospace as would be nice in an attempt to avoid a small startup time
// regression, see http://crbug.com/463613.
skia::RefPtr<SkTypeface> hud_typeface = skia::AdoptRef(
GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0));
DoPreSandboxWarmupForTypeface(hud_typeface.get());
- gfx::SetHudTypeface(hud_typeface);
}
} // namespace content
diff --git a/ui/gfx/BUILD.gn b/ui/gfx/BUILD.gn
index d014bd7..8fd50bd3b 100644
--- a/ui/gfx/BUILD.gn
+++ b/ui/gfx/BUILD.gn
@@ -103,8 +103,6 @@ component("gfx") {
"generic_shared_memory_id.h",
"gfx_paths.cc",
"gfx_paths.h",
- "hud_font.cc",
- "hud_font.h",
"icon_util.cc",
"icon_util.h",
"image/image.cc",
diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp
index 4519db9..0d8d2d4 100644
--- a/ui/gfx/gfx.gyp
+++ b/ui/gfx/gfx.gyp
@@ -185,8 +185,6 @@
'gfx_paths.h',
'harfbuzz_font_skia.cc',
'harfbuzz_font_skia.h',
- 'hud_font.cc',
- 'hud_font.h',
'image/canvas_image_source.cc',
'image/canvas_image_source.h',
'image/image.cc',
diff --git a/ui/gfx/hud_font.cc b/ui/gfx/hud_font.cc
deleted file mode 100644
index 8151778..0000000
--- a/ui/gfx/hud_font.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/gfx/hud_font.h"
-
-#include "base/lazy_instance.h"
-#include "third_party/skia/include/core/SkTypeface.h"
-
-namespace gfx {
-
-namespace {
-base::LazyInstance<skia::RefPtr<SkTypeface>> g_hud_typeface;
-} // namespace
-
-void SetHudTypeface(skia::RefPtr<SkTypeface> typeface) {
- g_hud_typeface.Get() = typeface;
-}
-
-skia::RefPtr<SkTypeface> GetHudTypeface() {
- // nullptr is fine; caller will create its own in that case.
- return g_hud_typeface.Get();
-}
-
-} // namespace gfx
diff --git a/ui/gfx/hud_font.h b/ui/gfx/hud_font.h
deleted file mode 100644
index f72a050..0000000
--- a/ui/gfx/hud_font.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef UI_GFX_HUD_FONT_H_
-#define UI_GFX_HUD_FONT_H_
-
-#include "skia/ext/refptr.h"
-#include "ui/gfx/gfx_export.h"
-
-class SkTypeface;
-
-namespace gfx {
-
-GFX_EXPORT void SetHudTypeface(skia::RefPtr<SkTypeface> typeface);
-GFX_EXPORT skia::RefPtr<SkTypeface> GetHudTypeface();
-
-} // namespace gfx
-
-#endif // UI_GFX_HUD_FONT_H_