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