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