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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
media / renderers / video_resource_updater_unittest.cc [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "media/renderers/video_resource_updater.h"
#include <stddef.h>
#include <stdint.h>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/read_only_shared_memory_region.h"
#include "base/test/task_environment.h"
#include "components/viz/client/client_resource_provider.h"
#include "components/viz/common/quads/compositor_render_pass.h"
#include "components/viz/common/quads/texture_draw_quad.h"
#include "components/viz/common/resources/shared_image_format.h"
#include "components/viz/test/fake_output_surface.h"
#include "components/viz/test/test_gles2_interface.h"
#include "components/viz/test/test_shared_image_interface_provider.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/ipc/client/client_shared_image_interface.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
#include "skia/ext/skcolorspace_primaries.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace {
class UploadCounterGLES2Interface : public viz::TestGLES2Interface {
public:
void TexSubImage2D(GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const void* pixels) override {
++upload_count_;
last_upload_ = reinterpret_cast<const uint8_t*>(pixels);
}
int UploadCount() { return upload_count_; }
void ResetUploadCount() { upload_count_ = 0; }
const uint8_t* last_upload() const { return last_upload_; }
private:
int upload_count_;
raw_ptr<const uint8_t, DanglingUntriaged> last_upload_ = nullptr;
};
class VideoResourceUpdaterTest : public testing::Test {
protected:
VideoResourceUpdaterTest() {
// TODO(hitawala): Use RasterInterface here instead.
auto gl = std::make_unique<UploadCounterGLES2Interface>();
gl_ = gl.get();
context_provider_ = viz::TestContextProvider::Create(std::move(gl));
context_provider_->BindToCurrentSequence();
}
// testing::Test implementation.
void SetUp() override {
testing::Test::SetUp();
resource_provider_ = std::make_unique<viz::ClientResourceProvider>();
}
std::unique_ptr<VideoResourceUpdater> CreateUpdaterForHardware(
bool use_stream_video_draw_quad = false) {
return std::make_unique<VideoResourceUpdater>(
context_provider_.get(), resource_provider_.get(),
/*shared_image_interface=*/nullptr, use_stream_video_draw_quad,
/*use_gpu_memory_buffer_resources=*/false,
/*max_resource_size=*/10000);
}
std::unique_ptr<VideoResourceUpdater> CreateUpdaterForSoftware() {
return std::make_unique<VideoResourceUpdater>(
/*context_provider=*/nullptr, resource_provider_.get(),
shared_image_interface_provider_.GetSharedImageInterface(),
/*use_stream_video_draw_quad=*/false,
/*use_gpu_memory_buffer_resources=*/false, /*max_resource_size=*/10000);
}
// Note that the number of pixels needed for |size| must be less than or equal
// to the number of pixels needed for size of 100x100.
scoped_refptr<VideoFrame> CreateTestYUVVideoFrame(
const gfx::Size& size = gfx::Size(10, 10)) {
constexpr int kMaxDimension = 100;
static uint8_t y_data[kMaxDimension * kMaxDimension] = {};
static uint8_t u_data[kMaxDimension * kMaxDimension / 2] = {};
static uint8_t v_data[kMaxDimension * kMaxDimension / 2] = {};
CHECK_LE(size.width() * size.height(), kMaxDimension * kMaxDimension);
scoped_refptr<VideoFrame> video_frame =
VideoFrame::WrapExternalYuvData(PIXEL_FORMAT_I422, // 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
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateWonkyTestYUVVideoFrame() {
const int kDimension = 10;
const int kYWidth = kDimension + 5;
const int kUWidth = (kYWidth + 1) / 2 + 200;
const int kVWidth = (kYWidth + 1) / 2 + 1;
static uint8_t y_data[kYWidth * kDimension] = {};
static uint8_t u_data[kUWidth * kDimension] = {};
static uint8_t v_data[kVWidth * kDimension] = {};
scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalYuvData(
PIXEL_FORMAT_I422, // format
gfx::Size(kYWidth, kDimension), // coded_size
gfx::Rect(2, 0, kDimension, kDimension), // visible_rect
gfx::Size(kDimension, kDimension), // natural_size
-kYWidth, // y_stride (negative)
kUWidth, // u_stride
kVWidth, // v_stride
y_data + kYWidth * (kDimension - 1), // y_data
u_data, // u_data
v_data, // v_data
base::TimeDelta()); // timestamp
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateTestRGBVideoFrame(VideoPixelFormat format) {
constexpr int kMaxDimension = 10;
constexpr gfx::Size kSize = gfx::Size(kMaxDimension, kMaxDimension);
static uint32_t rgb_data[kMaxDimension * kMaxDimension] = {};
scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalData(
format, // format
kSize, // coded_size
gfx::Rect(kSize), // visible_rect
kSize, // natural_size
reinterpret_cast<uint8_t*>(rgb_data), // data,
sizeof(rgb_data), // data_size
base::TimeDelta()); // timestamp
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateTestRGBVideoFrameWithVisibleRect(
VideoPixelFormat format) {
constexpr int kMaxDimension = 5;
constexpr gfx::Size kSize = gfx::Size(kMaxDimension, kMaxDimension);
constexpr gfx::Rect kVisibleRect = gfx::Rect(2, 1, 3, 3);
constexpr uint32_t kPix = 0xFFFFFFFF;
static uint32_t rgb_data[kMaxDimension * kMaxDimension] = {
0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, 0x00, 0x00, 0x00, //
};
scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalData(
format, // format
kSize, // coded_size
kVisibleRect, // visible_rect
kVisibleRect.size(), // natural_size
reinterpret_cast<uint8_t*>(rgb_data), // data,
sizeof(rgb_data), // data_size
base::TimeDelta()); // timestamp
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateTestY16VideoFrameWithVisibleRect() {
constexpr int kMaxDimension = 5;
constexpr gfx::Size kSize = gfx::Size(kMaxDimension, kMaxDimension);
constexpr gfx::Rect kVisibleRect = gfx::Rect(2, 1, 3, 3);
constexpr uint16_t kPix = 0xFFFF;
static uint16_t y16_data[kMaxDimension * kMaxDimension] = {
0x00, 0x00, 0x00, 0x00, 0x00, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, kPix, kPix, kPix, //
0x00, 0x00, 0x00, 0x00, 0x00, //
};
scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapExternalData(
PIXEL_FORMAT_Y16,
kSize, // coded_size
kVisibleRect, // visible_rect
kVisibleRect.size(), // natural_size
reinterpret_cast<uint8_t*>(y16_data), // data,
sizeof(y16_data), // data_size
base::TimeDelta()); // timestamp
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateTestHighBitFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
scoped_refptr<VideoFrame> video_frame(
VideoFrame::CreateFrame(PIXEL_FORMAT_YUV420P10, size, gfx::Rect(size),
size, base::TimeDelta()));
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateNV12TestFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
scoped_refptr<VideoFrame> video_frame(VideoFrame::CreateFrame(
PIXEL_FORMAT_NV12, size, gfx::Rect(size), size, base::TimeDelta()));
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateP010TestFrame() {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
scoped_refptr<VideoFrame> video_frame(VideoFrame::CreateFrame(
PIXEL_FORMAT_P010LE, size, gfx::Rect(size), size, base::TimeDelta()));
EXPECT_TRUE(video_frame);
return video_frame;
}
void SetReleaseSyncToken(const gpu::SyncToken& sync_token) {
release_sync_token_ = sync_token;
}
scoped_refptr<VideoFrame> CreateTestHardwareVideoFrame(
viz::SharedImageFormat si_format,
VideoPixelFormat format,
unsigned target) {
const int kDimension = 10;
gfx::Size size(kDimension, kDimension);
scoped_refptr<gpu::ClientSharedImage> shared_image =
gpu::ClientSharedImage::CreateForTesting(si_format, target);
scoped_refptr<VideoFrame> video_frame = VideoFrame::WrapSharedImage(
format, shared_image, kMailboxSyncToken,
base::BindOnce(&VideoResourceUpdaterTest::SetReleaseSyncToken,
base::Unretained(this)),
size, // coded_size
gfx::Rect(size), // visible_rect
size, // natural_size
base::TimeDelta()); // timestamp
EXPECT_TRUE(video_frame);
return video_frame;
}
scoped_refptr<VideoFrame> CreateTestRGBAHardwareVideoFrame() {
return CreateTestHardwareVideoFrame(viz::SinglePlaneFormat::kRGBA_8888,
PIXEL_FORMAT_ARGB, GL_TEXTURE_2D);
}
scoped_refptr<VideoFrame> CreateTestStreamTextureHardwareVideoFrame(
bool needs_copy) {
scoped_refptr<VideoFrame> video_frame = CreateTestHardwareVideoFrame(
viz::SinglePlaneFormat::kRGBA_8888, PIXEL_FORMAT_ARGB,
GL_TEXTURE_EXTERNAL_OES);
video_frame->metadata().copy_required = needs_copy;
return video_frame;
}
#if BUILDFLAG(IS_WIN)
scoped_refptr<VideoFrame> CreateTestDCompSurfaceVideoFrame() {
scoped_refptr<VideoFrame> video_frame = CreateTestHardwareVideoFrame(
viz::SinglePlaneFormat::kRGBA_8888, PIXEL_FORMAT_ARGB,
GL_TEXTURE_EXTERNAL_OES);
video_frame->metadata().dcomp_surface = true;
return video_frame;
}
#endif
size_t GetSharedImageCount() {
return context_provider_->SharedImageInterface()->shared_image_count();
}
static const gpu::SyncToken kMailboxSyncToken;
// VideoResourceUpdater registers as a MemoryDumpProvider, which requires
// a TaskRunner.
base::test::SingleThreadTaskEnvironment task_environment_;
raw_ptr<UploadCounterGLES2Interface, DanglingUntriaged> gl_;
scoped_refptr<viz::TestContextProvider> context_provider_;
std::unique_ptr<viz::ClientResourceProvider> resource_provider_;
viz::TestSharedImageInterfaceProvider shared_image_interface_provider_;
gpu::SyncToken release_sync_token_;
};
const gpu::SyncToken VideoResourceUpdaterTest::kMailboxSyncToken =
gpu::SyncToken(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(0x123),
7);
TEST_F(VideoResourceUpdaterTest, SoftwareFrame) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
// Create the resource again, to test the path where the
// resource are cached.
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
}
TEST_F(VideoResourceUpdaterTest, SoftwareFrameNV12) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(CreateNV12TestFrame());
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
// Use a different frame for this test since frames with the same unique_id()
// expect to use the same resource.
scoped_refptr<VideoFrame> video_frame = CreateNV12TestFrame();
gl_->set_supports_texture_rg(true);
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
}
// Ensure we end up with the right SharedImageFormat for each resource.
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGB) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
for (const auto& fmt : {PIXEL_FORMAT_XBGR, PIXEL_FORMAT_XRGB,
PIXEL_FORMAT_ABGR, PIXEL_FORMAT_ARGB}) {
scoped_refptr<VideoFrame> video_frame = CreateTestRGBVideoFrame(fmt);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
#if BUILDFLAG(IS_MAC)
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kBGRA_8888);
#else
EXPECT_EQ(resource.resource.size, video_frame->coded_size());
if (fmt == PIXEL_FORMAT_XBGR) {
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kRGBA_8888);
} else if (fmt == PIXEL_FORMAT_XRGB) {
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kBGRA_8888);
} else if (fmt == PIXEL_FORMAT_ABGR) {
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kRGBA_8888);
} else if (fmt == PIXEL_FORMAT_ARGB) {
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kBGRA_8888);
}
#endif
}
}
// Ensure the visible data is where it's supposed to be.
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGBNonOrigin) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
for (const auto& fmt : {PIXEL_FORMAT_XBGR, PIXEL_FORMAT_XRGB,
PIXEL_FORMAT_ABGR, PIXEL_FORMAT_ARGB}) {
auto video_frame = CreateTestRGBVideoFrameWithVisibleRect(fmt);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ(resource.resource.size, video_frame->coded_size());
auto rect = video_frame->visible_rect();
const auto bytes_per_row = video_frame->row_bytes(VideoFrame::Plane::kARGB);
const auto bytes_per_element =
VideoFrame::BytesPerElement(fmt, VideoFrame::Plane::kARGB);
auto* dest_pixels = gl_->last_upload() + rect.y() * bytes_per_row +
rect.x() * bytes_per_element;
auto* src_pixels = video_frame->visible_data(VideoFrame::Plane::kARGB);
// Pixels are 0xFFFFFFFF, so channel reordering doesn't matter.
for (int y = 0; y < rect.height(); ++y) {
for (int x = 0; x < rect.width() * bytes_per_element; ++x) {
const auto pos = y * bytes_per_row + x;
ASSERT_EQ(src_pixels[pos], dest_pixels[pos]);
}
}
}
}
// Ensure the visible data is where it's supposed to be.
TEST_F(VideoResourceUpdaterTest, SoftwareFrameY16NonOrigin) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
auto video_frame = CreateTestY16VideoFrameWithVisibleRect();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ(resource.resource.size, video_frame->coded_size());
auto rect = video_frame->visible_rect();
// Just used for sizing information, channel order doesn't matter.
constexpr auto kOutputFormat = PIXEL_FORMAT_ARGB;
const auto bytes_per_row =
VideoFrame::RowBytes(VideoFrame::Plane::kARGB, kOutputFormat,
video_frame->coded_size().width());
const auto bytes_per_element =
VideoFrame::BytesPerElement(kOutputFormat, VideoFrame::Plane::kARGB);
auto* dest_pixels = gl_->last_upload() + rect.y() * bytes_per_row +
rect.x() * bytes_per_element;
// Pixels are 0xFFFFFFFF, so channel reordering doesn't matter.
for (int y = 0; y < rect.height(); ++y) {
for (int x = 0; x < rect.width() * bytes_per_element; ++x) {
const auto pos = y * bytes_per_row + x;
ASSERT_EQ(0xFF, dest_pixels[pos]);
}
}
}
TEST_F(VideoResourceUpdaterTest, HighBitFrameNoF16) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
// Create the resource again, to test the path where the
// resource are cached.
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
}
class VideoResourceUpdaterTestWithF16 : public VideoResourceUpdaterTest {
public:
VideoResourceUpdaterTestWithF16() : VideoResourceUpdaterTest() {
gl_->set_support_texture_half_float_linear(true);
}
};
TEST_F(VideoResourceUpdaterTestWithF16, HighBitFrame) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
// Create the resource again, to test the path where the
// resource are cached.
VideoFrameExternalResource resource2 =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
}
class VideoResourceUpdaterTestWithR16 : public VideoResourceUpdaterTest {
public:
VideoResourceUpdaterTestWithR16() : VideoResourceUpdaterTest() {
auto* sii = context_provider_->SharedImageInterface();
auto shared_image_caps = sii->GetCapabilities();
shared_image_caps.supports_r16_shared_images = true;
sii->SetCapabilities(shared_image_caps);
gl_->set_support_texture_norm16(true);
}
};
TEST_F(VideoResourceUpdaterTestWithR16, HighBitFrame) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ(resource.bits_per_channel, 10u);
// Create the resource again, to test the path where the
// resource are cached.
VideoFrameExternalResource resource2 =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ(resource2.bits_per_channel, 10u);
}
TEST_F(VideoResourceUpdaterTest, NV12FrameSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateNV12TestFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
}
TEST_F(VideoResourceUpdaterTest, P010FrameSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateP010TestFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
}
TEST_F(VideoResourceUpdaterTest, HighBitFrameSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateTestHighBitFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
}
TEST_F(VideoResourceUpdaterTest, ReuseResource) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
video_frame->set_timestamp(base::Seconds(1234));
// Allocate the resource for a YUV video frame.
gl_->ResetUploadCount();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
// EXPECT_TRUE(resource.resource);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ(0, gl_->UploadCount());
// Simulate the ResourceProvider releasing the resource back to the video
// updater.
std::move(resource.release_callback).Run(gpu::SyncToken(), false);
// Allocate resource for the same frame.
gl_->ResetUploadCount();
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
// The data should be reused so expect no texture uploads.
EXPECT_EQ(0, gl_->UploadCount());
}
TEST_F(VideoResourceUpdaterTest, ReuseResourceNV12) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateNV12TestFrame();
video_frame->set_timestamp(base::Seconds(1234));
gl_->set_supports_texture_rg(true);
// Allocate the resource for a YUV video frame.
gl_->ResetUploadCount();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ(0, gl_->UploadCount());
// Simulate the ResourceProvider releasing the resource back to the video
// updater.
std::move(resource.release_callback).Run(gpu::SyncToken(), false);
// Allocate resource for the same frame.
gl_->ResetUploadCount();
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
// The data should be reused so expect no texture uploads.
EXPECT_EQ(0, gl_->UploadCount());
}
TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDelete) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
video_frame->set_timestamp(base::Seconds(1234));
// Allocate the resource for a YUV video frame.
gl_->ResetUploadCount();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ(0, gl_->UploadCount());
// Allocate resource for the same frame.
gl_->ResetUploadCount();
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
// With multiplanar shared images, a TextureDrawQuad is created instead of
// a YUVDrawQuad, we have a single resource and callback and use raster
// interface for uploads.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
// The data should be reused so expect no texture uploads.
EXPECT_EQ(0, gl_->UploadCount());
}
TEST_F(VideoResourceUpdaterTest, SoftwareFrameSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
}
TEST_F(VideoResourceUpdaterTest, SoftwareFrameRGBSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
for (const auto& fmt : {PIXEL_FORMAT_XBGR, PIXEL_FORMAT_XRGB,
PIXEL_FORMAT_ABGR, PIXEL_FORMAT_ARGB}) {
scoped_refptr<VideoFrame> video_frame = CreateTestRGBVideoFrame(fmt);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_EQ(resource.resource.format, viz::SinglePlaneFormat::kBGRA_8888);
}
}
TEST_F(VideoResourceUpdaterTest, ReuseResourceoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
video_frame->set_timestamp(base::Seconds(1234));
// Allocate the resource for a software video frame.
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_TRUE(resource.release_callback);
// Simulate the ResourceProvider releasing the resource back to the video
// updater.
std::move(resource.release_callback).Run(gpu::SyncToken(), false);
// Allocate resource for the same frame.
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_TRUE(resource.release_callback);
}
TEST_F(VideoResourceUpdaterTest, ReuseResourceNoDeleteSoftwareCompositor) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
scoped_refptr<VideoFrame> video_frame = CreateTestYUVVideoFrame();
video_frame->set_timestamp(base::Seconds(1234));
// Allocate the resource for a software video frame.
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_TRUE(resource.release_callback);
// Allocate resource for the same frame.
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_TRUE(resource.release_callback);
}
TEST_F(VideoResourceUpdaterTest, ChangeResourceizeSoftwareCompositor) {
constexpr gfx::Size kSize1(10, 10);
constexpr gfx::Size kSize2(20, 20);
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForSoftware();
// Allocate the resource for a software video frame.
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(
CreateTestYUVVideoFrame(kSize1));
// Simulate the ResourceProvider releasing the resource back to the video
// updater.
std::move(resource.release_callback).Run(gpu::SyncToken(), false);
// Allocate resource for the next frame with a different size.
resource = updater->CreateExternalResourceFromVideoFrame(
CreateTestYUVVideoFrame(kSize2));
}
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SharedImageFormat) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame =
CreateTestHardwareVideoFrame(viz::MultiPlaneFormat::kI420,
PIXEL_FORMAT_I420, GL_TEXTURE_RECTANGLE_ARB);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ(viz::MultiPlaneFormat::kI420, resource.resource.format);
EXPECT_EQ(resource.resource.synchronization_type,
viz::TransferableResource::SynchronizationType::kSyncToken);
video_frame =
CreateTestHardwareVideoFrame(viz::MultiPlaneFormat::kI420,
PIXEL_FORMAT_I420, GL_TEXTURE_RECTANGLE_ARB);
video_frame->metadata().read_lock_fences_enabled = true;
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(
resource.resource.synchronization_type,
viz::TransferableResource::SynchronizationType::kGpuCommandsCompleted);
}
TEST_F(VideoResourceUpdaterTest,
CreateForHardwarePlanes_StreamTexture_CopyToNewTexture) {
// Note that |use_stream_video_draw_quad| is true for this test.
std::unique_ptr<VideoResourceUpdater> updater =
CreateUpdaterForHardware(true);
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame =
CreateTestStreamTextureHardwareVideoFrame(/*needs_copy=*/false);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::STREAM_TEXTURE, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resource.resource.texture_target());
EXPECT_EQ(0u, GetSharedImageCount());
// A copied stream texture should return an RGBA resource in a new
// GL_TEXTURE_2D texture.
video_frame = CreateTestStreamTextureHardwareVideoFrame(/*needs_copy=*/true);
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGBA_PREMULTIPLIED, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ((GLenum)GL_TEXTURE_2D, resource.resource.texture_target());
EXPECT_EQ(1u, GetSharedImageCount());
}
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_TextureQuad) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame =
CreateTestStreamTextureHardwareVideoFrame(/*needs_copy=*/false);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resource.resource.texture_target());
EXPECT_EQ(0u, GetSharedImageCount());
}
#if BUILDFLAG(IS_WIN)
// Check that a video frame marked as containing a DComp surface turns into a
// texture draw quad that is required for overlay.
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_DCompSurface) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame = CreateTestDCompSurfaceVideoFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::STREAM_TEXTURE, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resource.resource.texture_target());
EXPECT_EQ(0u, GetSharedImageCount());
updater->ObtainFrameResource(video_frame);
std::unique_ptr<viz::CompositorRenderPass> pass =
viz::CompositorRenderPass::Create();
pass->SetNew(/*pass_id=*/viz::CompositorRenderPassId{1},
/*output_rect=*/gfx::Rect(video_frame->coded_size()),
/*damage_rect=*/gfx::Rect(),
/*transform_to_root_target=*/gfx::Transform());
updater->AppendQuad(
/*render_pass=*/pass.get(), video_frame,
/*transform=*/gfx::Transform(),
/*quad_rect=*/gfx::Rect(video_frame->coded_size()),
/*visible_quad_rect=*/gfx::Rect(video_frame->coded_size()),
gfx::MaskFilterInfo(), /*clip_rect=*/std::nullopt,
/*context_opaque=*/true, /*draw_opacity=*/1.0,
/*sorting_context_id=*/0);
EXPECT_EQ(1u, pass->quad_list.size());
const viz::TextureDrawQuad* quad =
pass->quad_list.ElementAt(0)->DynamicCast<viz::TextureDrawQuad>();
EXPECT_NE(nullptr, quad);
EXPECT_EQ(true, quad->is_stream_video);
EXPECT_EQ(viz::OverlayPriority::kRequired, quad->overlay_priority_hint);
updater->ReleaseFrameResource();
}
#endif
// Passthrough the sync token returned by the compositor if we don't have an
// existing release sync token.
TEST_F(VideoResourceUpdaterTest, PassReleaseSyncToken) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
const gpu::SyncToken sync_token(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(0x123),
123);
{
scoped_refptr<VideoFrame> video_frame = CreateTestRGBAHardwareVideoFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource.release_callback);
std::move(resource.release_callback).Run(sync_token, false);
}
EXPECT_EQ(release_sync_token_, sync_token);
}
// Generate new sync token because video frame has an existing sync token.
TEST_F(VideoResourceUpdaterTest, GenerateReleaseSyncToken) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
const gpu::SyncToken sync_token1(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(0x123),
123);
const gpu::SyncToken sync_token2(gpu::CommandBufferNamespace::GPU_IO,
gpu::CommandBufferId::FromUnsafeValue(0x234),
234);
{
scoped_refptr<VideoFrame> video_frame = CreateTestRGBAHardwareVideoFrame();
VideoFrameExternalResource resource1 =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource1.release_callback);
std::move(resource1.release_callback).Run(sync_token1, false);
VideoFrameExternalResource resource2 =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource2.release_callback);
std::move(resource2.release_callback).Run(sync_token2, false);
}
EXPECT_TRUE(release_sync_token_.HasData());
EXPECT_NE(release_sync_token_, sync_token1);
EXPECT_EQ(release_sync_token_, sync_token2);
}
// Pass mailbox sync token as is if no GL operations are performed before frame
// resource are handed off to the compositor.
TEST_F(VideoResourceUpdaterTest, PassMailboxSyncToken) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame = CreateTestRGBAHardwareVideoFrame();
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource.resource.sync_token().HasData());
EXPECT_EQ(resource.resource.sync_token(), kMailboxSyncToken);
}
// Generate new sync token for compositor when copying the texture.
TEST_F(VideoResourceUpdaterTest, GenerateSyncTokenOnTextureCopy) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
scoped_refptr<VideoFrame> video_frame =
CreateTestStreamTextureHardwareVideoFrame(/*needs_copy=*/true);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_TRUE(resource.resource.sync_token().HasData());
EXPECT_NE(resource.resource.sync_token(), kMailboxSyncToken);
}
// NV12 VideoFrames backed by a single native texture can be sampled out
// by GL as RGB. To use them as HW overlays we need to know the format
// of the underlying buffer, that is YUV_420_BIPLANAR.
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleNV12) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame = CreateTestHardwareVideoFrame(
viz::MultiPlaneFormat::kNV12, PIXEL_FORMAT_NV12, GL_TEXTURE_EXTERNAL_OES);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resource.resource.texture_target());
EXPECT_EQ(viz::MultiPlaneFormat::kNV12, resource.resource.format);
EXPECT_EQ(0u, GetSharedImageCount());
}
TEST_F(VideoResourceUpdaterTest,
CreateForHardwarePlanes_DualNV12_SharedImageFormat) {
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame =
CreateTestHardwareVideoFrame(viz::MultiPlaneFormat::kNV12,
PIXEL_FORMAT_NV12, GL_TEXTURE_RECTANGLE_ARB);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
// Setting to kSharedImageFormat, resource type should bo RGB.
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ((GLenum)GL_TEXTURE_RECTANGLE_ARB,
resource.resource.texture_target());
EXPECT_EQ(viz::MultiPlaneFormat::kNV12, resource.resource.format);
EXPECT_EQ(0u, GetSharedImageCount());
video_frame = CreateTestHardwareVideoFrame(
viz::MultiPlaneFormat::kNV12, PIXEL_FORMAT_NV12, GL_TEXTURE_EXTERNAL_OES);
resource = updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_TRUE(resource.release_callback);
EXPECT_EQ((GLenum)GL_TEXTURE_EXTERNAL_OES,
resource.resource.texture_target());
// |updater| doesn't set |buffer_format| in this case.
EXPECT_EQ(viz::MultiPlaneFormat::kNV12, resource.resource.format);
EXPECT_EQ(0u, GetSharedImageCount());
}
TEST_F(VideoResourceUpdaterTest, CreateForHardwarePlanes_SingleP010HDR) {
constexpr auto kHDR10ColorSpace = gfx::ColorSpace::CreateHDR10();
gfx::HDRMetadata hdr_metadata{};
hdr_metadata.smpte_st_2086 =
gfx::HdrMetadataSmpteSt2086(SkNamedPrimariesExt::kP3,
/*luminance_max=*/1000,
/*luminance_min=*/0);
std::unique_ptr<VideoResourceUpdater> updater = CreateUpdaterForHardware();
EXPECT_EQ(0u, GetSharedImageCount());
scoped_refptr<VideoFrame> video_frame = CreateTestHardwareVideoFrame(
viz::MultiPlaneFormat::kP010, PIXEL_FORMAT_P010LE,
GL_TEXTURE_EXTERNAL_OES);
video_frame->set_color_space(kHDR10ColorSpace);
video_frame->set_hdr_metadata(hdr_metadata);
VideoFrameExternalResource resource =
updater->CreateExternalResourceFromVideoFrame(video_frame);
EXPECT_EQ(VideoFrameResourceType::RGB, resource.type);
EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES),
resource.resource.texture_target());
EXPECT_EQ(viz::MultiPlaneFormat::kP010, resource.resource.format);
EXPECT_EQ(kHDR10ColorSpace, resource.resource.color_space);
EXPECT_EQ(hdr_metadata, resource.resource.hdr_metadata);
EXPECT_EQ(0u, GetSharedImageCount());
}
} // namespace
} // namespace media