OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "cc/resources/video_resource_updater.h" | 5 #include "cc/resources/video_resource_updater.h" |
6 | 6 |
7 #include "base/memory/shared_memory.h" | 7 #include "base/memory/shared_memory.h" |
8 #include "cc/resources/resource_provider.h" | 8 #include "cc/resources/resource_provider.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
11 #include "cc/test/test_shared_bitmap_manager.h" | 11 #include "cc/test/test_shared_bitmap_manager.h" |
12 #include "cc/test/test_web_graphics_context_3d.h" | 12 #include "cc/test/test_web_graphics_context_3d.h" |
13 #include "cc/trees/blocking_task_runner.h" | 13 #include "cc/trees/blocking_task_runner.h" |
| 14 #include "gpu/GLES2/gl2extchromium.h" |
14 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 namespace { | 19 namespace { |
19 | 20 |
20 class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D { | 21 class WebGraphicsContext3DUploadCounter : public TestWebGraphicsContext3D { |
21 public: | 22 public: |
22 void texSubImage2D(GLenum target, | 23 void texSubImage2D(GLenum target, |
23 GLint level, | 24 GLint level, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 size.width(), // y_stride | 100 size.width(), // y_stride |
100 size.width() / 2, // u_stride | 101 size.width() / 2, // u_stride |
101 size.width() / 2, // v_stride | 102 size.width() / 2, // v_stride |
102 y_data, // y_data | 103 y_data, // y_data |
103 u_data, // u_data | 104 u_data, // u_data |
104 v_data, // v_data | 105 v_data, // v_data |
105 base::TimeDelta(), // timestamp, | 106 base::TimeDelta(), // timestamp, |
106 base::Closure()); // no_longer_needed_cb | 107 base::Closure()); // no_longer_needed_cb |
107 } | 108 } |
108 | 109 |
| 110 static void ReleaseMailboxCB(unsigned sync_point) {} |
| 111 |
| 112 scoped_refptr<media::VideoFrame> CreateTestRGBAHardwareVideoFrame() { |
| 113 const int kDimension = 10; |
| 114 gfx::Size size(kDimension, kDimension); |
| 115 |
| 116 gpu::Mailbox mailbox; |
| 117 mailbox.name[0] = 51; |
| 118 |
| 119 const unsigned sync_point = 7; |
| 120 const unsigned target = GL_TEXTURE_2D; |
| 121 return media::VideoFrame::WrapNativeTexture( |
| 122 gpu::MailboxHolder(mailbox, target, sync_point), |
| 123 base::Bind(&ReleaseMailboxCB), |
| 124 size, // coded_size |
| 125 gfx::Rect(size), // visible_rect |
| 126 size, // natural_size |
| 127 base::TimeDelta(), // timestamp |
| 128 false); // allow_overlay |
| 129 } |
| 130 |
| 131 scoped_refptr<media::VideoFrame> CreateTestYUVHardareVideoFrame() { |
| 132 const int kDimension = 10; |
| 133 gfx::Size size(kDimension, kDimension); |
| 134 |
| 135 const int kPlanesNum = 3; |
| 136 gpu::Mailbox mailbox[kPlanesNum]; |
| 137 for (int i = 0; i < kPlanesNum; ++i) { |
| 138 mailbox[i].name[0] = 50 + 1; |
| 139 } |
| 140 const unsigned sync_point = 7; |
| 141 const unsigned target = GL_TEXTURE_RECTANGLE_ARB; |
| 142 return media::VideoFrame::WrapYUV420NativeTextures( |
| 143 gpu::MailboxHolder(mailbox[media::VideoFrame::kYPlane], target, |
| 144 sync_point), |
| 145 gpu::MailboxHolder(mailbox[media::VideoFrame::kUPlane], target, |
| 146 sync_point), |
| 147 gpu::MailboxHolder(mailbox[media::VideoFrame::kVPlane], target, |
| 148 sync_point), |
| 149 base::Bind(&ReleaseMailboxCB), |
| 150 size, // coded_size |
| 151 gfx::Rect(size), // visible_rect |
| 152 size, // natural_size |
| 153 base::TimeDelta(), // timestamp |
| 154 false); // allow_overlay |
| 155 } |
| 156 |
109 WebGraphicsContext3DUploadCounter* context3d_; | 157 WebGraphicsContext3DUploadCounter* context3d_; |
110 FakeOutputSurfaceClient client_; | 158 FakeOutputSurfaceClient client_; |
111 scoped_ptr<FakeOutputSurface> output_surface3d_; | 159 scoped_ptr<FakeOutputSurface> output_surface3d_; |
112 scoped_ptr<FakeOutputSurface> output_surface_software_; | 160 scoped_ptr<FakeOutputSurface> output_surface_software_; |
113 scoped_ptr<SharedBitmapManagerAllocationCounter> shared_bitmap_manager_; | 161 scoped_ptr<SharedBitmapManagerAllocationCounter> shared_bitmap_manager_; |
114 scoped_ptr<ResourceProvider> resource_provider3d_; | 162 scoped_ptr<ResourceProvider> resource_provider3d_; |
115 scoped_ptr<ResourceProvider> resource_provider_software_; | 163 scoped_ptr<ResourceProvider> resource_provider_software_; |
116 }; | 164 }; |
117 | 165 |
118 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { | 166 TEST_F(VideoResourceUpdaterTest, SoftwareFrame) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 shared_bitmap_manager_->ResetAllocationCount(); | 292 shared_bitmap_manager_->ResetAllocationCount(); |
245 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); | 293 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); |
246 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); | 294 EXPECT_EQ(VideoFrameExternalResources::SOFTWARE_RESOURCE, resources.type); |
247 EXPECT_EQ(size_t(0), resources.mailboxes.size()); | 295 EXPECT_EQ(size_t(0), resources.mailboxes.size()); |
248 EXPECT_EQ(size_t(0), resources.release_callbacks.size()); | 296 EXPECT_EQ(size_t(0), resources.release_callbacks.size()); |
249 EXPECT_EQ(size_t(1), resources.software_resources.size()); | 297 EXPECT_EQ(size_t(1), resources.software_resources.size()); |
250 // The data should be reused so expect no new allocations. | 298 // The data should be reused so expect no new allocations. |
251 EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount()); | 299 EXPECT_EQ(0, shared_bitmap_manager_->AllocationCount()); |
252 } | 300 } |
253 | 301 |
| 302 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes) { |
| 303 VideoResourceUpdater updater(output_surface3d_->context_provider(), |
| 304 resource_provider3d_.get()); |
| 305 |
| 306 scoped_refptr<media::VideoFrame> video_frame = |
| 307 CreateTestRGBAHardwareVideoFrame(); |
| 308 |
| 309 VideoFrameExternalResources resources = |
| 310 updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 311 EXPECT_EQ(VideoFrameExternalResources::RGB_RESOURCE, resources.type); |
| 312 EXPECT_EQ(1u, resources.mailboxes.size()); |
| 313 EXPECT_EQ(1u, resources.release_callbacks.size()); |
| 314 EXPECT_EQ(0u, resources.software_resources.size()); |
| 315 |
| 316 video_frame = CreateTestYUVHardareVideoFrame(); |
| 317 |
| 318 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame); |
| 319 EXPECT_EQ(VideoFrameExternalResources::YUV_RESOURCE, resources.type); |
| 320 EXPECT_EQ(3u, resources.mailboxes.size()); |
| 321 EXPECT_EQ(3u, resources.release_callbacks.size()); |
| 322 EXPECT_EQ(0u, resources.software_resources.size()); |
| 323 } |
254 } // namespace | 324 } // namespace |
255 } // namespace cc | 325 } // namespace cc |
OLD | NEW |