Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: cc/texture_draw_quad.cc

Issue 11481004: explicitly validating assumptions about positive matrix scale (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/texture_draw_quad.h ('k') | cc/texture_layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 make sure it's positive.
68 float x_scale = quadTransform().matrix().getDouble(0,0);
69 float y_scale = quadTransform().matrix().getDouble(1,1);
70 if (x_scale <= 0.0f || y_scale <= 0.0f)
71 return false;
72
73 // Grab our offset.
74 gfx::Vector2dF offset(
75 quadTransform().matrix().getDouble(0,3),
76 quadTransform().matrix().getDouble(1,3));
77
78 // Transform the rect by the scale and offset.
79 gfx::RectF rectF = rect;
80 rectF.Scale(x_scale, y_scale);
81 rectF += offset;
82
83 // Perform clipping and check to see if the result is empty.
84 gfx::RectF clippedRect = IntersectRects(rectF, clipRect());
85 if (clippedRect.IsEmpty()) {
86 rect = gfx::Rect();
87 uv_rect = gfx::RectF();
88 return true;
89 }
90
91 // Create a new uv-rect by clipping the old one to the new bounds.
92 uv_rect = gfx::RectF(
93 uv_rect.x()+uv_rect.width ()/rectF.width ()*(clippedRect.x()-rectF.x()),
94 uv_rect.y()+uv_rect.height()/rectF.height()*(clippedRect.y()-rectF.y()),
95 uv_rect.width () / rectF.width () * clippedRect.width (),
96 uv_rect.height() / rectF.height() * clippedRect.height());
97
98 // Move the clipped rectangle back into its space.
99 clippedRect -= offset;
100 clippedRect.Scale(1.0f / x_scale, 1.0f / y_scale);
101 rect = gfx::Rect(
102 static_cast<int>(clippedRect.x() + 0.5f),
103 static_cast<int>(clippedRect.y() + 0.5f),
104 static_cast<int>(clippedRect.width() + 0.5f),
105 static_cast<int>(clippedRect.height() + 0.5f));
106 return true;
107 }
108
61 } // namespace cc 109 } // namespace cc
OLDNEW
« no previous file with comments | « cc/texture_draw_quad.h ('k') | cc/texture_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698