Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "media/base/video_frame.h" | 5 #include "media/base/video_frame.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 | 233 |
| 234 // Ensure each frame is properly sized and allocated. Will trigger OOB reads | 234 // Ensure each frame is properly sized and allocated. Will trigger OOB reads |
| 235 // and writes as well as incorrect frame hashes otherwise. | 235 // and writes as well as incorrect frame hashes otherwise. |
| 236 TEST(VideoFrame, CheckFrameExtents) { | 236 TEST(VideoFrame, CheckFrameExtents) { |
| 237 // Each call consists of a VideoFrame::Format and the expected hash of all | 237 // Each call consists of a VideoFrame::Format and the expected hash of all |
| 238 // planes if filled with kFillByte (defined in ExpectFrameExtents). | 238 // planes if filled with kFillByte (defined in ExpectFrameExtents). |
| 239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); | 239 ExpectFrameExtents(VideoFrame::YV12, "8e5d54cb23cd0edca111dd35ffb6ff05"); |
| 240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef"); | 240 ExpectFrameExtents(VideoFrame::YV16, "cce408a044b212db42a10dfec304b3ef"); |
| 241 } | 241 } |
| 242 | 242 |
| 243 static void TextureCallback(uint32* called_sync_point, | 243 static void TextureCallback(std::vector<uint32>* called_sync_point, |
| 244 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 244 const std::vector<uint32>& release_sync_points) { |
| 245 *called_sync_point = mailbox_holder->sync_point; | 245 called_sync_point->clear(); |
| 246 called_sync_point->assign(release_sync_points.begin(), | |
|
Ami GONE FROM CHROMIUM
2014/04/24 01:19:50
assign obviates the need for clear?
dshwang
2014/04/24 05:07:16
Done in new patch set.
| |
| 247 release_sync_points.end()); | |
| 246 } | 248 } |
| 247 | 249 |
| 248 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 250 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 249 // destroyed with the original sync point. | 251 // destroyed with the default release sync points. |
| 250 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 252 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
| 251 uint32 sync_point = 7; | 253 std::vector<uint32> called_sync_points; |
| 252 uint32 called_sync_point = 0; | 254 called_sync_points.push_back(1); |
| 253 | 255 |
| 254 { | 256 { |
| 255 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 257 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 256 make_scoped_ptr(new gpu::MailboxHolder(gpu::Mailbox(), 5, sync_point)), | 258 make_scoped_ptr( |
| 257 base::Bind(&TextureCallback, &called_sync_point), | 259 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), |
| 258 gfx::Size(10, 10), // coded_size | 260 base::Bind(&TextureCallback, &called_sync_points), |
| 259 gfx::Rect(10, 10), // visible_rect | 261 gfx::Size(10, 10), // coded_size |
| 260 gfx::Size(10, 10), // natural_size | 262 gfx::Rect(10, 10), // visible_rect |
| 261 base::TimeDelta(), // timestamp | 263 gfx::Size(10, 10), // natural_size |
| 262 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 264 base::TimeDelta(), // timestamp |
| 265 VideoFrame::ReadPixelsCB()); // read_pixels_cb | |
| 263 | 266 |
| 264 EXPECT_EQ(0u, called_sync_point); | 267 EXPECT_EQ(1u, called_sync_points.size()); |
| 265 } | 268 } |
| 266 EXPECT_EQ(sync_point, called_sync_point); | 269 EXPECT_TRUE(called_sync_points.empty()); |
| 267 } | 270 } |
| 268 | 271 |
| 269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 272 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 270 // destroyed with the new sync point, when the mailbox is accessed by a caller. | 273 // destroyed with the release sync points, which was updated by clients. |
| 274 // (i.e. the compositor, webgl). | |
| 271 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | 275 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { |
| 272 uint32 called_sync_point = 0; | 276 std::vector<uint32> called_sync_points; |
| 273 | 277 |
| 274 gpu::Mailbox mailbox; | 278 gpu::Mailbox mailbox; |
| 275 mailbox.name[0] = 50; | 279 mailbox.name[0] = 50; |
| 276 uint32 sync_point = 7; | 280 uint32 sync_point = 7; |
| 277 uint32 target = 9; | 281 uint32 target = 9; |
| 282 std::vector<uint32> release_sync_points; | |
| 283 release_sync_points.push_back(1); | |
| 284 release_sync_points.push_back(2); | |
| 285 release_sync_points.push_back(3); | |
| 278 | 286 |
| 279 { | 287 { |
| 280 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 288 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 281 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), | 289 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), |
| 282 base::Bind(&TextureCallback, &called_sync_point), | 290 base::Bind(&TextureCallback, &called_sync_points), |
| 283 gfx::Size(10, 10), // coded_size | 291 gfx::Size(10, 10), // coded_size |
| 284 gfx::Rect(10, 10), // visible_rect | 292 gfx::Rect(10, 10), // visible_rect |
| 285 gfx::Size(10, 10), // natural_size | 293 gfx::Size(10, 10), // natural_size |
| 286 base::TimeDelta(), // timestamp | 294 base::TimeDelta(), // timestamp |
| 287 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 295 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
| 296 EXPECT_TRUE(called_sync_points.empty()); | |
| 288 | 297 |
| 289 gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); | 298 const gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); |
| 290 | 299 |
| 291 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); | 300 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); |
| 292 EXPECT_EQ(target, mailbox_holder->texture_target); | 301 EXPECT_EQ(target, mailbox_holder->texture_target); |
| 293 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 302 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
| 294 | 303 |
| 295 // Finish using the mailbox_holder and drop our reference. | 304 frame->AppendReleaseSyncPoint(release_sync_points[0]); |
| 296 sync_point = 10; | 305 frame->AppendReleaseSyncPoint(release_sync_points[1]); |
| 297 mailbox_holder->sync_point = sync_point; | 306 frame->AppendReleaseSyncPoint(release_sync_points[2]); |
| 307 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | |
| 298 } | 308 } |
| 299 EXPECT_EQ(sync_point, called_sync_point); | 309 EXPECT_EQ(release_sync_points, called_sync_points); |
| 300 } | 310 } |
| 301 | 311 |
| 302 } // namespace media | 312 } // namespace media |
| OLD | NEW |