Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Side by Side Diff: cc/resources/video_resource_updater_unittest.cc

Issue 2684073006: cc: UYVY video is not premultiplied rgba
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 scoped_refptr<media::VideoFrame> video_frame(media::VideoFrame::CreateFrame( 165 scoped_refptr<media::VideoFrame> video_frame(media::VideoFrame::CreateFrame(
166 media::PIXEL_FORMAT_YUV420P10, size, gfx::Rect(size), size, 166 media::PIXEL_FORMAT_YUV420P10, size, gfx::Rect(size), size,
167 base::TimeDelta())); 167 base::TimeDelta()));
168 EXPECT_TRUE(video_frame); 168 EXPECT_TRUE(video_frame);
169 return video_frame; 169 return video_frame;
170 } 170 }
171 171
172 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {} 172 static void ReleaseMailboxCB(const gpu::SyncToken& sync_token) {}
173 173
174 scoped_refptr<media::VideoFrame> CreateTestHardwareVideoFrame( 174 scoped_refptr<media::VideoFrame> CreateTestHardwareVideoFrame(
175 unsigned target) { 175 unsigned target,
176 media::VideoPixelFormat format) {
176 const int kDimension = 10; 177 const int kDimension = 10;
177 gfx::Size size(kDimension, kDimension); 178 gfx::Size size(kDimension, kDimension);
178 179
179 gpu::Mailbox mailbox; 180 gpu::Mailbox mailbox;
180 mailbox.name[0] = 51; 181 mailbox.name[0] = 51;
181 182
182 const gpu::SyncToken sync_token( 183 const gpu::SyncToken sync_token(
183 gpu::CommandBufferNamespace::GPU_IO, 0, 184 gpu::CommandBufferNamespace::GPU_IO, 0,
184 gpu::CommandBufferId::FromUnsafeValue(0x123), 7); 185 gpu::CommandBufferId::FromUnsafeValue(0x123), 7);
185 gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes] = { 186 gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes] = {
186 gpu::MailboxHolder(mailbox, sync_token, target)}; 187 gpu::MailboxHolder(mailbox, sync_token, target)};
187 scoped_refptr<media::VideoFrame> video_frame = 188 scoped_refptr<media::VideoFrame> video_frame =
188 media::VideoFrame::WrapNativeTextures(media::PIXEL_FORMAT_ARGB, 189 media::VideoFrame::WrapNativeTextures(format, mailbox_holders,
189 mailbox_holders,
190 base::Bind(&ReleaseMailboxCB), 190 base::Bind(&ReleaseMailboxCB),
191 size, // coded_size 191 size, // coded_size
192 gfx::Rect(size), // visible_rect 192 gfx::Rect(size), // visible_rect
193 size, // natural_size 193 size, // natural_size
194 base::TimeDelta()); // timestamp 194 base::TimeDelta()); // timestamp
195 EXPECT_TRUE(video_frame); 195 EXPECT_TRUE(video_frame);
196 return video_frame; 196 return video_frame;
197 } 197 }
198 198
199 scoped_refptr<media::VideoFrame> CreateTestRGBAHardwareVideoFrame() { 199 scoped_refptr<media::VideoFrame> CreateTestRGBAHardwareVideoFrame() {
200 return CreateTestHardwareVideoFrame(GL_TEXTURE_2D); 200 return CreateTestHardwareVideoFrame(GL_TEXTURE_2D,
201 media::PIXEL_FORMAT_ARGB);
201 } 202 }
202 203
203 scoped_refptr<media::VideoFrame> CreateTestStreamTextureHardwareVideoFrame( 204 scoped_refptr<media::VideoFrame> CreateTestStreamTextureHardwareVideoFrame(
204 bool needs_copy) { 205 bool needs_copy) {
205 scoped_refptr<media::VideoFrame> video_frame = 206 scoped_refptr<media::VideoFrame> video_frame = CreateTestHardwareVideoFrame(
206 CreateTestHardwareVideoFrame(GL_TEXTURE_EXTERNAL_OES); 207 GL_TEXTURE_EXTERNAL_OES, media::PIXEL_FORMAT_ARGB);
207 video_frame->metadata()->SetBoolean( 208 video_frame->metadata()->SetBoolean(
208 media::VideoFrameMetadata::COPY_REQUIRED, needs_copy); 209 media::VideoFrameMetadata::COPY_REQUIRED, needs_copy);
209 return video_frame; 210 return video_frame;
210 } 211 }
211 212
213 scoped_refptr<media::VideoFrame> CreateTestUYVYTextureHardwareVideoFrame(
214 unsigned target) {
215 scoped_refptr<media::VideoFrame> video_frame =
216 CreateTestHardwareVideoFrame(target, media::PIXEL_FORMAT_UYVY);
217 video_frame->metadata()->SetBoolean(
218 media::VideoFrameMetadata::COPY_REQUIRED, false);
219 return video_frame;
220 }
221
212 scoped_refptr<media::VideoFrame> CreateTestYuvHardwareVideoFrame() { 222 scoped_refptr<media::VideoFrame> CreateTestYuvHardwareVideoFrame() {
213 const int kDimension = 10; 223 const int kDimension = 10;
214 gfx::Size size(kDimension, kDimension); 224 gfx::Size size(kDimension, kDimension);
215 225
216 const gpu::SyncToken sync_token( 226 const gpu::SyncToken sync_token(
217 gpu::CommandBufferNamespace::GPU_IO, 0, 227 gpu::CommandBufferNamespace::GPU_IO, 0,
218 gpu::CommandBufferId::FromUnsafeValue(0x123), 7); 228 gpu::CommandBufferId::FromUnsafeValue(0x123), 7);
219 const unsigned target = GL_TEXTURE_RECTANGLE_ARB; 229 const unsigned target = GL_TEXTURE_RECTANGLE_ARB;
220 const int kPlanesNum = 3; 230 const int kPlanesNum = 3;
221 gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes]; 231 gpu::MailboxHolder mailbox_holders[media::VideoFrame::kMaxPlanes];
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 EXPECT_EQ(1, context3d_->TextureCreationCount()); 517 EXPECT_EQ(1, context3d_->TextureCreationCount());
508 518
509 // The texture copy path requires the use of CopyTextureCHROMIUM, which 519 // The texture copy path requires the use of CopyTextureCHROMIUM, which
510 // enforces that the target texture not be immutable, as it may need 520 // enforces that the target texture not be immutable, as it may need
511 // to alter the storage of the texture. Therefore, this test asserts 521 // to alter the storage of the texture. Therefore, this test asserts
512 // that an immutable texture wasn't created by glTexStorage2DEXT, when 522 // that an immutable texture wasn't created by glTexStorage2DEXT, when
513 // that extension is supported. 523 // that extension is supported.
514 EXPECT_FALSE(context3d_->WasImmutableTextureCreated()); 524 EXPECT_FALSE(context3d_->WasImmutableTextureCreated());
515 } 525 }
516 526
527 TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_UYVYTexture) {
528 VideoResourceUpdater updater(context_provider_.get(),
529 resource_provider3d_.get());
530
531 scoped_refptr<media::VideoFrame> video_frame =
532 CreateTestUYVYTextureHardwareVideoFrame(GL_TEXTURE_2D);
533
534 VideoFrameExternalResources resources =
535 updater.CreateExternalResourcesFromVideoFrame(video_frame);
536 EXPECT_EQ(VideoFrameExternalResources::RGB_RESOURCE, resources.type);
537 EXPECT_EQ(1u, resources.mailboxes.size());
538 EXPECT_EQ(1u, resources.release_callbacks.size());
539 EXPECT_EQ(0u, resources.software_resources.size());
540
541 video_frame =
542 CreateTestUYVYTextureHardwareVideoFrame(GL_TEXTURE_EXTERNAL_OES);
543
544 resources = updater.CreateExternalResourcesFromVideoFrame(video_frame);
545 EXPECT_EQ(VideoFrameExternalResources::STREAM_TEXTURE_RESOURCE,
546 resources.type);
547 EXPECT_EQ(1u, resources.mailboxes.size());
548 EXPECT_EQ(1u, resources.release_callbacks.size());
549 EXPECT_EQ(0u, resources.software_resources.size());
550 }
551
517 namespace { 552 namespace {
518 553
519 // Convert an IEEE 754 half-float to a double value 554 // Convert an IEEE 754 half-float to a double value
520 // that we can do math on. 555 // that we can do math on.
521 double FromHalfFloat(uint16_t half_float) { 556 double FromHalfFloat(uint16_t half_float) {
522 if (!half_float) 557 if (!half_float)
523 return 0.0; 558 return 0.0;
524 int sign = (half_float & 0x8000) ? -1 : 1; 559 int sign = (half_float & 0x8000) ? -1 : 1;
525 int exponent = (half_float >> 10) & 0x1F; 560 int exponent = (half_float >> 10) & 0x1F;
526 int fraction = half_float & 0x3FF; 561 int fraction = half_float & 0x3FF;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]); 601 FromHalfFloat(half_floats[i] + 1) - FromHalfFloat(half_floats[i]);
567 EXPECT_NEAR(FromHalfFloat(half_floats[i]), expected_value, 602 EXPECT_NEAR(FromHalfFloat(half_floats[i]), expected_value,
568 expected_precision) 603 expected_precision)
569 << "i = " << i << " bits = " << bits; 604 << "i = " << i << " bits = " << bits;
570 } 605 }
571 } 606 }
572 } 607 }
573 608
574 } // namespace 609 } // namespace
575 } // namespace cc 610 } // namespace cc
OLDNEW
« cc/resources/video_resource_updater.cc ('K') | « cc/resources/video_resource_updater.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698