Chromium Code Reviews| 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 "cc/layers/nine_patch_layer_impl.h" | 5 #include "cc/layers/nine_patch_layer_impl.h" |
| 6 | 6 |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/quads/solid_color_draw_quad.h" | |
| 10 #include "cc/quads/texture_draw_quad.h" | 11 #include "cc/quads/texture_draw_quad.h" |
| 11 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
| 12 #include "cc/trees/occlusion.h" | 13 #include "cc/trees/occlusion.h" |
| 13 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
| 14 | 15 |
| 15 namespace cc { | 16 namespace cc { |
| 16 | 17 |
| 18 // Maximum number of patches that can be produced for one NinePatchLayer. | |
| 19 static const int kMaxPatches = 12; | |
| 20 | |
| 17 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) | 21 NinePatchLayerImpl::NinePatchLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 18 : UIResourceLayerImpl(tree_impl, id), | 22 : UIResourceLayerImpl(tree_impl, id), |
| 19 fill_center_(false), | 23 fill_center_(false), |
| 20 nearest_neighbor_(false) {} | 24 nearest_neighbor_(false) {} |
| 21 | 25 |
| 22 NinePatchLayerImpl::~NinePatchLayerImpl() {} | 26 NinePatchLayerImpl::~NinePatchLayerImpl() {} |
| 23 | 27 |
| 24 scoped_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl( | 28 scoped_ptr<LayerImpl> NinePatchLayerImpl::CreateLayerImpl( |
| 25 LayerTreeImpl* tree_impl) { | 29 LayerTreeImpl* tree_impl) { |
| 26 return NinePatchLayerImpl::Create(tree_impl, id()); | 30 return NinePatchLayerImpl::Create(tree_impl, id()); |
| 27 } | 31 } |
| 28 | 32 |
| 29 void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { | 33 void NinePatchLayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 30 UIResourceLayerImpl::PushPropertiesTo(layer); | 34 UIResourceLayerImpl::PushPropertiesTo(layer); |
| 31 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); | 35 NinePatchLayerImpl* layer_impl = static_cast<NinePatchLayerImpl*>(layer); |
| 32 | 36 |
| 33 layer_impl->SetLayout(image_aperture_, border_, fill_center_, | 37 layer_impl->SetLayout(image_aperture_, border_, fill_center_, |
| 34 nearest_neighbor_); | 38 nearest_neighbor_, layer_occlusion_); |
| 35 } | 39 } |
| 36 | 40 |
| 37 static gfx::RectF NormalizedRect(float x, | 41 static gfx::Rect BoundsToRect(int x1, int y1, int x2, int y2) { |
| 38 float y, | 42 return gfx::Rect(x1, y1, x2 - x1, y2 - y1); |
| 39 float width, | 43 } |
| 40 float height, | 44 |
| 45 static gfx::RectF NormalizedRect(const gfx::Rect& rect, | |
| 41 float total_width, | 46 float total_width, |
| 42 float total_height) { | 47 float total_height) { |
| 43 return gfx::RectF(x / total_width, | 48 return gfx::RectF( |
| 44 y / total_height, | 49 (float)rect.x() / total_width, (float)rect.y() / total_height, |
|
Daniel Erat
2016/04/15 15:38:45
please don't use c-style casts. use static_cast in
llandwerlin-old
2016/04/18 15:08:20
Done.
| |
| 45 width / total_width, | 50 (float)rect.width() / total_width, (float)rect.height() / total_height); |
| 46 height / total_height); | |
| 47 } | 51 } |
| 48 | 52 |
| 49 void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, | 53 void NinePatchLayerImpl::SetLayout(const gfx::Rect& aperture, |
| 50 const gfx::Rect& border, | 54 const gfx::Rect& border, |
| 51 bool fill_center, | 55 bool fill_center, |
| 52 bool nearest_neighbor) { | 56 bool nearest_neighbor, |
| 57 const gfx::Rect& layer_occlusion) { | |
| 53 // This check imposes an ordering on the call sequence. An UIResource must | 58 // This check imposes an ordering on the call sequence. An UIResource must |
| 54 // exist before SetLayout can be called. | 59 // exist before SetLayout can be called. |
| 55 DCHECK(ui_resource_id_); | 60 DCHECK(ui_resource_id_); |
| 56 | 61 |
| 57 if (image_aperture_ == aperture && border_ == border && | 62 if (image_aperture_ == aperture && border_ == border && |
| 58 fill_center_ == fill_center && nearest_neighbor_ == nearest_neighbor) | 63 fill_center_ == fill_center && nearest_neighbor_ == nearest_neighbor && |
| 64 layer_occlusion_ == layer_occlusion) | |
| 59 return; | 65 return; |
| 60 | 66 |
| 61 image_aperture_ = aperture; | 67 image_aperture_ = aperture; |
| 62 border_ = border; | 68 border_ = border; |
| 63 fill_center_ = fill_center; | 69 fill_center_ = fill_center; |
| 64 nearest_neighbor_ = nearest_neighbor; | 70 nearest_neighbor_ = nearest_neighbor; |
| 71 layer_occlusion_ = layer_occlusion; | |
| 65 | 72 |
| 66 NoteLayerPropertyChanged(); | 73 NoteLayerPropertyChanged(); |
| 67 } | 74 } |
| 68 | 75 |
| 69 void NinePatchLayerImpl::CheckGeometryLimitations() { | 76 void NinePatchLayerImpl::CheckGeometryLimitations() { |
| 70 // |border| is in layer space. It cannot exceed the bounds of the layer. | 77 // |border| is in layer space. It cannot exceed the bounds of the layer. |
| 71 DCHECK_GE(bounds().width(), border_.width()); | 78 DCHECK_GE(bounds().width(), border_.width()); |
| 72 DCHECK_GE(bounds().height(), border_.height()); | 79 DCHECK_GE(bounds().height(), border_.height()); |
| 73 | 80 |
| 74 // Sanity Check on |border| | 81 // Sanity Check on |border| |
| 75 DCHECK_LE(border_.x(), border_.width()); | 82 DCHECK_LE(border_.x(), border_.width()); |
| 76 DCHECK_LE(border_.y(), border_.height()); | 83 DCHECK_LE(border_.y(), border_.height()); |
| 77 DCHECK_GE(border_.x(), 0); | 84 DCHECK_GE(border_.x(), 0); |
| 78 DCHECK_GE(border_.y(), 0); | 85 DCHECK_GE(border_.y(), 0); |
| 79 | 86 |
| 80 // |aperture| is in image space. It cannot exceed the bounds of the bitmap. | 87 // |aperture| is in image space. It cannot exceed the bounds of the bitmap. |
| 81 DCHECK(!image_aperture_.size().IsEmpty()); | 88 DCHECK(!image_aperture_.size().IsEmpty()); |
| 82 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) | 89 DCHECK(gfx::Rect(image_bounds_).Contains(image_aperture_)) |
| 83 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() | 90 << "image_bounds_ " << gfx::Rect(image_bounds_).ToString() |
| 84 << " image_aperture_ " << image_aperture_.ToString(); | 91 << " image_aperture_ " << image_aperture_.ToString(); |
| 85 } | 92 } |
| 86 | 93 |
| 94 void NinePatchLayerImpl::AppendQuadsWithoutOcclusion( | |
| 95 RenderPass* render_pass, | |
| 96 ResourceId resource, | |
| 97 SharedQuadState* shared_quad_state, | |
| 98 std::vector<gfx::Rect>* image_rects, | |
| 99 std::vector<gfx::Rect>* layer_rects) { | |
| 100 // Utility values. | |
| 101 float image_width = image_bounds_.width(); | |
| 102 float image_height = image_bounds_.height(); | |
| 103 int layer_width = bounds().width(); | |
| 104 int layer_height = bounds().height(); | |
| 105 gfx::Rect layer_aperture(border_.x(), border_.y(), | |
| 106 layer_width - border_.width(), | |
| 107 layer_height - border_.height()); | |
| 108 | |
| 109 // Top-left. | |
| 110 image_rects->push_back( | |
| 111 BoundsToRect(0, 0, image_aperture_.x(), image_aperture_.y())); | |
| 112 layer_rects->push_back( | |
| 113 BoundsToRect(0, 0, layer_aperture.x(), layer_aperture.y())); | |
| 114 | |
| 115 // Top-right. | |
| 116 image_rects->push_back(BoundsToRect(image_aperture_.right(), 0, image_width, | |
| 117 image_aperture_.y())); | |
| 118 layer_rects->push_back( | |
| 119 BoundsToRect(layer_aperture.right(), 0, layer_width, layer_aperture.y())); | |
| 120 | |
| 121 // Bottom-left. | |
| 122 image_rects->push_back(BoundsToRect(0, image_aperture_.bottom(), | |
| 123 image_aperture_.x(), image_height)); | |
| 124 layer_rects->push_back(BoundsToRect(0, layer_aperture.bottom(), | |
| 125 layer_aperture.x(), layer_height)); | |
| 126 | |
| 127 // Bottom-right. | |
| 128 image_rects->push_back(BoundsToRect(image_aperture_.right(), | |
| 129 image_aperture_.bottom(), image_width, | |
| 130 image_height)); | |
| 131 layer_rects->push_back(BoundsToRect(layer_aperture.right(), | |
| 132 layer_aperture.bottom(), layer_width, | |
| 133 layer_height)); | |
| 134 | |
| 135 // Top. | |
| 136 image_rects->push_back(BoundsToRect( | |
| 137 image_aperture_.x(), 0, image_aperture_.right(), image_aperture_.y())); | |
| 138 layer_rects->push_back(BoundsToRect( | |
| 139 layer_aperture.x(), 0, layer_aperture.right(), layer_aperture.y())); | |
| 140 | |
| 141 // Left. | |
| 142 image_rects->push_back(BoundsToRect( | |
| 143 0, image_aperture_.y(), image_aperture_.x(), image_aperture_.bottom())); | |
| 144 layer_rects->push_back(BoundsToRect(0, layer_aperture.y(), layer_aperture.x(), | |
| 145 layer_aperture.bottom())); | |
| 146 | |
| 147 // Right. | |
| 148 image_rects->push_back(BoundsToRect(image_aperture_.right(), | |
| 149 image_aperture_.y(), image_width, | |
| 150 image_aperture_.bottom())); | |
| 151 layer_rects->push_back(BoundsToRect(layer_aperture.right(), | |
| 152 layer_aperture.y(), layer_width, | |
| 153 layer_aperture.bottom())); | |
| 154 | |
| 155 // Bottom. | |
| 156 image_rects->push_back(BoundsToRect(image_aperture_.x(), | |
| 157 image_aperture_.bottom(), | |
| 158 image_aperture_.right(), image_height)); | |
| 159 layer_rects->push_back(BoundsToRect(layer_aperture.x(), | |
| 160 layer_aperture.bottom(), | |
| 161 layer_aperture.right(), layer_height)); | |
| 162 | |
| 163 // Center. | |
| 164 if (fill_center_) { | |
| 165 image_rects->push_back( | |
| 166 BoundsToRect(image_aperture_.x(), image_aperture_.y(), | |
| 167 image_aperture_.right(), image_aperture_.bottom())); | |
| 168 layer_rects->push_back(BoundsToRect(layer_aperture.x(), layer_aperture.y(), | |
| 169 layer_aperture.right(), | |
| 170 layer_aperture.bottom())); | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 void NinePatchLayerImpl::AppendQuadsWithOcclusion( | |
| 175 RenderPass* render_pass, | |
| 176 ResourceId resource, | |
| 177 SharedQuadState* shared_quad_state, | |
| 178 std::vector<gfx::Rect>* image_rects, | |
| 179 std::vector<gfx::Rect>* layer_rects) { | |
| 180 // Helper values. | |
| 181 float image_width = image_bounds_.width(); | |
| 182 float image_height = image_bounds_.height(); | |
| 183 int layer_width = bounds().width(); | |
| 184 int layer_height = bounds().height(); | |
| 185 gfx::Rect image_occlusion( | |
| 186 BoundsToRect(layer_occlusion_.x(), layer_occlusion_.y(), | |
| 187 image_width - (layer_width - layer_occlusion_.right()), | |
| 188 image_height - (layer_height - layer_occlusion_.bottom()))); | |
| 189 gfx::Rect layer_aperture( | |
| 190 BoundsToRect(image_aperture_.x(), image_aperture_.y(), | |
| 191 layer_width - (image_width - image_aperture_.right()), | |
| 192 layer_height - (image_height - image_aperture_.bottom()))); | |
| 193 | |
| 194 // Top-left-left. | |
| 195 image_rects->push_back( | |
| 196 BoundsToRect(0, 0, image_occlusion.x(), image_aperture_.y())); | |
| 197 layer_rects->push_back( | |
| 198 BoundsToRect(0, 0, layer_occlusion_.x(), layer_aperture.y())); | |
| 199 | |
| 200 // Top-left-right. | |
| 201 image_rects->push_back(BoundsToRect( | |
| 202 image_occlusion.x(), 0, image_aperture_.x(), image_occlusion.y())); | |
| 203 layer_rects->push_back(BoundsToRect( | |
| 204 layer_occlusion_.x(), 0, layer_aperture.x(), layer_occlusion_.y())); | |
| 205 | |
| 206 // Top-center. | |
| 207 image_rects->push_back(BoundsToRect( | |
| 208 image_aperture_.x(), 0, image_aperture_.right(), image_occlusion.y())); | |
| 209 layer_rects->push_back(BoundsToRect( | |
| 210 layer_aperture.x(), 0, layer_aperture.right(), layer_occlusion_.y())); | |
| 211 | |
| 212 // Top-right-left. | |
| 213 image_rects->push_back(BoundsToRect(image_aperture_.right(), 0, | |
| 214 image_occlusion.right(), | |
| 215 image_occlusion.y())); | |
| 216 layer_rects->push_back(BoundsToRect(layer_aperture.right(), 0, | |
| 217 layer_occlusion_.right(), | |
| 218 layer_occlusion_.y())); | |
| 219 | |
| 220 // Top-right-right. | |
| 221 image_rects->push_back(BoundsToRect(image_occlusion.right(), 0, image_width, | |
| 222 image_aperture_.y())); | |
| 223 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(), 0, layer_width, | |
| 224 layer_aperture.y())); | |
| 225 | |
| 226 // Right-center. | |
| 227 image_rects->push_back(BoundsToRect( | |
| 228 0, image_aperture_.y(), image_occlusion.x(), image_aperture_.bottom())); | |
| 229 layer_rects->push_back(BoundsToRect( | |
| 230 0, layer_aperture.y(), layer_occlusion_.x(), layer_aperture.bottom())); | |
| 231 | |
| 232 // Left-center. | |
| 233 image_rects->push_back(BoundsToRect(image_occlusion.right(), | |
| 234 image_aperture_.y(), image_width, | |
| 235 image_aperture_.bottom())); | |
| 236 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(), | |
| 237 layer_aperture.y(), layer_width, | |
| 238 layer_aperture.bottom())); | |
| 239 | |
| 240 // Bottom-left-left. | |
| 241 image_rects->push_back(BoundsToRect(0, image_aperture_.bottom(), | |
| 242 image_occlusion.x(), image_height)); | |
| 243 layer_rects->push_back(BoundsToRect(0, layer_aperture.bottom(), | |
| 244 layer_occlusion_.x(), layer_height)); | |
| 245 | |
| 246 // Bottom-left-right. | |
| 247 image_rects->push_back(BoundsToRect(image_occlusion.x(), | |
| 248 image_occlusion.bottom(), | |
| 249 image_aperture_.x(), image_height)); | |
| 250 layer_rects->push_back(BoundsToRect(layer_occlusion_.x(), | |
| 251 layer_occlusion_.bottom(), | |
| 252 layer_aperture.x(), layer_height)); | |
| 253 | |
| 254 // Bottom-center. | |
| 255 image_rects->push_back(BoundsToRect(image_aperture_.x(), | |
| 256 image_occlusion.bottom(), | |
| 257 image_aperture_.right(), image_height)); | |
| 258 layer_rects->push_back(BoundsToRect(layer_aperture.x(), | |
| 259 layer_occlusion_.bottom(), | |
| 260 layer_aperture.right(), layer_height)); | |
| 261 | |
| 262 // Bottom-right-left. | |
| 263 image_rects->push_back(BoundsToRect(image_aperture_.right(), | |
| 264 image_occlusion.bottom(), | |
| 265 image_occlusion.right(), image_height)); | |
| 266 layer_rects->push_back(BoundsToRect(layer_aperture.right(), | |
| 267 layer_occlusion_.bottom(), | |
| 268 layer_occlusion_.right(), layer_height)); | |
| 269 | |
| 270 // Bottom-right-right. | |
| 271 image_rects->push_back(BoundsToRect(image_occlusion.right(), | |
| 272 image_aperture_.bottom(), image_width, | |
| 273 image_height)); | |
| 274 layer_rects->push_back(BoundsToRect(layer_occlusion_.right(), | |
| 275 layer_aperture.bottom(), layer_width, | |
| 276 layer_height)); | |
| 277 } | |
| 278 | |
| 87 void NinePatchLayerImpl::AppendQuads( | 279 void NinePatchLayerImpl::AppendQuads( |
| 88 RenderPass* render_pass, | 280 RenderPass* render_pass, |
| 89 AppendQuadsData* append_quads_data) { | 281 AppendQuadsData* append_quads_data) { |
| 90 CheckGeometryLimitations(); | 282 CheckGeometryLimitations(); |
| 91 SharedQuadState* shared_quad_state = | 283 SharedQuadState* shared_quad_state = |
| 92 render_pass->CreateAndAppendSharedQuadState(); | 284 render_pass->CreateAndAppendSharedQuadState(); |
| 93 PopulateSharedQuadState(shared_quad_state); | 285 PopulateSharedQuadState(shared_quad_state); |
| 94 | 286 |
| 95 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, | 287 AppendDebugBorderQuad(render_pass, bounds(), shared_quad_state, |
| 96 append_quads_data); | 288 append_quads_data); |
| 97 | 289 |
| 98 if (!ui_resource_id_) | 290 if (!ui_resource_id_) |
| 99 return; | 291 return; |
| 100 | 292 |
| 101 ResourceId resource = | 293 ResourceId resource = |
| 102 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); | 294 layer_tree_impl()->ResourceIdForUIResource(ui_resource_id_); |
| 103 | 295 |
| 104 if (!resource) | 296 if (!resource) |
| 105 return; | 297 return; |
| 106 | 298 |
| 107 static const bool flipped = false; | |
| 108 static const bool premultiplied_alpha = true; | |
| 109 | |
| 110 DCHECK(!bounds().IsEmpty()); | 299 DCHECK(!bounds().IsEmpty()); |
| 111 | 300 |
| 112 // NinePatch border widths in layer space. | 301 // Patch positions in bitmap UV space (from zero to one). |
| 113 int layer_left_width = border_.x(); | 302 std::vector<gfx::Rect> image_rects; |
| 114 int layer_top_height = border_.y(); | 303 image_rects.reserve(kMaxPatches); |
| 115 int layer_right_width = border_.width() - layer_left_width; | 304 // Patch positions in layer space. |
| 116 int layer_bottom_height = border_.height() - layer_top_height; | 305 std::vector<gfx::Rect> layer_rects; |
| 306 layer_rects.reserve(kMaxPatches); | |
| 117 | 307 |
| 118 int layer_middle_width = bounds().width() - border_.width(); | 308 if (!layer_occlusion_.IsEmpty() && border_.IsEmpty() && !fill_center_) |
| 119 int layer_middle_height = bounds().height() - border_.height(); | 309 AppendQuadsWithOcclusion(render_pass, resource, shared_quad_state, |
| 310 &image_rects, &layer_rects); | |
| 311 else | |
| 312 AppendQuadsWithoutOcclusion(render_pass, resource, shared_quad_state, | |
| 313 &image_rects, &layer_rects); | |
| 120 | 314 |
| 121 // Patch positions in layer space | 315 DCHECK_EQ(image_rects.size(), layer_rects.size()); |
| 122 gfx::Rect layer_top_left(0, 0, layer_left_width, layer_top_height); | |
| 123 gfx::Rect layer_top_right(bounds().width() - layer_right_width, | |
| 124 0, | |
| 125 layer_right_width, | |
| 126 layer_top_height); | |
| 127 gfx::Rect layer_bottom_left(0, | |
| 128 bounds().height() - layer_bottom_height, | |
| 129 layer_left_width, | |
| 130 layer_bottom_height); | |
| 131 gfx::Rect layer_bottom_right(layer_top_right.x(), | |
| 132 layer_bottom_left.y(), | |
| 133 layer_right_width, | |
| 134 layer_bottom_height); | |
| 135 gfx::Rect layer_top( | |
| 136 layer_top_left.right(), 0, layer_middle_width, layer_top_height); | |
| 137 gfx::Rect layer_left( | |
| 138 0, layer_top_left.bottom(), layer_left_width, layer_middle_height); | |
| 139 gfx::Rect layer_right(layer_top_right.x(), | |
| 140 layer_top_right.bottom(), | |
| 141 layer_right_width, | |
| 142 layer_left.height()); | |
| 143 gfx::Rect layer_bottom(layer_top.x(), | |
| 144 layer_bottom_left.y(), | |
| 145 layer_top.width(), | |
| 146 layer_bottom_height); | |
| 147 gfx::Rect layer_center(layer_left_width, | |
| 148 layer_top_height, | |
| 149 layer_middle_width, | |
| 150 layer_middle_height); | |
| 151 | |
| 152 // Note the following values are in image (bitmap) space. | |
| 153 float image_width = image_bounds_.width(); | |
| 154 float image_height = image_bounds_.height(); | |
| 155 | |
| 156 int image_aperture_left_width = image_aperture_.x(); | |
| 157 int image_aperture_top_height = image_aperture_.y(); | |
| 158 int image_aperture_right_width = image_width - image_aperture_.right(); | |
| 159 int image_aperture_bottom_height = image_height - image_aperture_.bottom(); | |
| 160 // Patch positions in bitmap UV space (from zero to one) | |
| 161 gfx::RectF uv_top_left = NormalizedRect(0, | |
| 162 0, | |
| 163 image_aperture_left_width, | |
| 164 image_aperture_top_height, | |
| 165 image_width, | |
| 166 image_height); | |
| 167 gfx::RectF uv_top_right = | |
| 168 NormalizedRect(image_width - image_aperture_right_width, | |
| 169 0, | |
| 170 image_aperture_right_width, | |
| 171 image_aperture_top_height, | |
| 172 image_width, | |
| 173 image_height); | |
| 174 gfx::RectF uv_bottom_left = | |
| 175 NormalizedRect(0, | |
| 176 image_height - image_aperture_bottom_height, | |
| 177 image_aperture_left_width, | |
| 178 image_aperture_bottom_height, | |
| 179 image_width, | |
| 180 image_height); | |
| 181 gfx::RectF uv_bottom_right = | |
| 182 NormalizedRect(image_width - image_aperture_right_width, | |
| 183 image_height - image_aperture_bottom_height, | |
| 184 image_aperture_right_width, | |
| 185 image_aperture_bottom_height, | |
| 186 image_width, | |
| 187 image_height); | |
| 188 gfx::RectF uv_top( | |
| 189 uv_top_left.right(), | |
| 190 0, | |
| 191 (image_width - image_aperture_left_width - image_aperture_right_width) / | |
| 192 image_width, | |
| 193 (image_aperture_top_height) / image_height); | |
| 194 gfx::RectF uv_left(0, | |
| 195 uv_top_left.bottom(), | |
| 196 image_aperture_left_width / image_width, | |
| 197 (image_height - image_aperture_top_height - | |
| 198 image_aperture_bottom_height) / | |
| 199 image_height); | |
| 200 gfx::RectF uv_right(uv_top_right.x(), | |
| 201 uv_top_right.bottom(), | |
| 202 image_aperture_right_width / image_width, | |
| 203 uv_left.height()); | |
| 204 gfx::RectF uv_bottom(uv_top.x(), | |
| 205 uv_bottom_left.y(), | |
| 206 uv_top.width(), | |
| 207 image_aperture_bottom_height / image_height); | |
| 208 gfx::RectF uv_center(uv_top_left.right(), | |
| 209 uv_top_left.bottom(), | |
| 210 uv_top.width(), | |
| 211 uv_left.height()); | |
| 212 | 316 |
| 213 gfx::Rect opaque_rect; | 317 gfx::Rect opaque_rect; |
| 214 gfx::Rect visible_rect; | 318 gfx::Rect visible_rect; |
| 215 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 319 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 216 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); | 320 const bool opaque = layer_tree_impl()->IsUIResourceOpaque(ui_resource_id_); |
| 321 static const bool flipped = false; | |
| 322 static const bool premultiplied_alpha = true; | |
| 217 | 323 |
| 218 visible_rect = | 324 for (size_t i = 0; i < image_rects.size(); i++) { |
| 219 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | 325 const gfx::Rect& layer_rect(layer_rects[i]); |
| 220 layer_top_left); | |
| 221 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 222 if (!visible_rect.IsEmpty()) { | |
| 223 TextureDrawQuad* quad = | |
| 224 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 225 quad->SetNew(shared_quad_state, layer_top_left, opaque_rect, visible_rect, | |
| 226 resource, premultiplied_alpha, uv_top_left.origin(), | |
| 227 uv_top_left.bottom_right(), SK_ColorTRANSPARENT, | |
| 228 vertex_opacity, flipped, nearest_neighbor_); | |
| 229 ValidateQuadResources(quad); | |
| 230 } | |
| 231 | 326 |
| 232 visible_rect = | |
| 233 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 234 layer_top_right); | |
| 235 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 236 if (!visible_rect.IsEmpty()) { | |
| 237 TextureDrawQuad* quad = | |
| 238 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 239 quad->SetNew(shared_quad_state, layer_top_right, opaque_rect, visible_rect, | |
| 240 resource, premultiplied_alpha, uv_top_right.origin(), | |
| 241 uv_top_right.bottom_right(), SK_ColorTRANSPARENT, | |
| 242 vertex_opacity, flipped, nearest_neighbor_); | |
| 243 ValidateQuadResources(quad); | |
| 244 } | |
| 245 | |
| 246 visible_rect = | |
| 247 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 248 layer_bottom_left); | |
| 249 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 250 if (!visible_rect.IsEmpty()) { | |
| 251 TextureDrawQuad* quad = | |
| 252 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 253 quad->SetNew(shared_quad_state, layer_bottom_left, opaque_rect, | |
| 254 visible_rect, resource, premultiplied_alpha, | |
| 255 uv_bottom_left.origin(), uv_bottom_left.bottom_right(), | |
| 256 SK_ColorTRANSPARENT, vertex_opacity, flipped, | |
| 257 nearest_neighbor_); | |
| 258 ValidateQuadResources(quad); | |
| 259 } | |
| 260 | |
| 261 visible_rect = | |
| 262 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 263 layer_bottom_right); | |
| 264 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 265 if (!visible_rect.IsEmpty()) { | |
| 266 TextureDrawQuad* quad = | |
| 267 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 268 quad->SetNew(shared_quad_state, layer_bottom_right, opaque_rect, | |
| 269 visible_rect, resource, premultiplied_alpha, | |
| 270 uv_bottom_right.origin(), uv_bottom_right.bottom_right(), | |
| 271 SK_ColorTRANSPARENT, vertex_opacity, flipped, | |
| 272 nearest_neighbor_); | |
| 273 ValidateQuadResources(quad); | |
| 274 } | |
| 275 | |
| 276 visible_rect = | |
| 277 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 278 layer_top); | |
| 279 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 280 if (!visible_rect.IsEmpty()) { | |
| 281 TextureDrawQuad* quad = | |
| 282 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 283 quad->SetNew(shared_quad_state, layer_top, opaque_rect, visible_rect, | |
| 284 resource, premultiplied_alpha, uv_top.origin(), | |
| 285 uv_top.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity, | |
| 286 flipped, nearest_neighbor_); | |
| 287 ValidateQuadResources(quad); | |
| 288 } | |
| 289 | |
| 290 visible_rect = | |
| 291 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 292 layer_left); | |
| 293 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 294 if (!visible_rect.IsEmpty()) { | |
| 295 TextureDrawQuad* quad = | |
| 296 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 297 quad->SetNew(shared_quad_state, layer_left, opaque_rect, visible_rect, | |
| 298 resource, premultiplied_alpha, uv_left.origin(), | |
| 299 uv_left.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity, | |
| 300 flipped, nearest_neighbor_); | |
| 301 ValidateQuadResources(quad); | |
| 302 } | |
| 303 | |
| 304 visible_rect = | |
| 305 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 306 layer_right); | |
| 307 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 308 if (!visible_rect.IsEmpty()) { | |
| 309 TextureDrawQuad* quad = | |
| 310 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 311 quad->SetNew(shared_quad_state, layer_right, opaque_rect, layer_right, | |
| 312 resource, premultiplied_alpha, uv_right.origin(), | |
| 313 uv_right.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity, | |
| 314 flipped, nearest_neighbor_); | |
| 315 ValidateQuadResources(quad); | |
| 316 } | |
| 317 | |
| 318 visible_rect = | |
| 319 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | |
| 320 layer_bottom); | |
| 321 opaque_rect = opaque ? visible_rect : gfx::Rect(); | |
| 322 if (!visible_rect.IsEmpty()) { | |
| 323 TextureDrawQuad* quad = | |
| 324 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | |
| 325 quad->SetNew(shared_quad_state, layer_bottom, opaque_rect, visible_rect, | |
| 326 resource, premultiplied_alpha, uv_bottom.origin(), | |
| 327 uv_bottom.bottom_right(), SK_ColorTRANSPARENT, vertex_opacity, | |
| 328 flipped, nearest_neighbor_); | |
| 329 ValidateQuadResources(quad); | |
| 330 } | |
| 331 | |
| 332 if (fill_center_) { | |
| 333 visible_rect = | 327 visible_rect = |
| 334 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( | 328 draw_properties().occlusion_in_content_space.GetUnoccludedContentRect( |
| 335 layer_center); | 329 layer_rect); |
| 336 opaque_rect = opaque ? visible_rect : gfx::Rect(); | 330 opaque_rect = opaque ? visible_rect : gfx::Rect(); |
| 337 if (!visible_rect.IsEmpty()) { | 331 if (!visible_rect.IsEmpty()) { |
| 332 gfx::RectF image_rect(NormalizedRect( | |
| 333 image_rects[i], image_bounds_.width(), image_bounds_.height())); | |
| 338 TextureDrawQuad* quad = | 334 TextureDrawQuad* quad = |
| 339 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 335 render_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
| 340 quad->SetNew(shared_quad_state, layer_center, opaque_rect, visible_rect, | 336 quad->SetNew(shared_quad_state, layer_rect, opaque_rect, visible_rect, |
| 341 resource, premultiplied_alpha, uv_center.origin(), | 337 resource, premultiplied_alpha, image_rect.origin(), |
| 342 uv_center.bottom_right(), SK_ColorTRANSPARENT, | 338 image_rect.bottom_right(), SK_ColorTRANSPARENT, |
| 343 vertex_opacity, flipped, nearest_neighbor_); | 339 vertex_opacity, flipped, nearest_neighbor_); |
| 344 ValidateQuadResources(quad); | 340 ValidateQuadResources(quad); |
| 345 } | 341 } |
| 346 } | 342 } |
| 347 } | 343 } |
| 348 | 344 |
| 349 const char* NinePatchLayerImpl::LayerTypeAsString() const { | 345 const char* NinePatchLayerImpl::LayerTypeAsString() const { |
| 350 return "cc::NinePatchLayerImpl"; | 346 return "cc::NinePatchLayerImpl"; |
| 351 } | 347 } |
| 352 | 348 |
| 353 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { | 349 base::DictionaryValue* NinePatchLayerImpl::LayerTreeAsJson() const { |
| 354 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); | 350 base::DictionaryValue* result = LayerImpl::LayerTreeAsJson(); |
| 355 | 351 |
| 356 base::ListValue* list = new base::ListValue; | 352 base::ListValue* list = new base::ListValue; |
| 357 list->AppendInteger(image_aperture_.origin().x()); | 353 list->AppendInteger(image_aperture_.origin().x()); |
| 358 list->AppendInteger(image_aperture_.origin().y()); | 354 list->AppendInteger(image_aperture_.origin().y()); |
| 359 list->AppendInteger(image_aperture_.size().width()); | 355 list->AppendInteger(image_aperture_.size().width()); |
| 360 list->AppendInteger(image_aperture_.size().height()); | 356 list->AppendInteger(image_aperture_.size().height()); |
| 361 result->Set("ImageAperture", list); | 357 result->Set("ImageAperture", list); |
| 362 | 358 |
| 363 list = new base::ListValue; | 359 list = new base::ListValue; |
| 364 list->AppendInteger(image_bounds_.width()); | 360 list->AppendInteger(image_bounds_.width()); |
| 365 list->AppendInteger(image_bounds_.height()); | 361 list->AppendInteger(image_bounds_.height()); |
| 366 result->Set("ImageBounds", list); | 362 result->Set("ImageBounds", list); |
| 367 | 363 |
| 368 result->Set("Border", MathUtil::AsValue(border_).release()); | 364 result->Set("Border", MathUtil::AsValue(border_).release()); |
| 369 | 365 |
| 370 result->SetBoolean("FillCenter", fill_center_); | 366 result->SetBoolean("FillCenter", fill_center_); |
| 371 | 367 |
| 368 list = new base::ListValue; | |
| 369 list->AppendInteger(layer_occlusion_.x()); | |
| 370 list->AppendInteger(layer_occlusion_.y()); | |
| 371 list->AppendInteger(layer_occlusion_.width()); | |
| 372 list->AppendInteger(layer_occlusion_.height()); | |
| 373 result->Set("LayerOcclusion", list); | |
| 374 | |
| 372 return result; | 375 return result; |
| 373 } | 376 } |
| 374 | 377 |
| 375 } // namespace cc | 378 } // namespace cc |
| OLD | NEW |