diff options
author | egraether@chromium.org <egraether@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 14:22:43 +0000 |
---|---|---|
committer | egraether@chromium.org <egraether@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-04 14:22:43 +0000 |
commit | 97cd022eed90162aa4408632322d84d558c18f34 (patch) | |
tree | 552358c92453160b8f3bc403a85d22465adbc0a8 | |
parent | b8794a1aef3a5bf88c8a689af0782f084ba787bf (diff) | |
download | chromium_src-97cd022eed90162aa4408632322d84d558c18f34.zip chromium_src-97cd022eed90162aa4408632322d84d558c18f34.tar.gz chromium_src-97cd022eed90162aa4408632322d84d558c18f34.tar.bz2 |
cc: Fix HudLayer is blurry on high-DPI screens
This change fixes the Hudlayer's resolution on high-DPI screens and
refactors scaling of debug rects and widgets.
BUG=256286
Review URL: https://chromiumcodereview.appspot.com/18348006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210185 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | cc/debug/debug_colors.cc | 46 | ||||
-rw-r--r-- | cc/debug/debug_colors.h | 21 | ||||
-rw-r--r-- | cc/layers/heads_up_display_layer.cc | 38 | ||||
-rw-r--r-- | cc/layers/heads_up_display_layer.h | 4 | ||||
-rw-r--r-- | cc/layers/heads_up_display_layer_impl.cc | 78 |
5 files changed, 73 insertions, 114 deletions
diff --git a/cc/debug/debug_colors.cc b/cc/debug/debug_colors.cc index 5ffa729..e6f3e28 100644 --- a/cc/debug/debug_colors.cc +++ b/cc/debug/debug_colors.cc @@ -167,9 +167,7 @@ SkColor DebugColors::EvictedTileCheckerboardColor() { SkColor DebugColors::PaintRectBorderColor() { return SkColorSetARGB(255, 255, 0, 0); } -int DebugColors::PaintRectBorderWidth(const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::PaintRectBorderWidth() { return 2; } SkColor DebugColors::PaintRectFillColor() { return SkColorSetARGB(30, 255, 0, 0); } @@ -178,10 +176,7 @@ SkColor DebugColors::PaintRectFillColor() { SkColor DebugColors::PropertyChangedRectBorderColor() { return SkColorSetARGB(255, 0, 0, 255); } -int DebugColors::PropertyChangedRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::PropertyChangedRectBorderWidth() { return 2; } SkColor DebugColors::PropertyChangedRectFillColor() { return SkColorSetARGB(30, 0, 0, 255); } @@ -190,9 +185,7 @@ SkColor DebugColors::PropertyChangedRectFillColor() { SkColor DebugColors::SurfaceDamageRectBorderColor() { return SkColorSetARGB(255, 200, 100, 0); } -int DebugColors::SurfaceDamageRectBorderWidth(const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::SurfaceDamageRectBorderWidth() { return 2; } SkColor DebugColors::SurfaceDamageRectFillColor() { return SkColorSetARGB(30, 200, 100, 0); } @@ -201,10 +194,7 @@ SkColor DebugColors::SurfaceDamageRectFillColor() { SkColor DebugColors::ScreenSpaceLayerRectBorderColor() { return SkColorSetARGB(255, 100, 200, 0); } -int DebugColors::ScreenSpaceLayerRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::ScreenSpaceLayerRectBorderWidth() { return 2; } SkColor DebugColors::ScreenSpaceLayerRectFillColor() { return SkColorSetARGB(30, 100, 200, 0); } @@ -213,10 +203,7 @@ SkColor DebugColors::ScreenSpaceLayerRectFillColor() { SkColor DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor() { return SkColorSetARGB(255, 100, 0, 200); } -int DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth() { return 2; } SkColor DebugColors::ScreenSpaceSurfaceReplicaRectFillColor() { return SkColorSetARGB(10, 100, 0, 200); } @@ -225,9 +212,7 @@ SkColor DebugColors::ScreenSpaceSurfaceReplicaRectFillColor() { SkColor DebugColors::OccludingRectBorderColor() { return SkColorSetARGB(255, 245, 136, 255); } -int DebugColors::OccludingRectBorderWidth(const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::OccludingRectBorderWidth() { return 2; } SkColor DebugColors::OccludingRectFillColor() { return SkColorSetARGB(10, 245, 136, 255); } @@ -236,9 +221,7 @@ SkColor DebugColors::OccludingRectFillColor() { SkColor DebugColors::NonOccludingRectBorderColor() { return SkColorSetARGB(255, 200, 0, 100); } -int DebugColors::NonOccludingRectBorderWidth(const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::NonOccludingRectBorderWidth() { return 2; } SkColor DebugColors::NonOccludingRectFillColor() { return SkColorSetARGB(10, 200, 0, 100); } @@ -247,10 +230,7 @@ SkColor DebugColors::NonOccludingRectFillColor() { SkColor DebugColors::TouchEventHandlerRectBorderColor() { return SkColorSetARGB(255, 239, 229, 60); } -int DebugColors::TouchEventHandlerRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::TouchEventHandlerRectBorderWidth() { return 2; } SkColor DebugColors::TouchEventHandlerRectFillColor() { return SkColorSetARGB(30, 239, 229, 60); } @@ -259,10 +239,7 @@ SkColor DebugColors::TouchEventHandlerRectFillColor() { SkColor DebugColors::WheelEventHandlerRectBorderColor() { return SkColorSetARGB(255, 189, 209, 57); } -int DebugColors::WheelEventHandlerRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::WheelEventHandlerRectBorderWidth() { return 2; } SkColor DebugColors::WheelEventHandlerRectFillColor() { return SkColorSetARGB(30, 189, 209, 57); } @@ -271,10 +248,7 @@ SkColor DebugColors::WheelEventHandlerRectFillColor() { SkColor DebugColors::NonFastScrollableRectBorderColor() { return SkColorSetARGB(255, 238, 163, 59); } -int DebugColors::NonFastScrollableRectBorderWidth( - const LayerTreeImpl* tree_impl) { - return Scale(2, tree_impl); -} +int DebugColors::NonFastScrollableRectBorderWidth() { return 2; } SkColor DebugColors::NonFastScrollableRectFillColor() { return SkColorSetARGB(30, 238, 163, 59); } diff --git a/cc/debug/debug_colors.h b/cc/debug/debug_colors.h index be2cf8d..a1335e3 100644 --- a/cc/debug/debug_colors.h +++ b/cc/debug/debug_colors.h @@ -67,44 +67,43 @@ class DebugColors { static SkColor InvalidatedTileCheckerboardColor(); static SkColor PaintRectBorderColor(); - static int PaintRectBorderWidth(const LayerTreeImpl* tree_impl); + static int PaintRectBorderWidth(); static SkColor PaintRectFillColor(); static SkColor PropertyChangedRectBorderColor(); - static int PropertyChangedRectBorderWidth(const LayerTreeImpl* tree_impl); + static int PropertyChangedRectBorderWidth(); static SkColor PropertyChangedRectFillColor(); static SkColor SurfaceDamageRectBorderColor(); - static int SurfaceDamageRectBorderWidth(const LayerTreeImpl* tree_impl); + static int SurfaceDamageRectBorderWidth(); static SkColor SurfaceDamageRectFillColor(); static SkColor ScreenSpaceLayerRectBorderColor(); - static int ScreenSpaceLayerRectBorderWidth(const LayerTreeImpl* tree_impl); + static int ScreenSpaceLayerRectBorderWidth(); static SkColor ScreenSpaceLayerRectFillColor(); static SkColor ScreenSpaceSurfaceReplicaRectBorderColor(); - static int ScreenSpaceSurfaceReplicaRectBorderWidth( - const LayerTreeImpl* tree_impl); + static int ScreenSpaceSurfaceReplicaRectBorderWidth(); static SkColor ScreenSpaceSurfaceReplicaRectFillColor(); static SkColor OccludingRectBorderColor(); - static int OccludingRectBorderWidth(const LayerTreeImpl* tree_impl); + static int OccludingRectBorderWidth(); static SkColor OccludingRectFillColor(); static SkColor NonOccludingRectBorderColor(); - static int NonOccludingRectBorderWidth(const LayerTreeImpl* tree_impl); + static int NonOccludingRectBorderWidth(); static SkColor NonOccludingRectFillColor(); static SkColor TouchEventHandlerRectBorderColor(); - static int TouchEventHandlerRectBorderWidth(const LayerTreeImpl* tree_impl); + static int TouchEventHandlerRectBorderWidth(); static SkColor TouchEventHandlerRectFillColor(); static SkColor WheelEventHandlerRectBorderColor(); - static int WheelEventHandlerRectBorderWidth(const LayerTreeImpl* tree_impl); + static int WheelEventHandlerRectBorderWidth(); static SkColor WheelEventHandlerRectFillColor(); static SkColor NonFastScrollableRectBorderColor(); - static int NonFastScrollableRectBorderWidth(const LayerTreeImpl* tree_impl); + static int NonFastScrollableRectBorderWidth(); static SkColor NonFastScrollableRectFillColor(); static SkColor NonPaintedFillColor(); diff --git a/cc/layers/heads_up_display_layer.cc b/cc/layers/heads_up_display_layer.cc index 4d6351d..de44fac 100644 --- a/cc/layers/heads_up_display_layer.cc +++ b/cc/layers/heads_up_display_layer.cc @@ -16,7 +16,7 @@ scoped_refptr<HeadsUpDisplayLayer> HeadsUpDisplayLayer::Create() { return make_scoped_refptr(new HeadsUpDisplayLayer()); } -HeadsUpDisplayLayer::HeadsUpDisplayLayer() : Layer() { +HeadsUpDisplayLayer::HeadsUpDisplayLayer() : ContentsScalingLayer() { SetBounds(gfx::Size(256, 256)); } @@ -24,34 +24,36 @@ HeadsUpDisplayLayer::~HeadsUpDisplayLayer() {} void HeadsUpDisplayLayer::Update(ResourceUpdateQueue*, const OcclusionTracker*) { - const LayerTreeDebugState& debug_state = layer_tree_host()->debug_state(); - int max_texture_size = - layer_tree_host()->GetRendererCapabilities().max_texture_size; + gfx::Size device_viewport = layer_tree_host()->device_viewport_size(); + float device_scale_factor = layer_tree_host()->device_scale_factor(); - int device_viewport_in_layout_pixels_width = - layer_tree_host()->device_viewport_size().width() / - layer_tree_host()->device_scale_factor(); - int device_viewport_in_layout_pixels_height = - layer_tree_host()->device_viewport_size().height() / - layer_tree_host()->device_scale_factor(); + gfx::Size device_viewport_in_layout_pixels = gfx::Size( + device_viewport.width() / device_scale_factor, + device_viewport.height() / device_scale_factor); gfx::Size bounds; gfx::Transform matrix; matrix.MakeIdentity(); - if (debug_state.ShowHudRects()) { - int width = - std::min(max_texture_size, device_viewport_in_layout_pixels_width); - int height = - std::min(max_texture_size, device_viewport_in_layout_pixels_height); - bounds = gfx::Size(width, height); + if (layer_tree_host()->debug_state().ShowHudRects()) { + int max_texture_size = + layer_tree_host()->GetRendererCapabilities().max_texture_size; + bounds.SetSize(std::min(max_texture_size, + device_viewport_in_layout_pixels.width()), + std::min(max_texture_size, + device_viewport_in_layout_pixels.height())); } else { - bounds = gfx::Size(256, 256); - matrix.Translate(device_viewport_in_layout_pixels_width - 256.0, 0.0); + int size = 256; + bounds.SetSize(size, size); + matrix.Translate(device_viewport_in_layout_pixels.width() - size, 0.0); } SetBounds(bounds); SetTransform(matrix); + + // The HudLayer used to show up with the wrong bounds for one frame. + // This call fixes that the bounds get passed to LayerImpl on the next commit. + SavePaintProperties(); } bool HeadsUpDisplayLayer::DrawsContent() const { return true; } diff --git a/cc/layers/heads_up_display_layer.h b/cc/layers/heads_up_display_layer.h index c81d47e..80106b1 100644 --- a/cc/layers/heads_up_display_layer.h +++ b/cc/layers/heads_up_display_layer.h @@ -7,11 +7,11 @@ #include "base/memory/scoped_ptr.h" #include "cc/base/cc_export.h" -#include "cc/layers/layer.h" +#include "cc/layers/contents_scaling_layer.h" namespace cc { -class CC_EXPORT HeadsUpDisplayLayer : public Layer { +class CC_EXPORT HeadsUpDisplayLayer : public ContentsScalingLayer { public: static scoped_refptr<HeadsUpDisplayLayer> Create(); diff --git a/cc/layers/heads_up_display_layer_impl.cc b/cc/layers/heads_up_display_layer_impl.cc index f31ef7b..ef3e2fd 100644 --- a/cc/layers/heads_up_display_layer_impl.cc +++ b/cc/layers/heads_up_display_layer_impl.cc @@ -7,7 +7,6 @@ #include <algorithm> #include <vector> -#include "base/strings/string_split.h" #include "base/strings/stringprintf.h" #include "cc/debug/debug_colors.h" #include "cc/debug/debug_rect_history.h" @@ -17,7 +16,6 @@ #include "cc/output/renderer.h" #include "cc/quads/texture_draw_quad.h" #include "cc/resources/memory_history.h" -#include "cc/resources/tile_manager.h" #include "cc/trees/layer_tree_impl.h" #include "skia/ext/platform_canvas.h" #include "third_party/khronos/GLES2/gl2.h" @@ -89,18 +87,15 @@ bool HeadsUpDisplayLayerImpl::WillDraw(DrawMode draw_mode, if (!hud_resource_) hud_resource_ = ScopedResource::create(resource_provider); - // TODO(danakj): Scale the HUD by device scale to make it more friendly under - // high DPI. - // TODO(danakj): The HUD could swap between two textures instead of creating a // texture every frame in ubercompositor. - if (hud_resource_->size() != bounds() || + if (hud_resource_->size() != content_bounds() || resource_provider->InUseByConsumer(hud_resource_->id())) hud_resource_->Free(); if (!hud_resource_->id()) { hud_resource_->Allocate( - bounds(), GL_RGBA, ResourceProvider::TextureUsageAny); + content_bounds(), GL_RGBA, ResourceProvider::TextureUsageAny); } return LayerImpl::WillDraw(draw_mode, resource_provider); @@ -114,7 +109,7 @@ void HeadsUpDisplayLayerImpl::AppendQuads(QuadSink* quad_sink, SharedQuadState* shared_quad_state = quad_sink->UseSharedQuadState(CreateSharedQuadState()); - gfx::Rect quad_rect(bounds()); + gfx::Rect quad_rect(content_bounds()); gfx::Rect opaque_rect(contents_opaque() ? quad_rect : gfx::Rect()); bool premultiplied_alpha = true; gfx::PointF uv_top_left(0.f, 0.f); @@ -145,27 +140,32 @@ void HeadsUpDisplayLayerImpl::UpdateHudTexture( else canvas_size.set(0, 0); - if (canvas_size.fWidth != bounds().width() || - canvas_size.fHeight != bounds().height() || !hud_canvas_) { + if (canvas_size.width() != content_bounds().width() || + canvas_size.width() != content_bounds().height() || !hud_canvas_) { bool opaque = false; - hud_canvas_ = make_scoped_ptr( - skia::CreateBitmapCanvas(bounds().width(), bounds().height(), opaque)); + hud_canvas_ = make_scoped_ptr(skia::CreateBitmapCanvas( + content_bounds().width(), content_bounds().height(), opaque)); } UpdateHudContents(); hud_canvas_->clear(SkColorSetARGB(0, 0, 0, 0)); + hud_canvas_->save(); + hud_canvas_->scale(contents_scale_x(), contents_scale_y()); + DrawHudContents(hud_canvas_.get()); + hud_canvas_->restore(); + const SkBitmap* bitmap = &hud_canvas_->getDevice()->accessBitmap(false); SkAutoLockPixels locker(*bitmap); - gfx::Rect layer_rect(bounds()); + gfx::Rect content_rect(content_bounds()); DCHECK(bitmap->config() == SkBitmap::kARGB_8888_Config); resource_provider->SetPixels(hud_resource_->id(), static_cast<const uint8_t*>(bitmap->getPixels()), - layer_rect, - layer_rect, + content_rect, + content_rect, gfx::Vector2d()); } @@ -222,11 +222,11 @@ void HeadsUpDisplayLayerImpl::DrawHudContents(SkCanvas* canvas) const { SkRect area = SkRect::MakeEmpty(); if (debug_state.continuous_painting) { - // Don't show the FPS display when continuous painting is enabled, because - // it would show misleading numbers. area = DrawPaintTimeDisplay( canvas, layer_tree_impl()->paint_time_counter(), 0, 0); } else if (debug_state.show_fps_counter) { + // Don't show the FPS display when continuous painting is enabled, because + // it would show misleading numbers. area = DrawFPSDisplay(canvas, layer_tree_impl()->frame_rate_counter(), 0, 0); } @@ -579,12 +579,8 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( SkCanvas* canvas, DebugRectHistory* debug_rect_history) const { const std::vector<DebugRect>& debug_rects = debug_rect_history->debug_rects(); - float rect_scale = 1.f / layer_tree_impl()->device_scale_factor(); SkPaint paint = CreatePaint(); - canvas->save(); - canvas->scale(rect_scale, rect_scale); - for (size_t i = 0; i < debug_rects.size(); ++i) { SkColor stroke_color = 0; SkColor fill_color = 0; @@ -595,69 +591,62 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( case PAINT_RECT_TYPE: stroke_color = DebugColors::PaintRectBorderColor(); fill_color = DebugColors::PaintRectFillColor(); - stroke_width = DebugColors::PaintRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::PaintRectBorderWidth(); break; case PROPERTY_CHANGED_RECT_TYPE: stroke_color = DebugColors::PropertyChangedRectBorderColor(); fill_color = DebugColors::PropertyChangedRectFillColor(); - stroke_width = - DebugColors::PropertyChangedRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::PropertyChangedRectBorderWidth(); break; case SURFACE_DAMAGE_RECT_TYPE: stroke_color = DebugColors::SurfaceDamageRectBorderColor(); fill_color = DebugColors::SurfaceDamageRectFillColor(); - stroke_width = - DebugColors::SurfaceDamageRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::SurfaceDamageRectBorderWidth(); break; case REPLICA_SCREEN_SPACE_RECT_TYPE: stroke_color = DebugColors::ScreenSpaceSurfaceReplicaRectBorderColor(); fill_color = DebugColors::ScreenSpaceSurfaceReplicaRectFillColor(); - stroke_width = DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth( - layer_tree_impl()); + stroke_width = DebugColors::ScreenSpaceSurfaceReplicaRectBorderWidth(); break; case SCREEN_SPACE_RECT_TYPE: stroke_color = DebugColors::ScreenSpaceLayerRectBorderColor(); fill_color = DebugColors::ScreenSpaceLayerRectFillColor(); - stroke_width = - DebugColors::ScreenSpaceLayerRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::ScreenSpaceLayerRectBorderWidth(); break; case OCCLUDING_RECT_TYPE: stroke_color = DebugColors::OccludingRectBorderColor(); fill_color = DebugColors::OccludingRectFillColor(); - stroke_width = DebugColors::OccludingRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::OccludingRectBorderWidth(); break; case NONOCCLUDING_RECT_TYPE: stroke_color = DebugColors::NonOccludingRectBorderColor(); fill_color = DebugColors::NonOccludingRectFillColor(); - stroke_width = - DebugColors::NonOccludingRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::NonOccludingRectBorderWidth(); break; case TOUCH_EVENT_HANDLER_RECT_TYPE: stroke_color = DebugColors::TouchEventHandlerRectBorderColor(); fill_color = DebugColors::TouchEventHandlerRectFillColor(); - stroke_width = - DebugColors::TouchEventHandlerRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::TouchEventHandlerRectBorderWidth(); label_text = "touch event listener"; break; case WHEEL_EVENT_HANDLER_RECT_TYPE: stroke_color = DebugColors::WheelEventHandlerRectBorderColor(); fill_color = DebugColors::WheelEventHandlerRectFillColor(); - stroke_width = - DebugColors::WheelEventHandlerRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::WheelEventHandlerRectBorderWidth(); label_text = "mousewheel event listener"; break; case NON_FAST_SCROLLABLE_RECT_TYPE: stroke_color = DebugColors::NonFastScrollableRectBorderColor(); fill_color = DebugColors::NonFastScrollableRectFillColor(); - stroke_width = - DebugColors::NonFastScrollableRectBorderWidth(layer_tree_impl()); + stroke_width = DebugColors::NonFastScrollableRectBorderWidth(); label_text = "repaints on scroll"; break; } - const gfx::RectF& rect = debug_rects[i].rect; - SkRect sk_rect = - SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); + gfx::RectF debug_layer_rect = gfx::ScaleRect(debug_rects[i].rect, + 1.0 / contents_scale_x(), + 1.0 / contents_scale_y()); + SkRect sk_rect = RectFToSkRect(debug_layer_rect); paint.setColor(fill_color); paint.setStyle(SkPaint::kFill_Style); canvas->drawRect(sk_rect, paint); @@ -670,13 +659,10 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( if (label_text.length()) { const int kFontHeight = 12; const int kPadding = 3; - const float device_scale_factor = - layer_tree_impl()->device_scale_factor(); canvas->save(); canvas->clipRect(sk_rect); canvas->translate(sk_rect.x(), sk_rect.y()); - canvas->scale(device_scale_factor, device_scale_factor); SkPaint label_paint = CreatePaint(); label_paint.setTextSize(kFontHeight); @@ -700,8 +686,6 @@ void HeadsUpDisplayLayerImpl::DrawDebugRects( canvas->restore(); } } - - canvas->restore(); } const char* HeadsUpDisplayLayerImpl::LayerTypeAsString() const { |