| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 TEST(VideoFrame, CheckFrameExtents) { | 238 TEST(VideoFrame, CheckFrameExtents) { |
| 239 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, | 239 // Each call consists of a VideoFrame::Format, # of planes, bytes per pixel, |
| 240 // and the expected hash of all planes if filled with kFillByte (defined in | 240 // and the expected hash of all planes if filled with kFillByte (defined in |
| 241 // ExpectFrameExtents). | 241 // ExpectFrameExtents). |
| 242 ExpectFrameExtents( | 242 ExpectFrameExtents( |
| 243 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); | 243 VideoFrame::YV12, 3, 1, "71113bdfd4c0de6cf62f48fb74f7a0b1"); |
| 244 ExpectFrameExtents( | 244 ExpectFrameExtents( |
| 245 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); | 245 VideoFrame::YV16, 3, 1, "9bb99ac3ff350644ebff4d28dc01b461"); |
| 246 } | 246 } |
| 247 | 247 |
| 248 static void TextureCallback(uint32* called_sync_point, | 248 static void TextureCallback(std::vector<uint32>* called_sync_point, |
| 249 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 249 scoped_ptr<gpu::MailboxHolder> mailbox_holder, |
| 250 *called_sync_point = mailbox_holder->sync_point; | 250 const std::vector<uint32>& release_sync_points) { |
| 251 std::vector<uint32> sync_points(release_sync_points); |
| 252 called_sync_point->swap(sync_points); |
| 251 } | 253 } |
| 252 | 254 |
| 253 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 255 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 254 // destroyed with the original sync point. | 256 // destroyed with the default release sync points. |
| 255 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { | 257 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { |
| 256 uint32 sync_point = 7; | 258 std::vector<uint32> called_sync_points; |
| 257 uint32 called_sync_point = 0; | 259 called_sync_points.push_back(1); |
| 258 | 260 |
| 259 { | 261 { |
| 260 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 262 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 261 make_scoped_ptr(new gpu::MailboxHolder(gpu::Mailbox(), 5, sync_point)), | 263 make_scoped_ptr( |
| 262 base::Bind(&TextureCallback, &called_sync_point), | 264 new gpu::MailboxHolder(gpu::Mailbox(), 5, 0 /* sync_point */)), |
| 263 gfx::Size(10, 10), // coded_size | 265 base::Bind(&TextureCallback, &called_sync_points), |
| 264 gfx::Rect(10, 10), // visible_rect | 266 gfx::Size(10, 10), // coded_size |
| 265 gfx::Size(10, 10), // natural_size | 267 gfx::Rect(10, 10), // visible_rect |
| 266 base::TimeDelta(), // timestamp | 268 gfx::Size(10, 10), // natural_size |
| 267 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 269 base::TimeDelta(), // timestamp |
| 270 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
| 268 | 271 |
| 269 EXPECT_EQ(0u, called_sync_point); | 272 EXPECT_EQ(1u, called_sync_points.size()); |
| 270 } | 273 } |
| 271 EXPECT_EQ(sync_point, called_sync_point); | 274 EXPECT_TRUE(called_sync_points.empty()); |
| 272 } | 275 } |
| 273 | 276 |
| 274 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is | 277 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is |
| 275 // destroyed with the new sync point, when the mailbox is accessed by a caller. | 278 // destroyed with the release sync points, which was updated by clients. |
| 279 // (i.e. the compositor, webgl). |
| 276 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { | 280 TEST(VideoFrame, TextureNoLongerNeededCallbackAfterTakingAndReleasingMailbox) { |
| 277 uint32 called_sync_point = 0; | 281 std::vector<uint32> called_sync_points; |
| 278 | 282 |
| 279 gpu::Mailbox mailbox; | 283 gpu::Mailbox mailbox; |
| 280 mailbox.name[0] = 50; | 284 mailbox.name[0] = 50; |
| 281 uint32 sync_point = 7; | 285 uint32 sync_point = 7; |
| 282 uint32 target = 9; | 286 uint32 target = 9; |
| 287 std::vector<uint32> release_sync_points; |
| 288 release_sync_points.push_back(1); |
| 289 release_sync_points.push_back(2); |
| 290 release_sync_points.push_back(3); |
| 283 | 291 |
| 284 { | 292 { |
| 285 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( | 293 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( |
| 286 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), | 294 make_scoped_ptr(new gpu::MailboxHolder(mailbox, target, sync_point)), |
| 287 base::Bind(&TextureCallback, &called_sync_point), | 295 base::Bind(&TextureCallback, &called_sync_points), |
| 288 gfx::Size(10, 10), // coded_size | 296 gfx::Size(10, 10), // coded_size |
| 289 gfx::Rect(10, 10), // visible_rect | 297 gfx::Rect(10, 10), // visible_rect |
| 290 gfx::Size(10, 10), // natural_size | 298 gfx::Size(10, 10), // natural_size |
| 291 base::TimeDelta(), // timestamp | 299 base::TimeDelta(), // timestamp |
| 292 base::Callback<void(const SkBitmap&)>()); // read_pixels_cb | 300 VideoFrame::ReadPixelsCB()); // read_pixels_cb |
| 301 EXPECT_TRUE(called_sync_points.empty()); |
| 293 | 302 |
| 294 gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); | 303 gpu::MailboxHolder* mailbox_holder = frame->mailbox_holder(); |
| 295 | 304 |
| 296 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); | 305 EXPECT_EQ(mailbox.name[0], mailbox_holder->mailbox.name[0]); |
| 297 EXPECT_EQ(target, mailbox_holder->texture_target); | 306 EXPECT_EQ(target, mailbox_holder->texture_target); |
| 298 EXPECT_EQ(sync_point, mailbox_holder->sync_point); | 307 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
| 299 | 308 |
| 300 // Finish using the mailbox_holder and drop our reference. | 309 frame->AppendReleaseSyncPoint(release_sync_points[0]); |
| 301 sync_point = 10; | 310 frame->AppendReleaseSyncPoint(release_sync_points[1]); |
| 302 mailbox_holder->sync_point = sync_point; | 311 frame->AppendReleaseSyncPoint(release_sync_points[2]); |
| 312 EXPECT_EQ(sync_point, mailbox_holder->sync_point); |
| 303 } | 313 } |
| 304 EXPECT_EQ(sync_point, called_sync_point); | 314 EXPECT_EQ(release_sync_points, called_sync_points); |
| 305 } | 315 } |
| 306 | 316 |
| 307 } // namespace media | 317 } // namespace media |
| OLD | NEW |