| 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/layers/quad_sink.h" | 9 #include "cc/layers/quad_sink.h" |
| 10 #include "cc/quads/texture_draw_quad.h" | 10 #include "cc/quads/texture_draw_quad.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 float top_height_proportion = | 95 float top_height_proportion = |
| 96 static_cast<float>(top_height) / corner_total_height; | 96 static_cast<float>(top_height) / corner_total_height; |
| 97 int top_height_crop = middle_height * top_height_proportion; | 97 int top_height_crop = middle_height * top_height_proportion; |
| 98 top_height += top_height_crop; | 98 top_height += top_height_crop; |
| 99 bottom_height = bounds().height() - top_height; | 99 bottom_height = bounds().height() - top_height; |
| 100 middle_height = 0; | 100 middle_height = 0; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Patch positions in layer space | 103 // Patch positions in layer space |
| 104 gfx::Rect top_left(0, 0, left_width, top_height); | 104 gfx::Rect top_left(0, 0, left_width, top_height); |
| 105 gfx::Rect topRight( | 105 gfx::Rect top_right( |
| 106 bounds().width() - right_width, 0, right_width, top_height); | 106 bounds().width() - right_width, 0, right_width, top_height); |
| 107 gfx::Rect bottomLeft( | 107 gfx::Rect bottom_left( |
| 108 0, bounds().height() - bottom_height, left_width, bottom_height); | 108 0, bounds().height() - bottom_height, left_width, bottom_height); |
| 109 gfx::Rect bottomRight( | 109 gfx::Rect bottom_right( |
| 110 topRight.x(), bottomLeft.y(), right_width, bottom_height); | 110 top_right.x(), bottom_left.y(), right_width, bottom_height); |
| 111 gfx::Rect top(top_left.right(), 0, middle_width, top_height); | 111 gfx::Rect top(top_left.right(), 0, middle_width, top_height); |
| 112 gfx::Rect left(0, top_left.bottom(), left_width, middle_height); | 112 gfx::Rect left(0, top_left.bottom(), left_width, middle_height); |
| 113 gfx::Rect right(topRight.x(), topRight.bottom(), right_width, left.height()); | 113 gfx::Rect right(top_right.x(), top_right.bottom(), right_width, left.height())
; |
| 114 gfx::Rect bottom(top.x(), bottomLeft.y(), top.width(), bottom_height); | 114 gfx::Rect bottom(top.x(), bottom_left.y(), top.width(), bottom_height); |
| 115 | 115 |
| 116 float img_width = image_bounds_.width(); | 116 float img_width = image_bounds_.width(); |
| 117 float img_height = image_bounds_.height(); | 117 float img_height = image_bounds_.height(); |
| 118 | 118 |
| 119 // Patch positions in bitmap UV space (from zero to one) | 119 // Patch positions in bitmap UV space (from zero to one) |
| 120 gfx::RectF uv_top_left = NormalizedRect(0, | 120 gfx::RectF uv_top_left = NormalizedRect(0, |
| 121 0, | 121 0, |
| 122 left_width, | 122 left_width, |
| 123 top_height, | 123 top_height, |
| 124 img_width, | 124 img_width, |
| 125 img_height); | 125 img_height); |
| 126 gfx::RectF uv_top_right = NormalizedRect(img_width - right_width, | 126 gfx::RectF uv_top_right = NormalizedRect(img_width - right_width, |
| 127 0, | 127 0, |
| 128 right_width, | 128 right_width, |
| 129 top_height, | 129 top_height, |
| 130 img_width, | 130 img_width, |
| 131 img_height); | 131 img_height); |
| 132 gfx::RectF uv_bottom_left = NormalizedRect(0, | 132 gfx::RectF uv_bottom_left = NormalizedRect(0, |
| 133 img_height - bottom_height, | 133 img_height - bottom_height, |
| 134 left_width, | 134 left_width, |
| 135 bottom_height, | 135 bottom_height, |
| 136 img_width, | 136 img_width, |
| 137 img_height); | 137 img_height); |
| 138 gfx::RectF uv_bottom_right = NormalizedRect(img_width - right_width, | 138 gfx::RectF uv_bottom_right = NormalizedRect(img_width - right_width, |
| 139 img_height - bottom_height, | 139 img_height - bottom_height, |
| 140 right_width, | 140 right_width, |
| 141 bottom_height, | 141 bottom_height, |
| 142 img_width, | 142 img_width, |
| 143 img_height); | 143 img_height); |
| 144 gfx::RectF uvTop(uv_top_left.right(), | 144 gfx::RectF uv_top(uv_top_left.right(), |
| 145 0, | 145 0, |
| 146 (img_width - left_width - right_width) / img_width, | 146 (img_width - left_width - right_width) / img_width, |
| 147 (top_height) / img_height); | 147 (top_height) / img_height); |
| 148 gfx::RectF uvLeft(0, | 148 gfx::RectF uv_left(0, |
| 149 uv_top_left.bottom(), | 149 uv_top_left.bottom(), |
| 150 left_width / img_width, | 150 left_width / img_width, |
| 151 (img_height - top_height - bottom_height) / img_height); | 151 (img_height - top_height - bottom_height) / img_height); |
| 152 gfx::RectF uvRight(uv_top_right.x(), | 152 gfx::RectF uv_right(uv_top_right.x(), |
| 153 uv_top_right.bottom(), | 153 uv_top_right.bottom(), |
| 154 right_width / img_width, | 154 right_width / img_width, |
| 155 uvLeft.height()); | 155 uv_left.height()); |
| 156 gfx::RectF uvBottom(uvTop.x(), | 156 gfx::RectF uv_bottom(uv_top.x(), |
| 157 uv_bottom_left.y(), | 157 uv_bottom_left.y(), |
| 158 uvTop.width(), | 158 uv_top.width(), |
| 159 bottom_height / img_height); | 159 bottom_height / img_height); |
| 160 | 160 |
| 161 // Nothing is opaque here. | 161 // Nothing is opaque here. |
| 162 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? | 162 // TODO(danakj): Should we look at the SkBitmaps to determine opaqueness? |
| 163 gfx::Rect opaque_rect; | 163 gfx::Rect opaque_rect; |
| 164 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | 164 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; |
| 165 scoped_ptr<TextureDrawQuad> quad; | 165 scoped_ptr<TextureDrawQuad> quad; |
| 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 top_right, |
| 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 bottom_left, |
| 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 bottom_right, |
| 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 uv_top.origin(), |
| 220 uvTop.bottom_right(), | 220 uv_top.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 uv_left.origin(), |
| 232 uvLeft.bottom_right(), | 232 uv_left.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 uv_right.origin(), |
| 244 uvRight.bottom_right(), | 244 uv_right.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 uv_bottom.origin(), |
| 256 uvBottom.bottom_right(), | 256 uv_bottom.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 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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 |