| 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/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 3122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3133 | 3133 |
| 3134 // Child of the surface layer will produce some quads | 3134 // Child of the surface layer will produce some quads |
| 3135 addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(5, 5, rootSize.width() - 25,
rootSize.height() - 25), &childPtr); | 3135 addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(5, 5, rootSize.width() - 25,
rootSize.height() - 25), &childPtr); |
| 3136 } | 3136 } |
| 3137 | 3137 |
| 3138 class GLRendererWithReleaseTextures : public GLRenderer { | 3138 class GLRendererWithReleaseTextures : public GLRenderer { |
| 3139 public: | 3139 public: |
| 3140 using GLRenderer::releaseRenderPassTextures; | 3140 using GLRenderer::releaseRenderPassTextures; |
| 3141 }; | 3141 }; |
| 3142 | 3142 |
| 3143 TEST_P(LayerTreeHostImplTest, textureCachingWithClipping) | |
| 3144 { | |
| 3145 LayerTreeSettings settings; | |
| 3146 settings.minimumOcclusionTrackingSize = gfx::Size(); | |
| 3147 settings.partialSwapEnabled = true; | |
| 3148 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this, &m_proxy); | |
| 3149 | |
| 3150 LayerImpl* rootPtr; | |
| 3151 LayerImpl* surfaceLayerPtr; | |
| 3152 | |
| 3153 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d(scoped
_ptr<WebKit::WebGraphicsContext3D>(new PartialSwapContext)).PassAs<OutputSurface
>(); | |
| 3154 | |
| 3155 gfx::Size rootSize(100, 100); | |
| 3156 | |
| 3157 myHostImpl->initializeRenderer(outputSurface.Pass()); | |
| 3158 myHostImpl->setViewportSize(gfx::Size(rootSize.width(), rootSize.height()),
gfx::Size(rootSize.width(), rootSize.height())); | |
| 3159 | |
| 3160 scoped_ptr<LayerImpl> root = LayerImpl::create(myHostImpl->activeTree(), 1); | |
| 3161 rootPtr = root.get(); | |
| 3162 | |
| 3163 root->setAnchorPoint(gfx::PointF(0, 0)); | |
| 3164 root->setPosition(gfx::PointF(0, 0)); | |
| 3165 root->setBounds(rootSize); | |
| 3166 root->setContentBounds(rootSize); | |
| 3167 root->setDrawsContent(true); | |
| 3168 root->setMasksToBounds(true); | |
| 3169 myHostImpl->setRootLayer(root.Pass()); | |
| 3170 | |
| 3171 addDrawingLayerTo(rootPtr, 3, gfx::Rect(0, 0, rootSize.width(), rootSize.hei
ght()), &surfaceLayerPtr); | |
| 3172 surfaceLayerPtr->setDrawsContent(false); | |
| 3173 | |
| 3174 // Surface layer is the layer that changes its opacity | |
| 3175 // It will contain other layers that draw content. | |
| 3176 surfaceLayerPtr->setOpacity(0.5f); | |
| 3177 surfaceLayerPtr->setForceRenderSurface(true); // This will cause it to have
a surface | |
| 3178 | |
| 3179 addDrawingLayerTo(surfaceLayerPtr, 4, gfx::Rect(0, 0, 100, 3), 0); | |
| 3180 addDrawingLayerTo(surfaceLayerPtr, 5, gfx::Rect(0, 97, 100, 3), 0); | |
| 3181 | |
| 3182 // Rotation will put part of the child ouside the bounds of the root layer. | |
| 3183 // Nevertheless, the child layers should be drawn. | |
| 3184 gfx::Transform transform = surfaceLayerPtr->transform(); | |
| 3185 transform.Translate(50, 50); | |
| 3186 transform.Rotate(35); | |
| 3187 transform.Translate(-50, -50); | |
| 3188 surfaceLayerPtr->setTransform(transform); | |
| 3189 | |
| 3190 { | |
| 3191 LayerTreeHostImpl::FrameData frame; | |
| 3192 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | |
| 3193 | |
| 3194 // Must receive two render passes, each with one quad | |
| 3195 ASSERT_EQ(2U, frame.renderPasses.size()); | |
| 3196 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); | |
| 3197 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); | |
| 3198 | |
| 3199 // Verify that the child layers are being clipped. | |
| 3200 gfx::Rect quadVisibleRect = frame.renderPasses[0]->quad_list[0]->visible
_rect; | |
| 3201 EXPECT_LT(quadVisibleRect.width(), 100); | |
| 3202 | |
| 3203 quadVisibleRect = frame.renderPasses[0]->quad_list[1]->visible_rect; | |
| 3204 EXPECT_LT(quadVisibleRect.width(), 100); | |
| 3205 | |
| 3206 // Verify that the render surface texture is *not* clipped. | |
| 3207 EXPECT_RECT_EQ(gfx::Rect(0, 0, 100, 100), frame.renderPasses[0]->output_
rect); | |
| 3208 | |
| 3209 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma
terial); | |
| 3210 const RenderPassDrawQuad* quad = RenderPassDrawQuad::MaterialCast(frame.
renderPasses[1]->quad_list[0]); | |
| 3211 EXPECT_FALSE(quad->contents_changed_since_last_frame.IsEmpty()); | |
| 3212 | |
| 3213 myHostImpl->drawLayers(frame); | |
| 3214 myHostImpl->didDrawAllLayers(frame); | |
| 3215 } | |
| 3216 | |
| 3217 transform = surfaceLayerPtr->transform(); | |
| 3218 transform.Translate(50, 50); | |
| 3219 transform.Rotate(-35); | |
| 3220 transform.Translate(-50, -50); | |
| 3221 surfaceLayerPtr->setTransform(transform); | |
| 3222 | |
| 3223 // The surface is now aligned again, and the clipped parts are exposed. | |
| 3224 // Since the layers were clipped, even though the render surface size | |
| 3225 // was not changed, the texture should not be saved. | |
| 3226 { | |
| 3227 LayerTreeHostImpl::FrameData frame; | |
| 3228 EXPECT_TRUE(myHostImpl->prepareToDraw(frame)); | |
| 3229 | |
| 3230 // Must receive two render passes, each with one quad | |
| 3231 ASSERT_EQ(2U, frame.renderPasses.size()); | |
| 3232 EXPECT_EQ(2U, frame.renderPasses[0]->quad_list.size()); | |
| 3233 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); | |
| 3234 | |
| 3235 myHostImpl->drawLayers(frame); | |
| 3236 myHostImpl->didDrawAllLayers(frame); | |
| 3237 } | |
| 3238 } | |
| 3239 | |
| 3240 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusion) | 3143 TEST_P(LayerTreeHostImplTest, textureCachingWithOcclusion) |
| 3241 { | 3144 { |
| 3242 LayerTreeSettings settings; | 3145 LayerTreeSettings settings; |
| 3243 settings.minimumOcclusionTrackingSize = gfx::Size(); | 3146 settings.minimumOcclusionTrackingSize = gfx::Size(); |
| 3244 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this, &m_proxy); | 3147 scoped_ptr<LayerTreeHostImpl> myHostImpl = LayerTreeHostImpl::create(setting
s, this, &m_proxy); |
| 3245 | 3148 |
| 3246 // Layers are structure as follows: | 3149 // Layers are structure as follows: |
| 3247 // | 3150 // |
| 3248 // R +-- S1 +- L10 (owning) | 3151 // R +-- S1 +- L10 (owning) |
| 3249 // | +- L11 | 3152 // | +- L11 |
| (...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4921 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); | 4824 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); |
| 4922 drawFrameAndTestDamage(noDamage); | 4825 drawFrameAndTestDamage(noDamage); |
| 4923 } | 4826 } |
| 4924 | 4827 |
| 4925 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4828 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
| 4926 LayerTreeHostImplTest, | 4829 LayerTreeHostImplTest, |
| 4927 ::testing::Values(false, true)); | 4830 ::testing::Values(false, true)); |
| 4928 | 4831 |
| 4929 } // namespace | 4832 } // namespace |
| 4930 } // namespace cc | 4833 } // namespace cc |
| OLD | NEW |