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