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/texture_draw_quad.h" | 5 #include "cc/texture_draw_quad.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 this->uv_rect = uv_rect; | 51 this->uv_rect = uv_rect; |
52 this->flipped = flipped; | 52 this->flipped = flipped; |
53 } | 53 } |
54 | 54 |
55 const TextureDrawQuad* TextureDrawQuad::MaterialCast( | 55 const TextureDrawQuad* TextureDrawQuad::MaterialCast( |
56 const DrawQuad* quad) { | 56 const DrawQuad* quad) { |
57 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); | 57 DCHECK(quad->material == DrawQuad::TEXTURE_CONTENT); |
58 return static_cast<const TextureDrawQuad*>(quad); | 58 return static_cast<const TextureDrawQuad*>(quad); |
59 } | 59 } |
60 | 60 |
61 bool TextureDrawQuad::PerformClipping() { | |
62 // This only occurs if the rect is only scaled and translated (and thus still | |
63 // axis aligned). | |
64 if (!quadTransform().IsScaleOrTranslation()) | |
65 return false; | |
66 | |
67 // Grab our scale and offset. | |
68 float x_scale = quadTransform().matrix().getDouble(0,0); | |
69 float y_scale = quadTransform().matrix().getDouble(1,1); | |
70 gfx::Vector2dF offset( | |
71 quadTransform().matrix().getDouble(0,3), | |
72 quadTransform().matrix().getDouble(1,3)); | |
73 | |
74 // Transform the rect by the scale and offset. | |
75 gfx::RectF rectF = rect; | |
76 rectF.Scale(x_scale, y_scale); | |
77 rectF += offset; | |
78 | |
79 // Perform clipping and check to see if the result is empty. | |
80 gfx::RectF clippedRect = IntersectRects(rectF, clipRect()); | |
81 if (clippedRect.IsEmpty()) { | |
82 rect = gfx::Rect(); | |
83 uv_rect = gfx::RectF(); | |
84 return true; | |
85 } | |
86 | |
87 // Create a new uv-rect by clipping the old one to the new bounds. | |
88 uv_rect = gfx::RectF( | |
89 uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()), | |
90 uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()), | |
91 uv_rect.width () / rectF.width () * clippedRect.width (), | |
92 uv_rect.height() / rectF.height() * clippedRect.height()); | |
93 | |
94 // Move the clipped rectangle back into its space. | |
95 clippedRect -= offset; | |
96 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale); | |
97 rect = gfx::Rect( | |
98 static_cast<int>(clippedRect.x() + 0.5f), | |
99 static_cast<int>(clippedRect.y() + 0.5f), | |
100 static_cast<int>(clippedRect.width() + 0.5f), | |
101 static_cast<int>(clippedRect.height() + 0.5f)); | |
102 return true; | |
103 } | |
104 | |
105 } // namespace cc | 61 } // namespace cc |
OLD | NEW |