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

Side by Side Diff: media/base/video_frame_unittest.cc

Issue 1429213002: Converted video frame and image callbacks to use new sync tokens. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed content_unittests Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 static void TextureCallback(gpu::SyncToken* called_sync_token, 264 static void TextureCallback(gpu::SyncToken* called_sync_token,
265 const gpu::SyncToken& release_sync_token) { 265 const gpu::SyncToken& release_sync_token) {
266 *called_sync_token = release_sync_token; 266 *called_sync_token = release_sync_token;
267 } 267 }
268 268
269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 269 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
270 // destroyed with the default release sync point. 270 // destroyed with the default release sync point.
271 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) { 271 TEST(VideoFrame, TextureNoLongerNeededCallbackIsCalled) {
272 gpu::SyncToken called_sync_token(1); 272 gpu::SyncToken called_sync_token(gpu::CommandBufferNamespace::GPU_IO, 1, 1);
273 273
274 { 274 {
275 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture( 275 scoped_refptr<VideoFrame> frame = VideoFrame::WrapNativeTexture(
276 PIXEL_FORMAT_ARGB, 276 PIXEL_FORMAT_ARGB,
277 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5), 277 gpu::MailboxHolder(gpu::Mailbox::Generate(), gpu::SyncToken(), 5),
278 base::Bind(&TextureCallback, &called_sync_token), 278 base::Bind(&TextureCallback, &called_sync_token),
279 gfx::Size(10, 10), // coded_size 279 gfx::Size(10, 10), // coded_size
280 gfx::Rect(10, 10), // visible_rect 280 gfx::Rect(10, 10), // visible_rect
281 gfx::Size(10, 10), // natural_size 281 gfx::Size(10, 10), // natural_size
282 base::TimeDelta()); // timestamp 282 base::TimeDelta()); // timestamp
283 EXPECT_EQ(PIXEL_FORMAT_ARGB, frame->format()); 283 EXPECT_EQ(PIXEL_FORMAT_ARGB, frame->format());
284 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type()); 284 EXPECT_EQ(VideoFrame::STORAGE_OPAQUE, frame->storage_type());
285 EXPECT_TRUE(frame->HasTextures()); 285 EXPECT_TRUE(frame->HasTextures());
286 } 286 }
287 // Nobody set a sync point to |frame|, so |frame| set |called_sync_token| 287 // Nobody set a sync point to |frame|, so |frame| set |called_sync_token|
288 // cleared to default value. 288 // cleared to default value.
289 EXPECT_FALSE(called_sync_token.HasData()); 289 EXPECT_FALSE(called_sync_token.HasData());
290 } 290 }
291 291
292 namespace { 292 namespace {
293 293
294 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient { 294 class SyncTokenClientImpl : public VideoFrame::SyncTokenClient {
295 public: 295 public:
296 explicit SyncTokenClientImpl(const gpu::SyncToken& sync_token) 296 explicit SyncTokenClientImpl(const gpu::SyncToken& sync_token)
297 : sync_token_(sync_token) {} 297 : sync_token_(sync_token) {}
298 ~SyncTokenClientImpl() override {} 298 ~SyncTokenClientImpl() override {}
299 uint32 InsertSyncPoint() override { 299 void GenerateSyncToken(gpu::SyncToken* sync_token) override {
300 return static_cast<uint32>(sync_token_.release_count()); 300 *sync_token = sync_token_;
301 } 301 }
302 void WaitSyncToken(const gpu::SyncToken& sync_token) override {} 302 void WaitSyncToken(const gpu::SyncToken& sync_token) override {}
303 303
304 private: 304 private:
305 gpu::SyncToken sync_token_; 305 gpu::SyncToken sync_token_;
306 }; 306 };
307 307
308 } // namespace 308 } // namespace
309 309
310 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is 310 // Verify the gpu::MailboxHolder::ReleaseCallback is called when VideoFrame is
311 // destroyed with the release sync point, which was updated by clients. 311 // destroyed with the release sync point, which was updated by clients.
312 // (i.e. the compositor, webgl). 312 // (i.e. the compositor, webgl).
313 TEST(VideoFrame, 313 TEST(VideoFrame,
314 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) { 314 TexturesNoLongerNeededCallbackAfterTakingAndReleasingMailboxes) {
315 const int kPlanesNum = 3; 315 const int kPlanesNum = 3;
316 const gpu::CommandBufferNamespace kNamespace =
317 gpu::CommandBufferNamespace::GPU_IO;
318 const uint64_t kCommandBufferId = 0x123;
316 gpu::Mailbox mailbox[kPlanesNum]; 319 gpu::Mailbox mailbox[kPlanesNum];
317 for (int i = 0; i < kPlanesNum; ++i) { 320 for (int i = 0; i < kPlanesNum; ++i) {
318 mailbox[i].name[0] = 50 + 1; 321 mailbox[i].name[0] = 50 + 1;
319 } 322 }
320 323
321 gpu::SyncToken sync_token(7); 324 gpu::SyncToken sync_token(kNamespace, kCommandBufferId, 7);
325 sync_token.SetVerifyFlush();
322 uint32 target = 9; 326 uint32 target = 9;
323 gpu::SyncToken release_sync_token(111); 327 gpu::SyncToken release_sync_token(kNamespace, kCommandBufferId, 111);
328 release_sync_token.SetVerifyFlush();
329
324 gpu::SyncToken called_sync_token; 330 gpu::SyncToken called_sync_token;
325 { 331 {
326 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures( 332 scoped_refptr<VideoFrame> frame = VideoFrame::WrapYUV420NativeTextures(
327 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], sync_token, target), 333 gpu::MailboxHolder(mailbox[VideoFrame::kYPlane], sync_token, target),
328 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], sync_token, target), 334 gpu::MailboxHolder(mailbox[VideoFrame::kUPlane], sync_token, target),
329 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], sync_token, target), 335 gpu::MailboxHolder(mailbox[VideoFrame::kVPlane], sync_token, target),
330 base::Bind(&TextureCallback, &called_sync_token), 336 base::Bind(&TextureCallback, &called_sync_token),
331 gfx::Size(10, 10), // coded_size 337 gfx::Size(10, 10), // coded_size
332 gfx::Rect(10, 10), // visible_rect 338 gfx::Rect(10, 10), // visible_rect
333 gfx::Size(10, 10), // natural_size 339 gfx::Size(10, 10), // natural_size
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 482
477 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) { 483 for (int i = 0; i < VideoFrameMetadata::NUM_KEYS; ++i) {
478 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i); 484 const VideoFrameMetadata::Key key = static_cast<VideoFrameMetadata::Key>(i);
479 int value = -1; 485 int value = -1;
480 EXPECT_TRUE(result.GetInteger(key, &value)); 486 EXPECT_TRUE(result.GetInteger(key, &value));
481 EXPECT_EQ(i, value); 487 EXPECT_EQ(i, value);
482 } 488 }
483 } 489 }
484 490
485 } // namespace media 491 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698