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

Unified Diff: content/browser/compositor/buffer_queue_unittest.cc

Issue 1423843003: Make content::BufferQueue use scoped ptrs for AllocatedSurfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@surfaceless_only
Patch Set: Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/compositor/buffer_queue_unittest.cc
diff --git a/content/browser/compositor/buffer_queue_unittest.cc b/content/browser/compositor/buffer_queue_unittest.cc
index 82a798e32f2e93e8b14de0b8739606676d7ca725..cd0842c4a0f4343348987b6e26cde6a7f88d347f 100644
--- a/content/browser/compositor/buffer_queue_unittest.cc
+++ b/content/browser/compositor/buffer_queue_unittest.cc
@@ -94,31 +94,38 @@ class BufferQueueTest : public ::testing::Test {
output_surface_->Initialize();
}
- unsigned current_surface() { return output_surface_->current_surface_.image; }
- const std::vector<BufferQueue::AllocatedSurface>& available_surfaces() {
+ unsigned current_surface() {
+ return output_surface_->current_surface_
+ ? output_surface_->current_surface_->image
+ : 0;
+ }
+ const cc::ScopedPtrVector<BufferQueue::AllocatedSurface>&
+ available_surfaces() {
return output_surface_->available_surfaces_;
}
- const std::deque<BufferQueue::AllocatedSurface>& in_flight_surfaces() {
+ const cc::ScopedPtrDeque<BufferQueue::AllocatedSurface>&
+ in_flight_surfaces() {
return output_surface_->in_flight_surfaces_;
}
-
- const BufferQueue::AllocatedSurface& displayed_frame() {
- return output_surface_->displayed_surface_;
+ size_t in_flight_surface_count() {
+ return output_surface_->in_flight_surfaces_.size() +
+ output_surface_->deleted_in_flight_surface_count_;
}
- const BufferQueue::AllocatedSurface& current_frame() {
- return output_surface_->current_surface_;
+
+ const BufferQueue::AllocatedSurface* displayed_frame() {
+ return output_surface_->displayed_surface_.get();
}
- const BufferQueue::AllocatedSurface& last_frame() {
- return output_surface_->in_flight_surfaces_.back();
+ const BufferQueue::AllocatedSurface* current_frame() {
+ return output_surface_->current_surface_.get();
}
- const BufferQueue::AllocatedSurface& next_frame() {
+ const BufferQueue::AllocatedSurface* next_frame() {
return output_surface_->available_surfaces_.back();
}
const gfx::Size size() { return output_surface_->size_; }
int CountBuffers() {
int n = available_surfaces().size() + in_flight_surfaces().size() +
- (displayed_frame().texture ? 1 : 0);
+ (displayed_frame() ? 1 : 0);
if (current_surface())
n++;
return n;
@@ -128,14 +135,12 @@ class BufferQueueTest : public ::testing::Test {
void CheckUnique() {
std::set<unsigned> buffers;
EXPECT_TRUE(InsertUnique(&buffers, current_surface()));
- EXPECT_TRUE(InsertUnique(&buffers, displayed_frame().image));
+ if (displayed_frame())
+ EXPECT_TRUE(InsertUnique(&buffers, displayed_frame()->image));
for (size_t i = 0; i < available_surfaces().size(); i++)
- EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i].image));
- for (std::deque<BufferQueue::AllocatedSurface>::const_iterator it =
- in_flight_surfaces().begin();
- it != in_flight_surfaces().end();
- ++it)
- EXPECT_TRUE(InsertUnique(&buffers, it->image));
+ EXPECT_TRUE(InsertUnique(&buffers, available_surfaces()[i]->image));
+ for (size_t i = 0; i < in_flight_surfaces().size(); i++)
+ EXPECT_TRUE(InsertUnique(&buffers, in_flight_surfaces()[i]->image));
}
void SwapBuffers() {
@@ -314,7 +319,7 @@ TEST_F(BufferQueueTest, PartialSwapReuse) {
SendDamagedFrame(small_damage);
SendDamagedFrame(large_damage);
// Verify that the damage has propagated.
- EXPECT_EQ(next_frame().damage, large_damage);
+ EXPECT_EQ(next_frame()->damage, large_damage);
}
TEST_F(BufferQueueTest, PartialSwapFullFrame) {
@@ -326,7 +331,7 @@ TEST_F(BufferQueueTest, PartialSwapFullFrame) {
SendDamagedFrame(small_damage);
SendFullFrame();
SendFullFrame();
- EXPECT_EQ(next_frame().damage, screen_rect);
+ EXPECT_EQ(next_frame()->damage, screen_rect);
}
TEST_F(BufferQueueTest, PartialSwapOverlapping) {
@@ -340,7 +345,7 @@ TEST_F(BufferQueueTest, PartialSwapOverlapping) {
SendFullFrame();
SendDamagedFrame(small_damage);
SendDamagedFrame(overlapping_damage);
- EXPECT_EQ(next_frame().damage, overlapping_damage);
+ EXPECT_EQ(next_frame()->damage, overlapping_damage);
}
TEST_F(BufferQueueTest, MultipleBindCalls) {
@@ -359,27 +364,27 @@ TEST_F(BufferQueueTest, CheckDoubleBuffering) {
output_surface_->BindFramebuffer();
EXPECT_EQ(1, CountBuffers());
EXPECT_NE(0U, current_surface());
- EXPECT_FALSE(displayed_frame().texture);
+ EXPECT_FALSE(displayed_frame());
SwapBuffers();
EXPECT_EQ(1U, in_flight_surfaces().size());
output_surface_->PageFlipComplete();
EXPECT_EQ(0U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
output_surface_->BindFramebuffer();
EXPECT_EQ(2, CountBuffers());
CheckUnique();
EXPECT_NE(0U, current_surface());
EXPECT_EQ(0U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
SwapBuffers();
CheckUnique();
EXPECT_EQ(1U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
output_surface_->PageFlipComplete();
CheckUnique();
EXPECT_EQ(0U, in_flight_surfaces().size());
EXPECT_EQ(1U, available_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
output_surface_->BindFramebuffer();
EXPECT_EQ(2, CountBuffers());
CheckUnique();
@@ -391,7 +396,7 @@ TEST_F(BufferQueueTest, CheckTripleBuffering) {
// This bit is the same sequence tested in the doublebuffering case.
output_surface_->BindFramebuffer();
- EXPECT_FALSE(displayed_frame().texture);
+ EXPECT_FALSE(displayed_frame());
SwapBuffers();
output_surface_->PageFlipComplete();
output_surface_->BindFramebuffer();
@@ -400,19 +405,19 @@ TEST_F(BufferQueueTest, CheckTripleBuffering) {
EXPECT_EQ(2, CountBuffers());
CheckUnique();
EXPECT_EQ(1U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
output_surface_->BindFramebuffer();
EXPECT_EQ(3, CountBuffers());
CheckUnique();
EXPECT_NE(0U, current_surface());
EXPECT_EQ(1U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
output_surface_->PageFlipComplete();
EXPECT_EQ(3, CountBuffers());
CheckUnique();
EXPECT_NE(0U, current_surface());
EXPECT_EQ(0U, in_flight_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
+ EXPECT_TRUE(displayed_frame());
EXPECT_EQ(1U, available_surfaces().size());
}
@@ -425,9 +430,9 @@ TEST_F(BufferQueueTest, CheckCorrectBufferOrdering) {
EXPECT_EQ(kSwapCount, in_flight_surfaces().size());
for (size_t i = 0; i < kSwapCount; ++i) {
- unsigned int next_texture_id = in_flight_surfaces().front().texture;
+ unsigned int next_texture_id = in_flight_surfaces().front()->texture;
output_surface_->PageFlipComplete();
- EXPECT_EQ(displayed_frame().texture, next_texture_id);
+ EXPECT_EQ(displayed_frame()->texture, next_texture_id);
}
}
@@ -439,11 +444,11 @@ TEST_F(BufferQueueTest, ReshapeWithInFlightSurfaces) {
}
output_surface_->Reshape(gfx::Size(10, 20), 1.0f);
- EXPECT_EQ(3u, in_flight_surfaces().size());
+ EXPECT_EQ(3u, in_flight_surface_count());
for (size_t i = 0; i < kSwapCount; ++i) {
output_surface_->PageFlipComplete();
- EXPECT_EQ(0u, displayed_frame().texture);
+ EXPECT_FALSE(displayed_frame());
}
// The dummy surfacess left should be discarded.
@@ -464,20 +469,20 @@ TEST_F(BufferQueueTest, SwapAfterReshape) {
SwapBuffers();
}
- EXPECT_EQ(2 * kSwapCount, in_flight_surfaces().size());
+ EXPECT_EQ(2 * kSwapCount, in_flight_surface_count());
for (size_t i = 0; i < kSwapCount; ++i) {
output_surface_->PageFlipComplete();
- EXPECT_EQ(0u, displayed_frame().texture);
+ EXPECT_FALSE(displayed_frame());
}
CheckUnique();
for (size_t i = 0; i < kSwapCount; ++i) {
- unsigned int next_texture_id = in_flight_surfaces().front().texture;
+ unsigned int next_texture_id = in_flight_surfaces().front()->texture;
output_surface_->PageFlipComplete();
- EXPECT_EQ(displayed_frame().texture, next_texture_id);
- EXPECT_NE(0u, displayed_frame().texture);
+ EXPECT_EQ(displayed_frame()->texture, next_texture_id);
+ EXPECT_TRUE(displayed_frame());
}
}
@@ -503,8 +508,8 @@ TEST_F(BufferQueueMockedContextTest, RecreateBuffers) {
// being drawn to.
ASSERT_EQ(1U, in_flight_surfaces().size());
ASSERT_EQ(1U, available_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
- EXPECT_TRUE(current_frame().texture);
+ EXPECT_TRUE(displayed_frame()->texture);
+ EXPECT_TRUE(current_frame()->texture);
auto current = current_frame();
auto displayed = displayed_frame();
@@ -514,26 +519,26 @@ TEST_F(BufferQueueMockedContextTest, RecreateBuffers) {
// Expect all 4 images to be destroyed, 3 of the existing textures to be
// copied from and 3 new images to be created.
EXPECT_CALL(*context_, createImageCHROMIUM(_, 0, 0, GL_RGBA)).Times(3);
- Expectation copy1 =
- EXPECT_CALL(*mock_output_surface_,
- CopyBufferDamage(_, displayed.texture, _, _)).Times(1);
- Expectation copy2 =
- EXPECT_CALL(*mock_output_surface_,
- CopyBufferDamage(_, current.texture, _, _)).Times(1);
- Expectation copy3 =
- EXPECT_CALL(*mock_output_surface_,
- CopyBufferDamage(_, in_flight.texture, _, _)).Times(1);
-
- EXPECT_CALL(*context_, destroyImageCHROMIUM(displayed.image))
+ Expectation copy1 = EXPECT_CALL(*mock_output_surface_,
+ CopyBufferDamage(_, displayed->texture, _, _))
+ .Times(1);
+ Expectation copy2 = EXPECT_CALL(*mock_output_surface_,
+ CopyBufferDamage(_, current->texture, _, _))
+ .Times(1);
+ Expectation copy3 = EXPECT_CALL(*mock_output_surface_,
+ CopyBufferDamage(_, in_flight->texture, _, _))
+ .Times(1);
+
+ EXPECT_CALL(*context_, destroyImageCHROMIUM(displayed->image))
.Times(1)
.After(copy1);
- EXPECT_CALL(*context_, destroyImageCHROMIUM(current.image))
+ EXPECT_CALL(*context_, destroyImageCHROMIUM(current->image))
.Times(1)
.After(copy2);
- EXPECT_CALL(*context_, destroyImageCHROMIUM(in_flight.image))
+ EXPECT_CALL(*context_, destroyImageCHROMIUM(in_flight->image))
.Times(1)
.After(copy3);
- EXPECT_CALL(*context_, destroyImageCHROMIUM(available.image)).Times(1);
+ EXPECT_CALL(*context_, destroyImageCHROMIUM(available->image)).Times(1);
// After copying, we expect the framebuffer binding to be updated.
EXPECT_CALL(*context_, bindFramebuffer(_, _))
.After(copy1)
@@ -550,10 +555,10 @@ TEST_F(BufferQueueMockedContextTest, RecreateBuffers) {
// All free buffers should be destroyed, the remaining buffers should all
// be replaced but still valid.
- EXPECT_EQ(1U, in_flight_surfaces().size());
+ EXPECT_EQ(1U, in_flight_surface_count());
EXPECT_EQ(0U, available_surfaces().size());
- EXPECT_TRUE(displayed_frame().texture);
- EXPECT_TRUE(current_frame().texture);
+ EXPECT_TRUE(displayed_frame()->texture);
+ EXPECT_TRUE(current_frame()->texture);
}
} // namespace
« content/browser/compositor/buffer_queue.cc ('K') | « content/browser/compositor/buffer_queue.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698