Commit 616a8e65 authored by scottmg's avatar scottmg Committed by Commit bot

Fixes for two different HUD issues related to win32k lockdown

1. Using a GDI bitmap -- switch to SkSurface instead

2. Lazily loading a font. This breaks for two different reasons.
The first is a DCHECK for doing IO on the Compositor thread. This
could have been just ignored in general since it's only for debug
usage, the drawbacks of minor jank are limited.

However, once lockdown is on, the font load hard fails from the
renderer. So, load the typeface before lockdown and pass it into
CC and the hud via LayerTreeSettings.

R=danakj@chromium.org
BUG=453731,455104
TEST=run chrome with --enable-win32k-renderer-lockdown --show-fps-counter --ui-show-fps-counter on Win8

Review URL: https://codereview.chromium.org/900063002

Cr-Commit-Position: refs/heads/master@{#314929}
parent 3ea07aad
...@@ -69,11 +69,10 @@ double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() { ...@@ -69,11 +69,10 @@ double HeadsUpDisplayLayerImpl::Graph::UpdateUpperBound() {
HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl, HeadsUpDisplayLayerImpl::HeadsUpDisplayLayerImpl(LayerTreeImpl* tree_impl,
int id) int id)
: LayerImpl(tree_impl, id), : LayerImpl(tree_impl, id),
typeface_(skia::AdoptRef(
SkTypeface::CreateFromName("monospace", SkTypeface::kBold))),
fps_graph_(60.0, 80.0), fps_graph_(60.0, 80.0),
paint_time_graph_(16.0, 48.0), paint_time_graph_(16.0, 48.0),
fade_step_(0) {} fade_step_(0) {
}
HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {} HeadsUpDisplayLayerImpl::~HeadsUpDisplayLayerImpl() {}
...@@ -173,36 +172,36 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture( ...@@ -173,36 +172,36 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture(
return; return;
SkISize canvas_size; SkISize canvas_size;
if (hud_canvas_) if (hud_surface_)
canvas_size = hud_canvas_->getDeviceSize(); canvas_size = hud_surface_->getCanvas()->getDeviceSize();
else else
canvas_size.set(0, 0); canvas_size.set(0, 0);
if (canvas_size.width() != content_bounds().width() || if (canvas_size.width() != content_bounds().width() ||
canvas_size.height() != content_bounds().height() || !hud_canvas_) { canvas_size.height() != content_bounds().height() || !hud_surface_) {
TRACE_EVENT0("cc", "ResizeHudCanvas"); TRACE_EVENT0("cc", "ResizeHudCanvas");
bool opaque = false;
hud_canvas_ = make_scoped_ptr(skia::CreateBitmapCanvas( hud_surface_ = skia::AdoptRef(SkSurface::NewRasterN32Premul(
content_bounds().width(), content_bounds().height(), opaque)); content_bounds().width(), content_bounds().height()));
} }
UpdateHudContents(); UpdateHudContents();
{ {
TRACE_EVENT0("cc", "DrawHudContents"); TRACE_EVENT0("cc", "DrawHudContents");
hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); hud_surface_->getCanvas()->clear(SkColorSetARGB(0, 0, 0, 0));
hud_canvas_->save(); hud_surface_->getCanvas()->save();
hud_canvas_->scale(contents_scale_x(), contents_scale_y()); hud_surface_->getCanvas()->scale(contents_scale_x(), contents_scale_y());
DrawHudContents(hud_canvas_.get()); DrawHudContents(hud_surface_->getCanvas());
hud_canvas_->restore(); hud_surface_->getCanvas()->restore();
} }
TRACE_EVENT0("cc", "UploadHudTexture"); TRACE_EVENT0("cc", "UploadHudTexture");
SkImageInfo info; SkImageInfo info;
size_t row_bytes = 0; size_t row_bytes = 0;
const void* pixels = hud_canvas_->peekPixels(&info, &row_bytes); const void* pixels = hud_surface_->getCanvas()->peekPixels(&info, &row_bytes);
DCHECK(pixels); DCHECK(pixels);
gfx::Rect content_rect(content_bounds()); gfx::Rect content_rect(content_bounds());
DCHECK(info.colorType() == kN32_SkColorType); DCHECK(info.colorType() == kN32_SkColorType);
...@@ -300,7 +299,7 @@ void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas, ...@@ -300,7 +299,7 @@ void HeadsUpDisplayLayerImpl::DrawText(SkCanvas* canvas,
paint->setTextSize(size); paint->setTextSize(size);
paint->setTextAlign(align); paint->setTextAlign(align);
paint->setTypeface(typeface_.get()); paint->setTypeface(layer_tree_impl()->settings().hud_typeface.get());
canvas->drawText(text.c_str(), text.length(), x, y, *paint); canvas->drawText(text.c_str(), text.length(), x, y, *paint);
paint->setAntiAlias(anti_alias); paint->setAntiAlias(anti_alias);
...@@ -706,7 +705,7 @@ void HeadsUpDisplayLayerImpl::DrawDebugRect( ...@@ -706,7 +705,7 @@ void HeadsUpDisplayLayerImpl::DrawDebugRect(
SkPaint label_paint = CreatePaint(); SkPaint label_paint = CreatePaint();
label_paint.setTextSize(kFontHeight); label_paint.setTextSize(kFontHeight);
label_paint.setTypeface(typeface_.get()); label_paint.setTypeface(layer_tree_impl()->settings().hud_typeface.get());
label_paint.setColor(stroke_color); label_paint.setColor(stroke_color);
const SkScalar label_text_width = const SkScalar label_text_width =
......
...@@ -126,9 +126,7 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl { ...@@ -126,9 +126,7 @@ class CC_EXPORT HeadsUpDisplayLayerImpl : public LayerImpl {
void ReleaseUnmatchedSizeResources(ResourceProvider* resource_provider); void ReleaseUnmatchedSizeResources(ResourceProvider* resource_provider);
ScopedPtrVector<ScopedResource> resources_; ScopedPtrVector<ScopedResource> resources_;
scoped_ptr<SkCanvas> hud_canvas_; skia::RefPtr<SkSurface> hud_surface_;
skia::RefPtr<SkTypeface> typeface_;
Graph fps_graph_; Graph fps_graph_;
Graph paint_time_graph_; Graph paint_time_graph_;
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "cc/base/cc_export.h" #include "cc/base/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h" #include "cc/debug/layer_tree_debug_state.h"
#include "cc/output/renderer_settings.h" #include "cc/output/renderer_settings.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
namespace cc { namespace cc {
...@@ -83,6 +85,7 @@ class CC_EXPORT LayerTreeSettings { ...@@ -83,6 +85,7 @@ class CC_EXPORT LayerTreeSettings {
bool record_full_layer; bool record_full_layer;
bool use_display_lists; bool use_display_lists;
bool verify_property_trees; bool verify_property_trees;
skia::RefPtr<SkTypeface> hud_typeface;
LayerTreeDebugState initial_debug_state; LayerTreeDebugState initial_debug_state;
}; };
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "third_party/WebKit/public/web/WebKit.h" #include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebWidget.h" #include "third_party/WebKit/public/web/WebWidget.h"
#include "ui/gfx/frame_time.h" #include "ui/gfx/frame_time.h"
#include "ui/gfx/hud_font.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
#include "ui/native_theme/native_theme_switches.h" #include "ui/native_theme/native_theme_switches.h"
...@@ -433,6 +434,8 @@ void RenderWidgetCompositor::Initialize() { ...@@ -433,6 +434,8 @@ void RenderWidgetCompositor::Initialize() {
compositor_deps_->CreateExternalBeginFrameSource(widget_->routing_id()); compositor_deps_->CreateExternalBeginFrameSource(widget_->routing_id());
} }
settings.hud_typeface = ui::GetHudTypeface();
if (compositor_thread_task_runner.get()) { if (compositor_thread_task_runner.get()) {
layer_tree_host_ = cc::LayerTreeHost::CreateThreaded( layer_tree_host_ = cc::LayerTreeHost::CreateThreaded(
this, shared_bitmap_manager, gpu_memory_buffer_manager, settings, this, shared_bitmap_manager, gpu_memory_buffer_manager, settings,
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "third_party/icu/source/i18n/unicode/timezone.h" #include "third_party/icu/source/i18n/unicode/timezone.h"
#include "third_party/skia/include/ports/SkFontMgr.h" #include "third_party/skia/include/ports/SkFontMgr.h"
#include "third_party/skia/include/ports/SkTypeface_win.h" #include "third_party/skia/include/ports/SkTypeface_win.h"
#include "ui/gfx/hud_font.h"
#include "ui/gfx/win/direct_write.h" #include "ui/gfx/win/direct_write.h"
#include "ui/gfx/win/dpi.h" #include "ui/gfx/win/dpi.h"
...@@ -55,10 +56,17 @@ void SkiaPreCacheFontCharacters(const LOGFONT& logfont, ...@@ -55,10 +56,17 @@ void SkiaPreCacheFontCharacters(const LOGFONT& logfont,
void WarmupDirectWrite() { void WarmupDirectWrite() {
// The objects used here are intentionally not freed as we want the Skia // The objects used here are intentionally not freed as we want the Skia
// code to use these objects after warmup. // code to use these objects after warmup.
SetDefaultSkiaFactory(GetPreSandboxWarmupFontMgr());
SkTypeface* typeface = SkTypeface* typeface =
GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0); GetPreSandboxWarmupFontMgr()->legacyCreateTypeface("Times New Roman", 0);
DoPreSandboxWarmupForTypeface(typeface); DoPreSandboxWarmupForTypeface(typeface);
SetDefaultSkiaFactory(GetPreSandboxWarmupFontMgr());
// The CC HUD needs a debug font, we warm that up here and pass it down.
skia::RefPtr<SkTypeface> hud_typeface =
skia::AdoptRef(GetPreSandboxWarmupFontMgr()->legacyCreateTypeface(
"Consolas", SkTypeface::kBold));
DoPreSandboxWarmupForTypeface(hud_typeface.get());
ui::SetHudTypeface(hud_typeface);
} }
} // namespace } // namespace
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator_collection.h" #include "ui/compositor/layer_animator_collection.h"
#include "ui/gfx/frame_time.h" #include "ui/gfx/frame_time.h"
#include "ui/gfx/hud_font.h"
#include "ui/gl/gl_context.h" #include "ui/gl/gl_context.h"
#include "ui/gl/gl_switches.h" #include "ui/gl/gl_switches.h"
...@@ -137,6 +138,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget, ...@@ -137,6 +138,7 @@ Compositor::Compositor(gfx::AcceleratedWidget widget,
settings.impl_side_painting = IsUIImplSidePaintingEnabled(); settings.impl_side_painting = IsUIImplSidePaintingEnabled();
settings.use_zero_copy = IsUIZeroCopyEnabled(); settings.use_zero_copy = IsUIZeroCopyEnabled();
settings.hud_typeface = ui::GetHudTypeface();
base::TimeTicks before_create = base::TimeTicks::Now(); base::TimeTicks before_create = base::TimeTicks::Now();
if (compositor_thread_loop_.get()) { if (compositor_thread_loop_.get()) {
......
...@@ -105,6 +105,8 @@ component("gfx") { ...@@ -105,6 +105,8 @@ component("gfx") {
"gfx_paths.h", "gfx_paths.h",
"gpu_memory_buffer.cc", "gpu_memory_buffer.cc",
"gpu_memory_buffer.h", "gpu_memory_buffer.h",
"hud_font.cc",
"hud_font.h",
"icon_util.cc", "icon_util.cc",
"icon_util.h", "icon_util.h",
"image/canvas_image_source.cc", "image/canvas_image_source.cc",
......
...@@ -182,6 +182,8 @@ ...@@ -182,6 +182,8 @@
'gfx_paths.h', 'gfx_paths.h',
'gpu_memory_buffer.cc', 'gpu_memory_buffer.cc',
'gpu_memory_buffer.h', 'gpu_memory_buffer.h',
'hud_font.cc',
'hud_font.h',
'image/canvas_image_source.cc', 'image/canvas_image_source.cc',
'image/canvas_image_source.h', 'image/canvas_image_source.h',
'image/image.cc', 'image/image.cc',
......
// 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 ui {
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() {
if (!g_hud_typeface.Get()) {
// This will be set pre-sandbox on Windows. On other platforms, just make
// something here.
SetHudTypeface(skia::AdoptRef(
SkTypeface::CreateFromName("monospace", SkTypeface::kBold)));
}
return g_hud_typeface.Get();
}
} // namespace ui
// 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 ui {
GFX_EXPORT void SetHudTypeface(skia::RefPtr<SkTypeface> typeface);
GFX_EXPORT skia::RefPtr<SkTypeface> GetHudTypeface();
} // namespace ui
#endif // UI_GFX_HUD_FONT_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment