| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/tiled_layer.h" | 7 #include "cc/tiled_layer.h" |
| 8 | 8 |
| 9 #include "cc/bitmap_content_layer_updater.h" | 9 #include "cc/bitmap_content_layer_updater.h" |
| 10 #include "cc/layer_painter.h" | 10 #include "cc/layer_painter.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 class TestOcclusionTracker : public OcclusionTracker { | 30 class TestOcclusionTracker : public OcclusionTracker { |
| 31 public: | 31 public: |
| 32 TestOcclusionTracker() | 32 TestOcclusionTracker() |
| 33 : OcclusionTracker(gfx::Rect(0, 0, 1000, 1000), true) | 33 : OcclusionTracker(gfx::Rect(0, 0, 1000, 1000), true) |
| 34 , m_layerClipRectInTarget(gfx::Rect(0, 0, 1000, 1000)) | 34 , m_layerClipRectInTarget(gfx::Rect(0, 0, 1000, 1000)) |
| 35 { | 35 { |
| 36 // Pretend we have visited a render surface. | 36 // Pretend we have visited a render surface. |
| 37 m_stack.append(StackObject()); | 37 m_stack.push_back(StackObject()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void setOcclusion(const Region& occlusion) { m_stack.last().occlusionInTarge
t = occlusion; } | 40 void setOcclusion(const Region& occlusion) { m_stack.back().occlusionInTarge
t = occlusion; } |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 virtual gfx::Rect layerClipRectInTarget(const Layer* layer) const OVERRIDE {
return m_layerClipRectInTarget; } | 43 virtual gfx::Rect layerClipRectInTarget(const Layer* layer) const OVERRIDE {
return m_layerClipRectInTarget; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 gfx::Rect m_layerClipRectInTarget; | 46 gfx::Rect m_layerClipRectInTarget; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class TiledLayerTest : public testing::Test { | 49 class TiledLayerTest : public testing::Test { |
| 50 public: | 50 public: |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1263 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1
); | 1263 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000, 1
); |
| 1264 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1264 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
| 1265 | 1265 |
| 1266 // visibleContentOpaqueRegion should match the visible part of what is paint
ed opaque. | 1266 // visibleContentOpaqueRegion should match the visible part of what is paint
ed opaque. |
| 1267 opaquePaintRect = gfx::Rect(10, 10, 90, 190); | 1267 opaquePaintRect = gfx::Rect(10, 10, 90, 190); |
| 1268 layer->fakeLayerUpdater()->setOpaquePaintRect(opaquePaintRect); | 1268 layer->fakeLayerUpdater()->setOpaquePaintRect(opaquePaintRect); |
| 1269 layer->invalidateContentRect(contentBounds); | 1269 layer->invalidateContentRect(contentBounds); |
| 1270 layer->update(*m_queue.get(), &occluded, m_stats); | 1270 layer->update(*m_queue.get(), &occluded, m_stats); |
| 1271 updateTextures(); | 1271 updateTextures(); |
| 1272 opaqueContents = layer->visibleContentOpaqueRegion(); | 1272 opaqueContents = layer->visibleContentOpaqueRegion(); |
| 1273 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo
ntents.bounds()); | 1273 EXPECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds).ToString(), op
aqueContents.ToString()); |
| 1274 EXPECT_EQ(1u, Region::Iterator(opaqueContents).size()); | |
| 1275 | 1274 |
| 1276 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); | 1275 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); |
| 1277 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); | 1276 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); |
| 1278 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100, 1); | 1277 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100, 1); |
| 1279 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1278 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
| 1280 | 1279 |
| 1281 // If we paint again without invalidating, the same stuff should be opaque. | 1280 // If we paint again without invalidating, the same stuff should be opaque. |
| 1282 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); | 1281 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); |
| 1283 layer->update(*m_queue.get(), &occluded, m_stats); | 1282 layer->update(*m_queue.get(), &occluded, m_stats); |
| 1284 updateTextures(); | 1283 updateTextures(); |
| 1285 opaqueContents = layer->visibleContentOpaqueRegion(); | 1284 opaqueContents = layer->visibleContentOpaqueRegion(); |
| 1286 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo
ntents.bounds()); | 1285 EXPECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds).ToString(), op
aqueContents.ToString()); |
| 1287 EXPECT_EQ(1u, Region::Iterator(opaqueContents).size()); | |
| 1288 | 1286 |
| 1289 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); | 1287 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2, 1); |
| 1290 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); | 1288 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); |
| 1291 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100, 1); | 1289 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100, 1); |
| 1292 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1290 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
| 1293 | 1291 |
| 1294 // If we repaint a non-opaque part of the tile, then it shouldn't lose its o
paque-ness. And other tiles should | 1292 // If we repaint a non-opaque part of the tile, then it shouldn't lose its o
paque-ness. And other tiles should |
| 1295 // not be affected. | 1293 // not be affected. |
| 1296 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); | 1294 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); |
| 1297 layer->invalidateContentRect(gfx::Rect(0, 0, 1, 1)); | 1295 layer->invalidateContentRect(gfx::Rect(0, 0, 1, 1)); |
| 1298 layer->update(*m_queue.get(), &occluded, m_stats); | 1296 layer->update(*m_queue.get(), &occluded, m_stats); |
| 1299 updateTextures(); | 1297 updateTextures(); |
| 1300 opaqueContents = layer->visibleContentOpaqueRegion(); | 1298 opaqueContents = layer->visibleContentOpaqueRegion(); |
| 1301 EXPECT_RECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds), opaqueCo
ntents.bounds()); | 1299 EXPECT_EQ(gfx::IntersectRects(opaquePaintRect, visibleBounds).ToString(), op
aqueContents.ToString()); |
| 1302 EXPECT_EQ(1u, Region::Iterator(opaqueContents).size()); | |
| 1303 | 1300 |
| 1304 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1, 1); | 1301 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1, 1); |
| 1305 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); | 1302 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); |
| 1306 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100 + 1, 1); | 1303 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100 + 1, 1); |
| 1307 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1304 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
| 1308 | 1305 |
| 1309 // If we repaint an opaque part of the tile, then it should lose its opaque-
ness. But other tiles should still | 1306 // If we repaint an opaque part of the tile, then it should lose its opaque-
ness. But other tiles should still |
| 1310 // not be affected. | 1307 // not be affected. |
| 1311 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); | 1308 layer->fakeLayerUpdater()->setOpaquePaintRect(gfx::Rect()); |
| 1312 layer->invalidateContentRect(gfx::Rect(10, 10, 1, 1)); | 1309 layer->invalidateContentRect(gfx::Rect(10, 10, 1, 1)); |
| 1313 layer->update(*m_queue.get(), &occluded, m_stats); | 1310 layer->update(*m_queue.get(), &occluded, m_stats); |
| 1314 updateTextures(); | 1311 updateTextures(); |
| 1315 opaqueContents = layer->visibleContentOpaqueRegion(); | 1312 opaqueContents = layer->visibleContentOpaqueRegion(); |
| 1316 EXPECT_RECT_EQ(gfx::IntersectRects(gfx::Rect(10, 100, 90, 100), visibleBound
s), opaqueContents.bounds()); | 1313 EXPECT_EQ(gfx::IntersectRects(gfx::Rect(10, 100, 90, 100), visibleBounds).To
String(), opaqueContents.ToString()); |
| 1317 EXPECT_EQ(1u, Region::Iterator(opaqueContents).size()); | |
| 1318 | 1314 |
| 1319 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1 + 1,
1); | 1315 EXPECT_NEAR(occluded.overdrawMetrics().pixelsPainted(), 20000 * 2 + 1 + 1,
1); |
| 1320 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); | 1316 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedOpaque(), 17100, 1); |
| 1321 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100 + 1 + 1, 1); | 1317 EXPECT_NEAR(occluded.overdrawMetrics().pixelsUploadedTranslucent(), 20000 +
20000 - 17100 + 1 + 1, 1); |
| 1322 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); | 1318 EXPECT_EQ(0, occluded.overdrawMetrics().tilesCulledForUpload()); |
| 1323 } | 1319 } |
| 1324 | 1320 |
| 1325 TEST_F(TiledLayerTest, pixelsPaintedMetrics) | 1321 TEST_F(TiledLayerTest, pixelsPaintedMetrics) |
| 1326 { | 1322 { |
| 1327 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); | 1323 scoped_refptr<FakeTiledLayer> layer = make_scoped_refptr(new FakeTiledLayer(
m_textureManager.get())); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1621 updateTextures(); | 1617 updateTextures(); |
| 1622 | 1618 |
| 1623 // Invalidate the entire layer in layer space. When painting, the rect given
to webkit should match the layer's bounds. | 1619 // Invalidate the entire layer in layer space. When painting, the rect given
to webkit should match the layer's bounds. |
| 1624 layer->setNeedsDisplayRect(layerRect); | 1620 layer->setNeedsDisplayRect(layerRect); |
| 1625 layer->update(*m_queue.get(), 0, m_stats); | 1621 layer->update(*m_queue.get(), 0, m_stats); |
| 1626 | 1622 |
| 1627 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); | 1623 EXPECT_RECT_EQ(layerRect, layer->trackingLayerPainter()->paintedRect()); |
| 1628 } | 1624 } |
| 1629 | 1625 |
| 1630 } // anonymous namespace | 1626 } // anonymous namespace |
| OLD | NEW |