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/fake_output_surface_client.h" 11#include "cc/test/test_shared_bitmap_manager.h" 12#include "cc/test/test_web_graphics_context_3d.h" 13#include "cc/trees/blocking_task_runner.h" 14#include "media/base/video_frame.h" 15#include "testing/gtest/include/gtest/gtest.h" 16 17namespace cc { 18namespace { 19 20class VideoResourceUpdaterTest : public testing::Test { 21 protected: 22 VideoResourceUpdaterTest() { 23 scoped_ptr<TestWebGraphicsContext3D> context3d = 24 TestWebGraphicsContext3D::Create(); 25 context3d_ = context3d.get(); 26 27 output_surface3d_ = 28 FakeOutputSurface::Create3d(context3d.Pass()); 29 CHECK(output_surface3d_->BindToClient(&client_)); 30 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); 31 resource_provider3d_ = 32 ResourceProvider::Create(output_surface3d_.get(), 33 shared_bitmap_manager_.get(), 34 NULL, 35 0, 36 false, 37 1, 38 false); 39 } 40 41 scoped_refptr<media::VideoFrame> CreateTestYUVVideoFrame() { 42 const int kDimension = 10; 43 gfx::Size size(kDimension, kDimension); 44 static uint8 y_data[kDimension * kDimension] = { 0 }; 45 static uint8 u_data[kDimension * kDimension / 2] = { 0 }; 46 static uint8 v_data[kDimension * kDimension / 2] = { 0 }; 47 48 return media::VideoFrame::WrapExternalYuvData( 49 media::VideoFrame::YV16, // format 50 size, // coded_size 51 gfx::Rect(size), // visible_rect 52 size, // natural_size 53 size.width(), // y_stride 54 size.width() / 2, // u_stride 55 size.width() / 2, // v_stride 56 y_data, // y_data 57 u_data, // u_data 58 v_data, // v_data 59 base::TimeDelta(), // timestamp, 60 base::Closure()); // no_longer_needed_cb 61 } 62 63 TestWebGraphicsContext3D* context3d_; 64 FakeOutputSurfaceClient client_; 65 scoped_ptr<FakeOutputSurface> output_surface3d_; 66 scoped_ptr<TestSharedBitmapManager> shared_bitmap_manager_; 67 scoped_ptr<ResourceProvider> resource_provider3d_; 68}; 69 70TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { 71 VideoResourceUpdater updater(output_surface3d_->context_provider(), 72 resource_provider3d_.get()); 73 scoped_refptr<media::VideoFrame> video_frame = CreateTestYUVVideoFrame(); 74 75 VideoFrameExternalResources resources = 76 updater.CreateExternalResourcesFromVideoFrame(video_frame); 77 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); 78} 79 80} // namespace 81} // namespace cc 82