OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_layer_impl.h" | 5 #include "cc/texture_layer_impl.h" |
6 | 6 |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "cc/quad_sink.h" | 8 #include "cc/quad_sink.h" |
9 #include "cc/renderer.h" | 9 #include "cc/renderer.h" |
10 #include "cc/texture_draw_quad.h" | 10 #include "cc/texture_draw_quad.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 if (!m_externalTextureResource) | 38 if (!m_externalTextureResource) |
39 return; | 39 return; |
40 | 40 |
41 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState()); | 41 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState()); |
42 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); | 42 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
43 | 43 |
44 gfx::Rect quadRect(gfx::Point(), contentBounds()); | 44 gfx::Rect quadRect(gfx::Point(), contentBounds()); |
45 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); | 45 gfx::Rect opaqueRect(contentsOpaque() ? quadRect : gfx::Rect()); |
46 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | 46 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); |
47 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResourc e, m_premultipliedAlpha, m_uvRect, m_flipped); | 47 quad->SetNew(sharedQuadState, quadRect, opaqueRect, m_externalTextureResourc e, m_premultipliedAlpha, m_uvRect, m_flipped); |
48 | |
49 if (quad->quadTransform().IsScaleOrTranslation()) | |
shawnsingh
2012/12/03 23:37:52
A few more thoughts:
(1) Don't we need an isClipp
whunt
2012/12/04 00:01:24
I added the isClipped check.
I can make it a help
| |
50 { | |
51 // Grab the corners of our boxes. | |
52 float rect_min_x = quad->rect.x(); | |
53 float rect_min_y = quad->rect.y(); | |
54 float rect_max_x = rect_min_x + quad->rect.width(); | |
55 float rect_max_y = rect_min_y + quad->rect.height(); | |
56 | |
57 // Grab the relevant values from our matrix. | |
58 float x_scale = quad->quadTransform().matrix().getDouble(0,0); | |
59 float y_scale = quad->quadTransform().matrix().getDouble(1,1); | |
60 float x_offset = quad->quadTransform().matrix().getDouble(0,3); | |
61 float y_offset = quad->quadTransform().matrix().getDouble(1,3); | |
62 | |
63 // Transform the rect to the same space as the clip. | |
64 rect_min_x = x_scale * rect_min_x + x_offset; | |
65 rect_min_y = y_scale * rect_min_y + y_offset; | |
66 rect_max_x = x_scale * rect_max_x + x_offset; | |
67 rect_max_y = y_scale * rect_max_y + y_offset; | |
68 | |
69 // Grab the clipped region. | |
70 float clip_min_x = quad->clipRect().x(); | |
71 float clip_min_y = quad->clipRect().y(); | |
72 float clip_max_x = clip_min_x + quad->clipRect().width(); | |
73 float clip_max_y = clip_min_y + quad->clipRect().height(); | |
74 | |
75 // Perform clipping on the rect. | |
shawnsingh
2012/12/03 23:34:08
Unless there's some performance caveats, I think w
whunt
2012/12/04 00:01:24
There are certainly performance caveats to using g
jamesr
2012/12/04 00:15:42
Would you mind running cc_perftests on this with t
whunt
2012/12/04 19:35:04
Given that this code gets run ~8 times/frame in th
| |
76 float min_x = std::max(rect_min_x, clip_min_x); | |
77 float min_y = std::max(rect_min_y, clip_min_y); | |
78 float max_x = std::min(rect_max_x, clip_max_x); | |
79 float max_y = std::min(rect_max_y, clip_max_y); | |
80 | |
81 // Empty bounds mean that this is clipped completely away. | |
82 if (min_x > max_x || min_y > max_y) | |
83 return; | |
84 | |
85 // Create a new uv-rect by clipping the old one to the new bounds. | |
86 quad->uv_rect = gfx::RectF( | |
87 quad->uv_rect.x() + quad->uv_rect.width () * (1.0f / (rect_max_x - r ect_min_x)) * (min_x - rect_min_x), | |
shawnsingh
2012/12/03 23:34:08
how about (min_x - rect_min_x) / (rect_max_x - rec
whunt
2012/12/04 00:01:24
Ditto as previous comment.
On 2012/12/03 23:34:08
| |
88 quad->uv_rect.y() + quad->uv_rect.height() * (1.0f / (rect_max_y - r ect_min_y)) * (min_y - rect_min_y), | |
89 quad->uv_rect.width () * (1.0f / (rect_max_x - rect_min_x)) * (max_x - min_x), | |
90 quad->uv_rect.height() * (1.0f / (rect_max_y - rect_min_y)) * (max_y - min_y)); | |
91 | |
92 // Move the clipped rectangle back into its space. | |
93 quad->rect = gfx::Rect( | |
shawnsingh
2012/12/03 23:34:08
Its likely that scaling and translation are operat
whunt
2012/12/04 00:01:24
Ditto again.
On 2012/12/03 23:34:08, shawnsingh w
| |
94 (int)((min_x - x_offset) * (1.0f / x_scale) + 0.5f), | |
jamesr
2012/12/04 00:15:42
we prefer c++ style casts to c-style cases in chro
| |
95 (int)((min_y - y_offset) * (1.0f / y_scale) + 0.5f), | |
96 (int)((max_x - min_x) * (1.0f / x_scale) + 0.5f), | |
97 (int)((max_y - min_y) * (1.0f / y_scale) + 0.5f)); | |
98 | |
99 // Disable hardware clipping | |
100 sharedQuadState->is_clipped = false; | |
101 } | |
102 | |
48 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); | 103 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); |
49 } | 104 } |
50 | 105 |
51 void TextureLayerImpl::didDraw(ResourceProvider* resourceProvider) | 106 void TextureLayerImpl::didDraw(ResourceProvider* resourceProvider) |
52 { | 107 { |
53 if (!m_externalTextureResource) | 108 if (!m_externalTextureResource) |
54 return; | 109 return; |
55 // FIXME: the following assert will not be true when sending resources to a | 110 // FIXME: the following assert will not be true when sending resources to a |
56 // parent compositor. A synchronization scheme (double-buffering or | 111 // parent compositor. A synchronization scheme (double-buffering or |
57 // pipelining of updates) for the client will need to exist to solve this. | 112 // pipelining of updates) for the client will need to exist to solve this. |
(...skipping 14 matching lines...) Expand all Loading... | |
72 m_textureId = 0; | 127 m_textureId = 0; |
73 m_externalTextureResource = 0; | 128 m_externalTextureResource = 0; |
74 } | 129 } |
75 | 130 |
76 const char* TextureLayerImpl::layerTypeAsString() const | 131 const char* TextureLayerImpl::layerTypeAsString() const |
77 { | 132 { |
78 return "TextureLayer"; | 133 return "TextureLayer"; |
79 } | 134 } |
80 | 135 |
81 } // namespace cc | 136 } // namespace cc |
OLD | NEW |