| Index: cc/layers/nine_patch_layer_impl.cc
|
| diff --git a/cc/layers/nine_patch_layer_impl.cc b/cc/layers/nine_patch_layer_impl.cc
|
| index 4274bf00af17da64a015880563c700c9f324df80..31f847a429f610d6214ced96b7f8528f7c5a0718 100644
|
| --- a/cc/layers/nine_patch_layer_impl.cc
|
| +++ b/cc/layers/nine_patch_layer_impl.cc
|
| @@ -8,13 +8,15 @@
|
| #include "base/values.h"
|
| #include "cc/layers/quad_sink.h"
|
| #include "cc/quads/texture_draw_quad.h"
|
| +#include "cc/trees/layer_tree_impl.h"
|
| #include "ui/gfx/rect_f.h"
|
|
|
| namespace cc {
|
|
|
| NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id)
|
| : LayerImpl(tree_impl, id),
|
| - resource_id_(0) {}
|
| + fill_center_(false),
|
| + ui_resource_id_(0) {}
|
|
|
| NinePatchLayerImpl::~NinePatchLayerImpl() {}
|
|
|
| @@ -31,11 +33,8 @@ void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) {
|
| LayerImpl::PushPropertiesTo(layer);
|
| NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer);
|
|
|
| - if (!resource_id_)
|
| - return;
|
| -
|
| - layer_impl->SetResourceId(resource_id_);
|
| - layer_impl->SetLayout(image_bounds_, image_aperture_);
|
| + layer_impl->set_ui_resource_id(ui_resource_id_);
|
| + layer_impl->SetLayout(image_bounds_, image_aperture_, border_, fill_center_);
|
| }
|
|
|
| static gfx::RectF NormalizedRect(float x,
|
| @@ -50,37 +49,47 @@ static gfx::RectF NormalizedRect(float x,
|
| height / total_height);
|
| }
|
|
|
| -void NinePatchLayerImpl::SetLayout(gfx::Size image_bounds, gfx::Rect aperture) {
|
| +void NinePatchLayerImpl::SetLayout(gfx::Size image_bounds, gfx::Rect aperture,
|
| + gfx::Rect border, bool fill_center) {
|
| image_bounds_ = image_bounds;
|
| image_aperture_ = aperture;
|
| + border_ = border;
|
| + fill_center_ = fill_center;
|
| }
|
|
|
| bool NinePatchLayerImpl::WillDraw(DrawMode draw_mode,
|
| ResourceProvider* resource_provider) {
|
| - if (!resource_id_ || draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
|
| + if (!ui_resource_id_ || draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE)
|
| return false;
|
| return LayerImpl::WillDraw(draw_mode, resource_provider);
|
| }
|
|
|
| void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| AppendQuadsData* append_quads_data) {
|
| + if (!ui_resource_id_ || !layer_tree_impl())
|
| + return;
|
| +
|
| + ResourceProvider::ResourceId resource =
|
| + layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_);
|
| +
|
| + if (!resource)
|
| + return;
|
| +
|
| SharedQuadState* shared_quad_state =
|
| quad_sink->UseSharedQuadState(CreateSharedQuadState());
|
| AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data);
|
|
|
| - if (!resource_id_)
|
| - return;
|
| -
|
| static const bool flipped = false;
|
| static const bool premultiplied_alpha = true;
|
|
|
| DCHECK(!bounds().IsEmpty());
|
|
|
| // NinePatch border widths in bitmap pixel space
|
| - int left_width = image_aperture_.x();
|
| - int top_height = image_aperture_.y();
|
| - int right_width = image_bounds_.width() - image_aperture_.right();
|
| - int bottom_height = image_bounds_.height() - image_aperture_.bottom();
|
| + // NinePatch border widths in layer space
|
| + int left_width = border_.x();
|
| + int top_height = border_.y();
|
| + int right_width = border_.width() - left_width;
|
| + int bottom_height = border_.height() - top_height;
|
|
|
| // If layer can't fit the corners, clip to show the outer edges of the
|
| // image.
|
| @@ -120,51 +129,62 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| right_width,
|
| left.height());
|
| gfx::Rect bottom(top.x(), bottom_left.y(), top.width(), bottom_height);
|
| + gfx::Rect center(left_width, top_height,
|
| + middle_width,
|
| + middle_height);
|
|
|
| float img_width = image_bounds_.width();
|
| float img_height = image_bounds_.height();
|
|
|
| + int aperture_left_width = image_aperture_.x();
|
| + int aperture_top_height = image_aperture_.y();
|
| + int aperture_right_width = img_width - image_aperture_.right();
|
| + int aperture_bottom_height = img_height - image_aperture_.bottom();
|
| // Patch positions in bitmap UV space (from zero to one)
|
| - gfx::RectF uv_top_left = NormalizedRect(0,
|
| - 0,
|
| - left_width,
|
| - top_height,
|
| - img_width,
|
| - img_height);
|
| - gfx::RectF uv_top_right = NormalizedRect(img_width - right_width,
|
| + gfx::RectF uv_top_left = NormalizedRect(
|
| + 0, 0, aperture_left_width, aperture_top_height, img_width, img_height);
|
| + gfx::RectF uv_top_right = NormalizedRect(img_width - aperture_right_width,
|
| 0,
|
| - right_width,
|
| - top_height,
|
| + aperture_right_width,
|
| + aperture_top_height,
|
| img_width,
|
| img_height);
|
| - gfx::RectF uv_bottom_left = NormalizedRect(0,
|
| - img_height - bottom_height,
|
| - left_width,
|
| - bottom_height,
|
| - img_width,
|
| - img_height);
|
| - gfx::RectF uv_bottom_right = NormalizedRect(img_width - right_width,
|
| - img_height - bottom_height,
|
| - right_width,
|
| - bottom_height,
|
| - img_width,
|
| - img_height);
|
| - gfx::RectF uv_top(uv_top_left.right(),
|
| - 0,
|
| - (img_width - left_width - right_width) / img_width,
|
| - (top_height) / img_height);
|
| - gfx::RectF uv_left(0,
|
| - uv_top_left.bottom(),
|
| - left_width / img_width,
|
| - (img_height - top_height - bottom_height) / img_height);
|
| + gfx::RectF uv_bottom_left =
|
| + NormalizedRect(0,
|
| + img_height - aperture_bottom_height,
|
| + aperture_left_width,
|
| + aperture_bottom_height,
|
| + img_width,
|
| + img_height);
|
| + gfx::RectF uv_bottom_right =
|
| + NormalizedRect(img_width - aperture_right_width,
|
| + img_height - aperture_bottom_height,
|
| + aperture_right_width,
|
| + aperture_bottom_height,
|
| + img_width,
|
| + img_height);
|
| + gfx::RectF uv_top(
|
| + uv_top_left.right(),
|
| + 0,
|
| + (img_width - aperture_left_width - aperture_right_width) / img_width,
|
| + (aperture_top_height) / img_height);
|
| + gfx::RectF uv_left(
|
| + 0,
|
| + uv_top_left.bottom(),
|
| + aperture_left_width / img_width,
|
| + (img_height - aperture_top_height - aperture_bottom_height) / img_height);
|
| gfx::RectF uv_right(uv_top_right.x(),
|
| - uv_top_right.bottom(),
|
| - right_width / img_width,
|
| - uv_left.height());
|
| + uv_top_right.bottom(),
|
| + aperture_right_width / img_width,
|
| + uv_left.height());
|
| gfx::RectF uv_bottom(uv_top.x(),
|
| uv_bottom_left.y(),
|
| uv_top.width(),
|
| - bottom_height / img_height);
|
| + aperture_bottom_height / img_height);
|
| + gfx::RectF uv_center(uv_top_left.right(),
|
| + uv_top_left.bottom(),
|
| + uv_top.width(),
|
| + uv_left.height());
|
|
|
| // Nothing is opaque here.
|
| // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness?
|
| @@ -176,7 +196,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| top_left,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_top_left.origin(),
|
| uv_top_left.bottom_right(),
|
| @@ -189,7 +209,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| top_right,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_top_right.origin(),
|
| uv_top_right.bottom_right(),
|
| @@ -202,7 +222,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| bottom_left,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_bottom_left.origin(),
|
| uv_bottom_left.bottom_right(),
|
| @@ -215,7 +235,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| bottom_right,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_bottom_right.origin(),
|
| uv_bottom_right.bottom_right(),
|
| @@ -228,7 +248,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| top,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_top.origin(),
|
| uv_top.bottom_right(),
|
| @@ -241,7 +261,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| left,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_left.origin(),
|
| uv_left.bottom_right(),
|
| @@ -254,7 +274,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| right,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_right.origin(),
|
| uv_right.bottom_right(),
|
| @@ -267,7 +287,7 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| quad->SetNew(shared_quad_state,
|
| bottom,
|
| opaque_rect,
|
| - resource_id_,
|
| + resource,
|
| premultiplied_alpha,
|
| uv_bottom.origin(),
|
| uv_bottom.bottom_right(),
|
| @@ -275,10 +295,21 @@ void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink,
|
| vertex_opacity,
|
| flipped);
|
| quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
|
| -}
|
|
|
| -void NinePatchLayerImpl::DidLoseOutputSurface() {
|
| - resource_id_ = 0;
|
| + if (fill_center_) {
|
| + quad = TextureDrawQuad::Create();
|
| + quad->SetNew(shared_quad_state,
|
| + center,
|
| + opaque_rect,
|
| + resource,
|
| + premultiplied_alpha,
|
| + uv_center.origin(),
|
| + uv_center.bottom_right(),
|
| + SK_ColorTRANSPARENT,
|
| + vertex_opacity,
|
| + flipped);
|
| + quad_sink->Append(quad.PassAs<DrawQuad>(), append_quads_data);
|
| + }
|
| }
|
|
|
| const char* NinePatchLayerImpl::LayerTypeAsString() const {
|
|
|