Home | History | Annotate | Download | only in resources
      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.
      4 
      5 #include "cc/resources/video_resource_updater.h"
      6 
      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/test_web_graphics_context_3d.h"
     11 #include "media/base/video_frame.h"
     12 #include "testing/gtest/include/gtest/gtest.h"
     13 
     14 namespace cc {
     15 namespace {
     16 
     17 class VideoResourceUpdaterTest : public testing::Test {
     18  protected:
     19   VideoResourceUpdaterTest() {
     20     scoped_ptr<TestWebGraphicsContext3D> context3d =
     21         TestWebGraphicsContext3D::Create();
     22     context3d_ = context3d.get();
     23 
     24     output_surface3d_ = FakeOutputSurface::Create3d(
     25         context3d.PassAs<WebKit::WebGraphicsContext3D>());
     26     resource_provider3d_ =
     27         ResourceProvider::Create(output_surface3d_.get(), 0);
     28   }
     29 
     30   scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() {
     31     const int kDimension = 10;
     32     gfx::Size size(kDimension, kDimension);
     33     static uint8 y_data[kDimension * kDimension] = { 0 };
     34     static uint8 u_data[kDimension * kDimension / 2] = { 0 };
     35     static uint8 v_data[kDimension * kDimension / 2] = { 0 };
     36 
     37     return media::VideoFrame::WrapExternalYuvData(
     38         media::VideoFrame::YV16,  // format
     39         size,                     // coded_size
     40         gfx::Rect(size),          // visible_rect
     41         size,                     // natural_size
     42         size.width(),             // y_stride
     43         size.width() / 2,         // u_stride
     44         size.width() / 2,         // v_stride
     45         y_data,                   // y_data
     46         u_data,                   // u_data
     47         v_data,                   // v_data
     48         base::TimeDelta(),        // timestamp,
     49         base::Closure());         // no_longer_needed_cb
     50   }
     51 
     52   TestWebGraphicsContext3D* context3d_;
     53   scoped_ptr<FakeOutputSurface> output_surface3d_;
     54   scoped_ptr<ResourceProvider> resource_provider3d_;
     55 };
     56 
     57 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
     58   VideoResourceUpdater updater(resource_provider3d_.get());
     59   scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
     60 
     61   VideoFrameExternalResources resources =
     62       updater.CreateExternalResourcesFromVideoFrame(video_frame);
     63   EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type);
     64 }
     65 
     66 TEST_F(VideoResourceUpdaterTest, LostContextForSoftwareFrame) {
     67   VideoResourceUpdater updater(resource_provider3d_.get());
     68   scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame();
     69 
     70   // Fail while creating the mailbox for the second YUV plane.
     71   context3d_->set_times_gen_mailbox_succeeds(1);
     72 
     73   VideoFrameExternalResources resources =
     74       updater.CreateExternalResourcesFromVideoFrame(video_frame);
     75   EXPECT_EQ(VideoFrameExternalResources::NONE, resources.type);
     76 }
     77 
     78 }  // namespace
     79 }  // namespace cc
     80