Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1288)

Unified Diff: cc/layers/nine_patch_layer_impl.cc

Issue 22870016: Update the nine patch layer to use UI resources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compilation error fixes Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..95a2d3a385c0b1010aa282292d2488861cb3caef 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,54 @@ 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) {
danakj 2013/08/27 15:42:48 One argument per line, lining up with the ( unless
powei 2013/08/27 19:04:57 Done.
+ // |border| is in layer space. It cannot exceed the bounds of the layer.
+ DCHECK_GE(bounds().width(), border.width());
+ DCHECK_GE(bounds().height(), border.height());
+
+ // |aperture| is in image space. It cannot exceed the bounds of the bitmap.
+ DCHECK(gfx::Rect(image_bounds.width(), image_bounds.height())
+ .Contains(aperture));
+
image_bounds_ = image_bounds;
image_aperture_ = aperture;
+ border_ = border;
+ fill_center_ = fill_center;
danakj 2013/08/27 15:42:48 Should this function also cause damage so it is re
powei 2013/08/27 19:04:57 Done.
}
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())
danakj 2013/08/27 15:42:48 layer_tree_impl is never null, it's set non-null i
powei 2013/08/27 22:39:28 Done.
+ 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
danakj 2013/08/27 15:42:48 nit: Period.
powei 2013/08/27 22:39:28 Done.
+ int left_width = border_.x();
danakj 2013/08/27 15:42:48 maybe prefixing all these variables with layer_ or
powei 2013/08/27 22:39:28 Done.
+ 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 +136,69 @@ 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);
+ // Note the following values are in image (bitmap) space.
float img_width = image_bounds_.width();
float img_height = image_bounds_.height();
+ int img_aperture_left_width = image_aperture_.x();
+ int img_aperture_top_height = image_aperture_.y();
+ int img_aperture_right_width = img_width - image_aperture_.right();
+ int img_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_aperture_left_width,
+ img_aperture_top_height,
img_width,
img_height);
- gfx::RectF uv_top_right = NormalizedRect(img_width - right_width,
+ gfx::RectF uv_top_right = NormalizedRect(img_width - img_aperture_right_width,
0,
- right_width,
- top_height,
+ img_aperture_right_width,
+ img_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 - img_aperture_bottom_height,
+ img_aperture_left_width,
+ img_aperture_bottom_height,
+ img_width,
+ img_height);
+ gfx::RectF uv_bottom_right =
+ NormalizedRect(img_width - img_aperture_right_width,
+ img_height - img_aperture_bottom_height,
+ img_aperture_right_width,
+ img_aperture_bottom_height,
+ img_width,
+ img_height);
+ gfx::RectF uv_top(
+ uv_top_left.right(),
+ 0,
+ (img_width - img_aperture_left_width - img_aperture_right_width) /
+ img_width,
+ (img_aperture_top_height) / img_height);
+ gfx::RectF uv_left(
+ 0,
+ uv_top_left.bottom(),
+ img_aperture_left_width / img_width,
+ (img_height - img_aperture_top_height - img_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(),
+ img_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);
+ img_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 +210,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 +223,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 +236,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 +249,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 +262,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 +275,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 +288,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 +301,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 +309,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 {
@@ -300,6 +345,15 @@ base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const {
list->AppendInteger(image_bounds_.height());
result->Set("ImageBounds", list);
+ list = new base::ListValue;
+ list->AppendInteger(border_.width());
danakj 2013/08/27 15:42:48 Border is a rect, why not save it all? Also we hav
powei 2013/08/27 22:39:28 Done.
+ list->AppendInteger(border_.height());
+ result->Set("Border", list);
+
+ base::FundamentalValue* fill_center =
+ base::Value::CreateBooleanValue(fill_center_);
+ result->Set("FillCenter", fill_center);
+
return result;
}

Powered by Google App Engine
This is Rietveld 408576698