summaryrefslogtreecommitdiffstats
path: root/cc/resources/video_resource_updater_unittest.cc
blob: 95b3124369af72ac7d85750564501bed77f87c51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cc/resources/video_resource_updater.h"

#include "base/memory/shared_memory.h"
#include "cc/resources/resource_provider.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace cc {
namespace {

class VideoResourceUpdaterTest : public testing::Test {
 protected:
  VideoResourceUpdaterTest() {
    scoped_ptr<TestWebGraphicsContext3D> context3d =
        TestWebGraphicsContext3D::Create();
    context3d_ = context3d.get();

    output_surface3d_ = FakeOutputSurface::Create3d(
        context3d.PassAs<WebKit::WebGraphicsContext3D>());
    resource_provider3d_ =
        ResourceProvider::Create(output_surface3d_.get(), 0);
  }

  scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() {
    const int kDimension = 10;
    gfx::Size size(kDimension, kDimension);
    static uint8 y_data[kDimension * kDimension] = { 0 };
    static uint8 u_data[kDimension * kDimension / 2] = { 0 };
    static uint8 v_data[kDimension * kDimension / 2] = { 0 };

    return media::VideoFrame::WrapExternalYuvData(
        media::VideoFrame::YV16,  // format
        size,  // coded_size
        gfx::Rect(size),  // visible_rect
        size,  // natural_size
        size.width(),  // y_stride
        size.width() / 2,  // u_stride
        size.width() / 2,  // v_stride
        y_data,  // y_data
        u_data,  // u_data
        v_data,  // v_data
        base::TimeDelta(),  // timestamp,
        base::SharedMemory::NULLHandle(),  // shm_handle
        base::Closure());  // no_longer_needed_cb
  }

  TestWebGraphicsContext3D* context3d_;
  scoped_ptr<FakeOutputSurface> output_surface3d_;
  scoped_ptr<ResourceProvider> resource_provider3d_;
};

TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
  VideoResourceUpdater updater(resource_provider3d_.get());
  scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();

  VideoFrameExternalResources resources =
      updater.CreateExternalResourcesFromVideoFrame(video_frame);
  EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
}

TEST_F(VideoResourceUpdaterTest, LostContextForSoftwareFrame) {
  VideoResourceUpdater updater(resource_provider3d_.get());
  scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();

  // Fail while creating the mailbox for the second YUV plane.
  context3d_->set_times_gen_mailbox_succeeds(1);

  VideoFrameExternalResources resources =
      updater.CreateExternalResourcesFromVideoFrame(video_frame);
  EXPECT_EQ(VideoFrameExternalResources::NONE, resources.type);
}

}  // namespace
}  // namespace cc