Commit 270f6229 authored by hshi's avatar hshi Committed by Commit bot

Change ui::wm::Shadow to pass ImageSkia instead of SkBitmap.

This allows ui::Layer to take scale factor into consideration when updating the cc::NinePatchLayer.

BUG=466950
R=danakj@chromium.org
R=oshima@chromium.org
TBR=sky@chromium.org
TEST=verify on HiDPI display as well as HiDPI + LowDPI extended mode that shadows are correct.

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

Cr-Commit-Position: refs/heads/master@{#320974}
parent c8ae1d65
...@@ -620,8 +620,11 @@ void Layer::SetShowSolidColorContent() { ...@@ -620,8 +620,11 @@ void Layer::SetShowSolidColorContent() {
RecomputeDrawsContentAndUVRect(); RecomputeDrawsContentAndUVRect();
} }
void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) { void Layer::UpdateNinePatchLayerImage(const gfx::ImageSkia& image) {
DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
nine_patch_layer_image_ = image;
SkBitmap bitmap = nine_patch_layer_image_.GetRepresentation(
device_scale_factor_).sk_bitmap();
SkBitmap bitmap_copy; SkBitmap bitmap_copy;
if (bitmap.isImmutable()) { if (bitmap.isImmutable()) {
bitmap_copy = bitmap; bitmap_copy = bitmap;
...@@ -633,9 +636,11 @@ void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) { ...@@ -633,9 +636,11 @@ void Layer::UpdateNinePatchLayerBitmap(const SkBitmap& bitmap) {
nine_patch_layer_->SetBitmap(bitmap_copy); nine_patch_layer_->SetBitmap(bitmap_copy);
} }
void Layer::UpdateNinePatchLayerAperture(const gfx::Rect& aperture) { void Layer::UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip) {
DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get());
nine_patch_layer_->SetAperture(aperture); nine_patch_layer_aperture_ = aperture_in_dip;
gfx::Rect aperture_in_pixel = ConvertRectToPixel(this, aperture_in_dip);
nine_patch_layer_->SetAperture(aperture_in_pixel);
} }
void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) { void Layer::UpdateNinePatchLayerBorder(const gfx::Rect& border) {
...@@ -709,6 +714,10 @@ void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) { ...@@ -709,6 +714,10 @@ void Layer::OnDeviceScaleFactorChanged(float device_scale_factor) {
device_scale_factor_ = device_scale_factor; device_scale_factor_ = device_scale_factor;
RecomputeDrawsContentAndUVRect(); RecomputeDrawsContentAndUVRect();
RecomputePosition(); RecomputePosition();
if (nine_patch_layer_) {
UpdateNinePatchLayerImage(nine_patch_layer_image_);
UpdateNinePatchLayerAperture(nine_patch_layer_aperture_);
}
SchedulePaint(gfx::Rect(bounds_.size())); SchedulePaint(gfx::Rect(bounds_.size()));
if (delegate_) if (delegate_)
delegate_->OnDeviceScaleFactorChanged(device_scale_factor); delegate_->OnDeviceScaleFactorChanged(device_scale_factor);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ui/compositor/layer_delegate.h" #include "ui/compositor/layer_delegate.h"
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
class SkCanvas; class SkCanvas;
...@@ -300,10 +301,10 @@ class COMPOSITOR_EXPORT Layer ...@@ -300,10 +301,10 @@ class COMPOSITOR_EXPORT Layer
// Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR.
void SetColor(SkColor color); void SetColor(SkColor color);
// Updates the nine patch layer's bitmap, aperture and border. May only be // Updates the nine patch layer's image, aperture and border. May only be
// called for LAYER_NINE_PATCH. // called for LAYER_NINE_PATCH.
void UpdateNinePatchLayerBitmap(const SkBitmap& bitmap); void UpdateNinePatchLayerImage(const gfx::ImageSkia& image);
void UpdateNinePatchLayerAperture(const gfx::Rect& aperture); void UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip);
void UpdateNinePatchLayerBorder(const gfx::Rect& border); void UpdateNinePatchLayerBorder(const gfx::Rect& border);
// Adds |invalid_rect| to the Layer's pending invalid rect and calls // Adds |invalid_rect| to the Layer's pending invalid rect and calls
...@@ -512,6 +513,11 @@ class COMPOSITOR_EXPORT Layer ...@@ -512,6 +513,11 @@ class COMPOSITOR_EXPORT Layer
// A cached copy of |Compositor::device_scale_factor()|. // A cached copy of |Compositor::device_scale_factor()|.
float device_scale_factor_; float device_scale_factor_;
// A cached copy of the nine patch layer's image and aperture.
// These are required for device scale factor change.
gfx::ImageSkia nine_patch_layer_image_;
gfx::Rect nine_patch_layer_aperture_;
// The mailbox used by texture_layer_. // The mailbox used by texture_layer_.
cc::TextureMailbox mailbox_; cc::TextureMailbox mailbox_;
......
...@@ -162,7 +162,7 @@ void Shadow::UpdateImagesForStyle() { ...@@ -162,7 +162,7 @@ void Shadow::UpdateImagesForStyle() {
break; break;
} }
shadow_layer_->UpdateNinePatchLayerBitmap(image.AsBitmap()); shadow_layer_->UpdateNinePatchLayerImage(image.AsImageSkia());
image_size_ = image.Size(); image_size_ = image.Size();
interior_inset_ = GetInteriorInsetForStyle(style_); interior_inset_ = GetInteriorInsetForStyle(style_);
......
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