| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "nine_patch_layer_impl.h" | 5 #include "nine_patch_layer_impl.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "cc/quad_sink.h" | 9 #include "cc/quad_sink.h" |
| 10 #include "cc/texture_draw_quad.h" | 10 #include "cc/texture_draw_quad.h" |
| 11 #include "ui/gfx/rect_f.h" | 11 #include "ui/gfx/rect_f.h" |
| 12 | 12 |
| 13 namespace cc { | 13 namespace cc { |
| 14 | 14 |
| 15 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) | 15 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 16 : LayerImpl(tree_impl, id), | 16 : LayerImpl(tree_impl, id), |
| 17 resource_id_(0) {} | 17 resource_id_(0) {} |
| 18 | 18 |
| 19 NinePatchLayerImpl::~NinePatchLayerImpl() {} | 19 NinePatchLayerImpl::~NinePatchLayerImpl() {} |
| 20 | 20 |
| 21 ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const { | 21 ResourceProvider::ResourceId NinePatchLayerImpl::ContentsResourceId() const { |
| 22 return 0; | 22 return 0; |
| 23 } | 23 } |
| 24 | 24 |
| 25 scoped_ptr<LayerImpl> NinePatchLayerImpl::createLayerImpl( | 25 scoped_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl( |
| 26 LayerTreeImpl* tree_impl) { | 26 LayerTreeImpl* tree_impl) { |
| 27 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 27 return NinePatchLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void NinePatchLayerImpl::pushPropertiesTo(LayerImpl* layer) { | 30 void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 31 LayerImpl::pushPropertiesTo(layer); | 31 LayerImpl::PushPropertiesTo(layer); |
| 32 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); | 32 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 33 | 33 |
| 34 if (!resource_id_) | 34 if (!resource_id_) |
| 35 return; | 35 return; |
| 36 | 36 |
| 37 layer_impl->SetResourceId(resource_id_); | 37 layer_impl->SetResourceId(resource_id_); |
| 38 layer_impl->SetLayout(image_bounds_, image_aperture_); | 38 layer_impl->SetLayout(image_bounds_, image_aperture_); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void NinePatchLayerImpl::willDraw(ResourceProvider* resource_provider) {} | 41 void NinePatchLayerImpl::WillDraw(ResourceProvider* resource_provider) {} |
| 42 | 42 |
| 43 static gfx::RectF NormalizedRect(float x, | 43 static gfx::RectF NormalizedRect(float x, |
| 44 float y, | 44 float y, |
| 45 float width, | 45 float width, |
| 46 float height, | 46 float height, |
| 47 float total_width, | 47 float total_width, |
| 48 float total_height) { | 48 float total_height) { |
| 49 return gfx::RectF(x / total_width, | 49 return gfx::RectF(x / total_width, |
| 50 y / total_height, | 50 y / total_height, |
| 51 width / total_width, | 51 width / total_width, |
| 52 height / total_height); | 52 height / total_height); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void NinePatchLayerImpl::SetLayout(gfx::Size image_bounds, gfx::Rect aperture) { | 55 void NinePatchLayerImpl::SetLayout(gfx::Size image_bounds, gfx::Rect aperture) { |
| 56 image_bounds_ = image_bounds; | 56 image_bounds_ = image_bounds; |
| 57 image_aperture_ = aperture; | 57 image_aperture_ = aperture; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void NinePatchLayerImpl::appendQuads(QuadSink& quad_sink, | 60 void NinePatchLayerImpl::AppendQuads(QuadSink* quad_sink, |
| 61 AppendQuadsData& append_quads_data) { | 61 AppendQuadsData* append_quads_data) { |
| 62 if (!resource_id_) | 62 if (!resource_id_) |
| 63 return; | 63 return; |
| 64 | 64 |
| 65 SharedQuadState* shared_quad_state = | 65 SharedQuadState* shared_quad_state = |
| 66 quad_sink.useSharedQuadState(createSharedQuadState()); | 66 quad_sink->useSharedQuadState(CreateSharedQuadState()); |
| 67 appendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); | 67 AppendDebugBorderQuad(quad_sink, shared_quad_state, append_quads_data); |
| 68 | 68 |
| 69 static const bool flipped = false; | 69 static const bool flipped = false; |
| 70 static const bool premultiplied_alpha = true; | 70 static const bool premultiplied_alpha = true; |
| 71 | 71 |
| 72 DCHECK(!bounds().IsEmpty()); | 72 DCHECK(!bounds().IsEmpty()); |
| 73 | 73 |
| 74 // NinePatch border widths in bitmap pixel space | 74 // NinePatch border widths in bitmap pixel space |
| 75 int left_width = image_aperture_.x(); | 75 int left_width = image_aperture_.x(); |
| 76 int top_height = image_aperture_.y(); | 76 int top_height = image_aperture_.y(); |
| 77 int right_width = image_bounds_.width() - image_aperture_.right(); | 77 int right_width = image_bounds_.width() - image_aperture_.right(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 | 166 |
| 167 quad = TextureDrawQuad::Create(); | 167 quad = TextureDrawQuad::Create(); |
| 168 quad->SetNew(shared_quad_state, | 168 quad->SetNew(shared_quad_state, |
| 169 top_left, | 169 top_left, |
| 170 opaque_rect, | 170 opaque_rect, |
| 171 resource_id_, | 171 resource_id_, |
| 172 premultiplied_alpha, | 172 premultiplied_alpha, |
| 173 uv_top_left.origin(), | 173 uv_top_left.origin(), |
| 174 uv_top_left.bottom_right(), | 174 uv_top_left.bottom_right(), |
| 175 vertex_opacity, flipped); | 175 vertex_opacity, flipped); |
| 176 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 176 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 177 | 177 |
| 178 quad = TextureDrawQuad::Create(); | 178 quad = TextureDrawQuad::Create(); |
| 179 quad->SetNew(shared_quad_state, | 179 quad->SetNew(shared_quad_state, |
| 180 topRight, | 180 topRight, |
| 181 opaque_rect, | 181 opaque_rect, |
| 182 resource_id_, | 182 resource_id_, |
| 183 premultiplied_alpha, | 183 premultiplied_alpha, |
| 184 uv_top_right.origin(), | 184 uv_top_right.origin(), |
| 185 uv_top_right.bottom_right(), | 185 uv_top_right.bottom_right(), |
| 186 vertex_opacity, flipped); | 186 vertex_opacity, flipped); |
| 187 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 187 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 188 | 188 |
| 189 quad = TextureDrawQuad::Create(); | 189 quad = TextureDrawQuad::Create(); |
| 190 quad->SetNew(shared_quad_state, | 190 quad->SetNew(shared_quad_state, |
| 191 bottomLeft, | 191 bottomLeft, |
| 192 opaque_rect, | 192 opaque_rect, |
| 193 resource_id_, | 193 resource_id_, |
| 194 premultiplied_alpha, | 194 premultiplied_alpha, |
| 195 uv_bottom_left.origin(), | 195 uv_bottom_left.origin(), |
| 196 uv_bottom_left.bottom_right(), | 196 uv_bottom_left.bottom_right(), |
| 197 vertex_opacity, | 197 vertex_opacity, |
| 198 flipped); | 198 flipped); |
| 199 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 199 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 200 | 200 |
| 201 quad = TextureDrawQuad::Create(); | 201 quad = TextureDrawQuad::Create(); |
| 202 quad->SetNew(shared_quad_state, | 202 quad->SetNew(shared_quad_state, |
| 203 bottomRight, | 203 bottomRight, |
| 204 opaque_rect, | 204 opaque_rect, |
| 205 resource_id_, | 205 resource_id_, |
| 206 premultiplied_alpha, | 206 premultiplied_alpha, |
| 207 uv_bottom_right.origin(), | 207 uv_bottom_right.origin(), |
| 208 uv_bottom_right.bottom_right(), | 208 uv_bottom_right.bottom_right(), |
| 209 vertex_opacity, | 209 vertex_opacity, |
| 210 flipped); | 210 flipped); |
| 211 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 211 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 212 | 212 |
| 213 quad = TextureDrawQuad::Create(); | 213 quad = TextureDrawQuad::Create(); |
| 214 quad->SetNew(shared_quad_state, | 214 quad->SetNew(shared_quad_state, |
| 215 top, | 215 top, |
| 216 opaque_rect, | 216 opaque_rect, |
| 217 resource_id_, | 217 resource_id_, |
| 218 premultiplied_alpha, | 218 premultiplied_alpha, |
| 219 uvTop.origin(), | 219 uvTop.origin(), |
| 220 uvTop.bottom_right(), | 220 uvTop.bottom_right(), |
| 221 vertex_opacity, | 221 vertex_opacity, |
| 222 flipped); | 222 flipped); |
| 223 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 223 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 224 | 224 |
| 225 quad = TextureDrawQuad::Create(); | 225 quad = TextureDrawQuad::Create(); |
| 226 quad->SetNew(shared_quad_state, | 226 quad->SetNew(shared_quad_state, |
| 227 left, | 227 left, |
| 228 opaque_rect, | 228 opaque_rect, |
| 229 resource_id_, | 229 resource_id_, |
| 230 premultiplied_alpha, | 230 premultiplied_alpha, |
| 231 uvLeft.origin(), | 231 uvLeft.origin(), |
| 232 uvLeft.bottom_right(), | 232 uvLeft.bottom_right(), |
| 233 vertex_opacity, | 233 vertex_opacity, |
| 234 flipped); | 234 flipped); |
| 235 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 235 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 236 | 236 |
| 237 quad = TextureDrawQuad::Create(); | 237 quad = TextureDrawQuad::Create(); |
| 238 quad->SetNew(shared_quad_state, | 238 quad->SetNew(shared_quad_state, |
| 239 right, | 239 right, |
| 240 opaque_rect, | 240 opaque_rect, |
| 241 resource_id_, | 241 resource_id_, |
| 242 premultiplied_alpha, | 242 premultiplied_alpha, |
| 243 uvRight.origin(), | 243 uvRight.origin(), |
| 244 uvRight.bottom_right(), | 244 uvRight.bottom_right(), |
| 245 vertex_opacity, | 245 vertex_opacity, |
| 246 flipped); | 246 flipped); |
| 247 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 247 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 248 | 248 |
| 249 quad = TextureDrawQuad::Create(); | 249 quad = TextureDrawQuad::Create(); |
| 250 quad->SetNew(shared_quad_state, | 250 quad->SetNew(shared_quad_state, |
| 251 bottom, | 251 bottom, |
| 252 opaque_rect, | 252 opaque_rect, |
| 253 resource_id_, | 253 resource_id_, |
| 254 premultiplied_alpha, | 254 premultiplied_alpha, |
| 255 uvBottom.origin(), | 255 uvBottom.origin(), |
| 256 uvBottom.bottom_right(), | 256 uvBottom.bottom_right(), |
| 257 vertex_opacity, | 257 vertex_opacity, |
| 258 flipped); | 258 flipped); |
| 259 quad_sink.append(quad.PassAs<DrawQuad>(), append_quads_data); | 259 quad_sink->append(quad.PassAs<DrawQuad>(), append_quads_data); |
| 260 } | 260 } |
| 261 | 261 |
| 262 void NinePatchLayerImpl::didDraw(ResourceProvider* resource_provider) {} | 262 void NinePatchLayerImpl::DidDraw(ResourceProvider* resource_provider) {} |
| 263 | 263 |
| 264 void NinePatchLayerImpl::didLoseOutputSurface() { | 264 void NinePatchLayerImpl::DidLoseOutputSurface() { |
| 265 resource_id_ = 0; | 265 resource_id_ = 0; |
| 266 } | 266 } |
| 267 | 267 |
| 268 const char* NinePatchLayerImpl::layerTypeAsString() const { | 268 const char* NinePatchLayerImpl::LayerTypeAsString() const { |
| 269 return "NinePatchLayer"; | 269 return "NinePatchLayer"; |
| 270 } | 270 } |
| 271 | 271 |
| 272 void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) | 272 void NinePatchLayerImpl::DumpLayerProperties(std::string* str, int indent) |
| 273 const { | 273 const { |
| 274 str->append(indentString(indent)); | 274 str->append(IndentString(indent)); |
| 275 base::StringAppendF( | 275 base::StringAppendF( |
| 276 str, "imageAperture: %s\n", image_aperture_.ToString().c_str()); | 276 str, "imageAperture: %s\n", image_aperture_.ToString().c_str()); |
| 277 base::StringAppendF( | 277 base::StringAppendF( |
| 278 str, "image_bounds: %s\n", image_bounds_.ToString().c_str()); | 278 str, "image_bounds: %s\n", image_bounds_.ToString().c_str()); |
| 279 LayerImpl::dumpLayerProperties(str, indent); | 279 LayerImpl::DumpLayerProperties(str, indent); |
| 280 } | 280 } |
| 281 | 281 |
| 282 base::DictionaryValue* NinePatchLayerImpl::layerTreeAsJson() const { | 282 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { |
| 283 base::DictionaryValue* result = LayerImpl::layerTreeAsJson(); | 283 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); |
| 284 | 284 |
| 285 base::ListValue* list = new base::ListValue; | 285 base::ListValue* list = new base::ListValue; |
| 286 list->AppendInteger(image_aperture_.origin().x()); | 286 list->AppendInteger(image_aperture_.origin().x()); |
| 287 list->AppendInteger(image_aperture_.origin().y()); | 287 list->AppendInteger(image_aperture_.origin().y()); |
| 288 list->AppendInteger(image_aperture_.size().width()); | 288 list->AppendInteger(image_aperture_.size().width()); |
| 289 list->AppendInteger(image_aperture_.size().height()); | 289 list->AppendInteger(image_aperture_.size().height()); |
| 290 result->Set("ImageAperture", list); | 290 result->Set("ImageAperture", list); |
| 291 | 291 |
| 292 list = new base::ListValue; | 292 list = new base::ListValue; |
| 293 list->AppendInteger(image_bounds_.width()); | 293 list->AppendInteger(image_bounds_.width()); |
| 294 list->AppendInteger(image_bounds_.height()); | 294 list->AppendInteger(image_bounds_.height()); |
| 295 result->Set("ImageBounds", list); | 295 result->Set("ImageBounds", list); |
| 296 | 296 |
| 297 return result; | 297 return result; |
| 298 } | 298 } |
| 299 | 299 |
| 300 } // namespace cc | 300 } // namespace cc |
| OLD | NEW |