1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/resources/video_resource_updater.h"
7 #include "base/memory/shared_memory.h"
8 #include "cc/resources/resource_provider.h"
9 #include "cc/test/fake_output_surface.h"
10 #include "cc/test/fake_output_surface_client.h"
11 #include "cc/test/test_web_graphics_context_3d.h"
12 #include "media/base/video_frame.h"
13 #include "testing/gtest/include/gtest/gtest.h"
18 class VideoResourceUpdaterTest : public testing::Test {
20 VideoResourceUpdaterTest() {
21 scoped_ptr<TestWebGraphicsContext3D> context3d =
22 TestWebGraphicsContext3D::Create();
23 context3d_ = context3d.get();
26 FakeOutputSurface::Create3d(context3d.Pass());
27 CHECK(output_surface3d_->BindToClient(&client_));
28 resource_provider3d_ =
29 ResourceProvider::Create(output_surface3d_.get(), NULL, 0, false, 1);
32 scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() {
33 const int kDimension = 10;
34 gfx::Size size(kDimension, kDimension);
35 static uint8 y_data[kDimension * kDimension] = { 0 };
36 static uint8 u_data[kDimension * kDimension / 2] = { 0 };
37 static uint8 v_data[kDimension * kDimension / 2] = { 0 };
39 return media::VideoFrame::WrapExternalYuvData(
40 media::VideoFrame::YV16, // format
42 gfx::Rect(size), // visible_rect
44 size.width(), // y_stride
45 size.width() / 2, // u_stride
46 size.width() / 2, // v_stride
50 base::TimeDelta(), // timestamp,
51 base::Closure()); // no_longer_needed_cb
54 TestWebGraphicsContext3D* context3d_;
55 FakeOutputSurfaceClient client_;
56 scoped_ptr<FakeOutputSurface> output_surface3d_;
57 scoped_ptr<ResourceProvider> resource_provider3d_;
60 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
61 VideoResourceUpdater updater(output_surface3d_->context_provider().get(),
62 resource_provider3d_.get());
63 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
65 VideoFrameExternalResources resources =
66 updater.CreateExternalResourcesFromVideoFrame(video_frame);
67 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
70 TEST_F(VideoResourceUpdaterTest, LostContextForSoftwareFrame) {
71 VideoResourceUpdater updater(output_surface3d_->context_provider().get(),
72 resource_provider3d_.get());
73 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
75 // Fail while creating the mailbox for the second YUV plane.
76 context3d_->set_times_gen_mailbox_succeeds(1);
78 VideoFrameExternalResources resources =
79 updater.CreateExternalResourcesFromVideoFrame(video_frame);
80 EXPECT_EQ(VideoFrameExternalResources::NONE, resources.type);