summaryrefslogtreecommitdiff
path: root/chromium/media/gpu/android/android_video_surface_chooser_impl_unittest.cc
blob: 9f5eff7e972a125fa5b515c8aecac5f3ec861893 (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/gpu/android/android_video_surface_chooser_impl.h"

#include <stdint.h>

#include <memory>

#include "base/bind.h"
#include "base/test/simple_test_tick_clock.h"
#include "media/base/android/mock_android_overlay.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using ::testing::AnyNumber;
using ::testing::Bool;
using ::testing::Combine;
using ::testing::NotNull;
using ::testing::Return;
using ::testing::StrictMock;
using ::testing::Values;
using ::testing::_;

namespace {
using ::media::AndroidOverlay;
using ::media::MockAndroidOverlay;

class MockClient {
 public:
  MOCK_METHOD1(UseOverlay, void(AndroidOverlay*));

  void UseOverlayImpl(std::unique_ptr<AndroidOverlay> overlay) {
    UseOverlay(overlay.get());

    // Also take ownership of the overlay, so that it's not destroyed.
    overlay_ = std::move(overlay);
  }

  // Note that this won't clear |overlay_|, which is helpful.
  MOCK_METHOD0(UseTextureOwner, void(void));

  // Let the test have the overlay.
  std::unique_ptr<AndroidOverlay> ReleaseOverlay() {
    return std::move(overlay_);
  }

 private:
  std::unique_ptr<AndroidOverlay> overlay_;
};

// Strongly-typed enums for TestParams.  It would be nice if Values() didn't
// do something that causes these to work anyway if you mis-match them.  Maybe
// it'll work better in a future gtest.  At the very least, it's a lot more
// readable than 'true' and 'false' in the test instantiations.
//
// Outputs from the chooser.
enum class ShouldUseOverlay { No, Yes };
enum class ShouldBePowerEfficient { No, Yes, Ignored /* for clarity */ };
// Inputs to the chooser.
enum class AllowDynamic { No, Yes };
enum class IsFullscreen { No, Yes };
enum class IsRequired { No, Yes };
enum class IsSecure { No, Yes };
enum class IsCCPromotable { No, Yes };
enum class IsExpectingRelayout { No, Yes };
enum class PromoteAggressively { No, Yes };
// Since gtest only supports ten args, combine some uncommon ones.
enum class MiscFlags { None, Rotated, Persistent };

// Allow any misc flag values.
#define AnyMisc \
  Values(MiscFlags::None, MiscFlags::Rotated, MiscFlags::Persistent)

using TestParams = std::tuple<ShouldUseOverlay,
                              ShouldBePowerEfficient,
                              AllowDynamic,
                              IsRequired,
                              IsFullscreen,
                              IsSecure,
                              IsCCPromotable,
                              IsExpectingRelayout,
                              PromoteAggressively,
                              MiscFlags>;

// Useful macro for instantiating tests.
#define Either(x) Values(x::No, x::Yes)

// Check if a parameter of type |type| is Yes.  |n| is the location of the
// parameter of that type.
// c++14 can remove |n|, and std::get() by type.
#define IsYes(type, n) (::testing::get<n>(GetParam()) == type::Yes)
#define IsIgnored(type, n) (::testing::get<n>(GetParam()) == type::Ignored)
// |v| is the value to check for equality.
#define IsEqual(type, n, v) (::testing::get<n>(GetParam()) == type::v)

}  // namespace

namespace media {

// Unit tests for AndroidVideoSurfaceChooserImpl
class AndroidVideoSurfaceChooserImplTest
    : public testing::TestWithParam<TestParams> {
 public:
  ~AndroidVideoSurfaceChooserImplTest() override {}

  void SetUp() override {
    overlay_ = std::make_unique<MockAndroidOverlay>();

    // Advance the clock just so we're not at 0.
    tick_clock_.Advance(base::TimeDelta::FromSeconds(10));

    // Don't prevent promotions because of the compositor.
    chooser_state_.is_compositor_promotable = true;

    // We create a destruction observer.  By default, the overlay must not be
    // destroyed until the test completes.  Of course, the test may ask the
    // observer to expect something else.
    destruction_observer_ = overlay_->CreateDestructionObserver();
    destruction_observer_->DoNotAllowDestruction();
    overlay_callbacks_ = overlay_->GetCallbacks();
  }

  void TearDown() override {
    // If we get this far, the assume that whatever |destruction_observer_|
    // was looking for should have already happened.  We don't want the
    // lifetime of the observer to matter with respect to the overlay when
    // checking expectations.
    // Note that it might already be null.
    destruction_observer_ = nullptr;
  }

  // Start the chooser, providing |factory| as the initial factory.
  void StartChooser(AndroidOverlayFactoryCB factory) {
    chooser_ = std::make_unique<AndroidVideoSurfaceChooserImpl>(allow_dynamic_,
                                                                &tick_clock_);
    chooser_->SetClientCallbacks(
        base::BindRepeating(&MockClient::UseOverlayImpl,
                            base::Unretained(&client_)),
        base::BindRepeating(&MockClient::UseTextureOwner,
                            base::Unretained(&client_)));
    chooser_->UpdateState(
        factory ? base::make_optional(std::move(factory)) : base::nullopt,
        chooser_state_);
  }

  // Start the chooser with |overlay_|, and verify that the client is told to
  // use it.  As a convenience, return the overlay raw ptr.
  MockAndroidOverlay* StartChooserAndProvideOverlay() {
    MockAndroidOverlay* overlay = overlay_.get();

    EXPECT_CALL(*this, MockOnOverlayCreated());
    StartChooser(FactoryFor(std::move(overlay_)));
    testing::Mock::VerifyAndClearExpectations(&client_);
    testing::Mock::VerifyAndClearExpectations(this);
    EXPECT_CALL(client_, UseOverlay(NotNull()));
    overlay_callbacks_.OverlayReady.Run();

    return overlay;
  }

  // AndroidOverlayFactoryCB is a RepeatingCallback, so we can't just bind
  // something that uses unique_ptr.  RepeatingCallback needs to copy it.
  class Factory {
   public:
    Factory(std::unique_ptr<MockAndroidOverlay> overlay,
            base::RepeatingCallback<void()> create_overlay_cb)
        : overlay_(std::move(overlay)),
          create_overlay_cb_(std::move(create_overlay_cb)) {}

    // Return whatever overlay we're given.  This is used to construct factory
    // callbacks for the chooser.
    std::unique_ptr<AndroidOverlay> ReturnOverlay(AndroidOverlayConfig config) {
      // Notify the mock.
      create_overlay_cb_.Run();
      if (overlay_)
        overlay_->SetConfig(std::move(config));
      return std::move(overlay_);
    }

   private:
    std::unique_ptr<MockAndroidOverlay> overlay_;
    base::RepeatingCallback<void()> create_overlay_cb_;
  };

  // Create a factory that will return |overlay| when run.
  AndroidOverlayFactoryCB FactoryFor(
      std::unique_ptr<MockAndroidOverlay> overlay) {
    Factory* factory = new Factory(
        std::move(overlay),
        base::Bind(&AndroidVideoSurfaceChooserImplTest::MockOnOverlayCreated,
                   base::Unretained(this)));

    // Leaky!
    return base::Bind(&Factory::ReturnOverlay, base::Unretained(factory));
  }

  // Called by the factory when it's run.
  MOCK_METHOD0(MockOnOverlayCreated, void());

  std::unique_ptr<AndroidVideoSurfaceChooserImpl> chooser_;
  StrictMock<MockClient> client_;
  std::unique_ptr<MockAndroidOverlay> overlay_;

  // Callbacks to control the overlay that will be vended by |factory_|
  MockAndroidOverlay::Callbacks overlay_callbacks_;

  std::unique_ptr<DestructionObserver> destruction_observer_;

  // Will the chooser created by StartChooser() support dynamic surface changes?
  bool allow_dynamic_ = true;

  base::SimpleTestTickClock tick_clock_;

  AndroidVideoSurfaceChooser::State chooser_state_;
};

TEST_F(AndroidVideoSurfaceChooserImplTest,
       InitializeWithoutFactoryUsesTextureOwner) {
  // Calling Initialize() with no factory should result in a callback to use
  // texture owner.
  EXPECT_CALL(client_, UseTextureOwner());
  StartChooser(AndroidOverlayFactoryCB());
}

TEST_F(AndroidVideoSurfaceChooserImplTest, NullInitialOverlayUsesTextureOwner) {
  // If we provide a factory, but it fails to create an overlay, then |client_|
  // should be notified to use a texture owner.

  chooser_state_.is_fullscreen = true;
  EXPECT_CALL(*this, MockOnOverlayCreated());
  EXPECT_CALL(client_, UseTextureOwner());
  StartChooser(FactoryFor(nullptr));
}

TEST_F(AndroidVideoSurfaceChooserImplTest,
       FailedInitialOverlayUsesTextureOwner) {
  // If we provide a factory, but the overlay that it provides returns 'failed',
  // then |client_| should use texture owner.  Also check that it won't retry
  // after a failed overlay too soon.
  chooser_state_.is_fullscreen = true;
  EXPECT_CALL(*this, MockOnOverlayCreated());
  StartChooser(FactoryFor(std::move(overlay_)));

  testing::Mock::VerifyAndClearExpectations(&client_);
  testing::Mock::VerifyAndClearExpectations(this);

  // The overlay may be destroyed at any time after we send OverlayFailed.  It
  // doesn't have to be destroyed.  We just care that it hasn't been destroyed
  // before now.
  destruction_observer_ = nullptr;
  EXPECT_CALL(client_, UseTextureOwner());
  overlay_callbacks_.OverlayFailed.Run();
  testing::Mock::VerifyAndClearExpectations(&client_);
  testing::Mock::VerifyAndClearExpectations(this);

  // Try to get it to choose again, which shouldn't do anything.
  tick_clock_.Advance(base::TimeDelta::FromSeconds(2));
  EXPECT_CALL(*this, MockOnOverlayCreated()).Times(0);
  chooser_->UpdateState(FactoryFor(nullptr), chooser_state_);
  testing::Mock::VerifyAndClearExpectations(&client_);
  testing::Mock::VerifyAndClearExpectations(this);

  // Advance some more and try again.  This time, it should request an overlay
  // from the factory.
  tick_clock_.Advance(base::TimeDelta::FromSeconds(100));
  EXPECT_CALL(*this, MockOnOverlayCreated()).Times(1);
  chooser_->UpdateState(FactoryFor(nullptr), chooser_state_);
  testing::Mock::VerifyAndClearExpectations(&client_);
  testing::Mock::VerifyAndClearExpectations(this);
}

TEST_F(AndroidVideoSurfaceChooserImplTest, NullLaterOverlayUsesTextureOwner) {
  // If an overlay factory is provided after startup that returns a null overlay
  // from CreateOverlay, |chooser_| should, at most, notify |client_| to use
  // TextureOwner zero or more times.

  // Start with TextureOwner.
  chooser_state_.is_fullscreen = true;
  EXPECT_CALL(client_, UseTextureOwner());
  allow_dynamic_ = true;
  StartChooser(AndroidOverlayFactoryCB());
  testing::Mock::VerifyAndClearExpectations(&client_);

  // Provide a factory that will return a null overlay.
  EXPECT_CALL(*this, MockOnOverlayCreated());
  EXPECT_CALL(client_, UseTextureOwner()).Times(AnyNumber());
  chooser_->UpdateState(FactoryFor(nullptr), chooser_state_);
}

TEST_F(AndroidVideoSurfaceChooserImplTest, FailedLaterOverlayDoesNothing) {
  // If we send an overlay factory that returns an overlay, and that overlay
  // fails, then the client should not be notified except for zero or more
  // callbacks to switch to texture owner.

  // Start with TextureOwner.
  chooser_state_.is_fullscreen = true;
  EXPECT_CALL(client_, UseTextureOwner());
  StartChooser(AndroidOverlayFactoryCB());
  testing::Mock::VerifyAndClearExpectations(&client_);

  // Provide a factory.
  EXPECT_CALL(*this, MockOnOverlayCreated());
  EXPECT_CALL(client_, UseTextureOwner()).Times(AnyNumber());
  chooser_->UpdateState(FactoryFor(std::move(overlay_)), chooser_state_);
  testing::Mock::VerifyAndClearExpectations(&client_);

  // Fail the overlay.  We don't care if it's destroyed after that, as long as
  // it hasn't been destroyed yet.
  destruction_observer_ = nullptr;
  overlay_callbacks_.OverlayFailed.Run();
}

TEST_F(AndroidVideoSurfaceChooserImplTest,
       SuccessfulLaterOverlayNotifiesClient) {
  // |client_| is notified if we provide a factory that gets an overlay.

  // Start with TextureOwner.
  chooser_state_.is_fullscreen = true;
  EXPECT_CALL(client_, UseTextureOwner());
  StartChooser(AndroidOverlayFactoryCB());
  testing::Mock::VerifyAndClearExpectations(&client_);

  // Provide a factory.  |chooser_| should try to create an overlay.  We don't
  // care if a call to UseTextureOwner is elided or not.  Note that AVDA will
  // ignore duplicate calls anyway (MultipleTextureOwnerCallbacksAreIgnored).
  EXPECT_CALL(*this, MockOnOverlayCreated());
  EXPECT_CALL(client_, UseTextureOwner()).Times(AnyNumber());
  chooser_->UpdateState(FactoryFor(std::move(overlay_)), chooser_state_);
  testing::Mock::VerifyAndClearExpectations(&client_);
  testing::Mock::VerifyAndClearExpectations(this);

  // Notify |chooser_| that the overlay is ready.
  EXPECT_CALL(client_, UseOverlay(NotNull()));
  overlay_callbacks_.OverlayReady.Run();
}

TEST_F(AndroidVideoSurfaceChooserImplTest,
       UpdateStateAfterDeleteRetriesOverlay) {
  // Make sure that SurfaceChooser notices that we delete the overlay, and have
  // switched back to TextureOwner mode.

  chooser_state_.is_fullscreen = true;
  StartChooserAndProvideOverlay();

  // Delete the overlay.
  destruction_observer_ = nullptr;
  client_.ReleaseOverlay();

  // Force chooser to choose again.  We expect that it will retry the overlay,
  // since the delete should have informed it that we've switched back to
  // TextureOwner without a callback from SurfaceChooser.  If it didn't know
  // this, then it would think that the client is still using an overlay, and
  // take no action.

  // Note that if it enforces a delay here before retrying, that might be okay
  // too.  For now, we assume that it doesn't.
  EXPECT_CALL(*this, MockOnOverlayCreated());
  chooser_->UpdateState(base::Optional<AndroidOverlayFactoryCB>(),
                        chooser_state_);
}

TEST_F(AndroidVideoSurfaceChooserImplTest,
       PowerEffcientOverlayCancelsIfNotPowerEfficient) {
  // If we request a power efficient overlay that later becomes not power
  // efficient, then the client should switch to TextureOwner.

  chooser_state_.promote_aggressively = true;
  MockAndroidOverlay* overlay = StartChooserAndProvideOverlay();

  // Verify that this results in a power efficient overlay.  If not, then we've
  // picked the wrong flags, since we're just assuming what state will make the
  // chooser care about power-efficiency.
  ASSERT_TRUE(overlay->config()->power_efficient);

  // Notify the chooser that it's not power efficient anymore.
  EXPECT_CALL(client_, UseTextureOwner());
  overlay_callbacks_.PowerEfficientState.Run(false);
}

TEST_F(AndroidVideoSurfaceChooserImplTest, AlwaysUseTextureOwner) {
  // Start with an overlay.
  chooser_state_.is_fullscreen = true;
  StartChooserAndProvideOverlay();
  testing::Mock::VerifyAndClearExpectations(&client_);

  // Change the state to force texture owner. It should use the TextureOwner
  // instead.
  chooser_state_.always_use_texture_owner = true;
  EXPECT_CALL(client_, UseTextureOwner());
  chooser_->UpdateState(base::nullopt, chooser_state_);
}

TEST_P(AndroidVideoSurfaceChooserImplTest, OverlayIsUsedOrNotBasedOnState) {
  // Provide a factory, and verify that it is used when the state says that it
  // should be.  If the overlay is used, then we also verify that it does not
  // switch to TextureOwner first, since pre-M requires it.

  const bool should_use_overlay = IsYes(ShouldUseOverlay, 0);
  const bool should_be_power_efficient = IsYes(ShouldBePowerEfficient, 1);
  const bool ignore_power_efficient = IsIgnored(ShouldBePowerEfficient, 1);
  allow_dynamic_ = IsYes(AllowDynamic, 2);
  chooser_state_.is_required = IsYes(IsRequired, 3);
  chooser_state_.is_fullscreen = IsYes(IsFullscreen, 4);
  chooser_state_.is_secure = IsYes(IsSecure, 5);
  chooser_state_.is_compositor_promotable = IsYes(IsCCPromotable, 6);
  chooser_state_.is_expecting_relayout = IsYes(IsExpectingRelayout, 7);
  chooser_state_.promote_aggressively = IsYes(PromoteAggressively, 8);
  chooser_state_.video_rotation =
      IsEqual(MiscFlags, 9, Rotated) ? VIDEO_ROTATION_90 : VIDEO_ROTATION_0;
  chooser_state_.is_persistent_video = IsEqual(MiscFlags, 9, Persistent);

  MockAndroidOverlay* overlay = overlay_.get();

  if (should_use_overlay) {
    EXPECT_CALL(client_, UseTextureOwner()).Times(0);
    EXPECT_CALL(*this, MockOnOverlayCreated());
  } else {
    EXPECT_CALL(client_, UseTextureOwner());
    EXPECT_CALL(*this, MockOnOverlayCreated()).Times(0);
  }

  StartChooser(FactoryFor(std::move(overlay_)));

  // Check that the overlay config has the right power-efficient state set.
  if (should_use_overlay && !ignore_power_efficient)
    ASSERT_EQ(should_be_power_efficient, overlay->config()->power_efficient);

  // Verify that the overlay is provided when it becomes ready.
  if (should_use_overlay) {
    EXPECT_CALL(client_, UseOverlay(NotNull()));
    overlay_callbacks_.OverlayReady.Run();
  }
}

// Unless we're promoting aggressively, we should default to TextureOwner.
INSTANTIATE_TEST_SUITE_P(NoFullscreenUsesTextureOwner,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::No),
                                 Values(ShouldBePowerEfficient::Ignored),
                                 Either(AllowDynamic),
                                 Values(IsRequired::No),
                                 Values(IsFullscreen::No),
                                 Values(IsSecure::No),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Values(PromoteAggressively::No),
                                 AnyMisc));

INSTANTIATE_TEST_SUITE_P(FullscreenUsesOverlay,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::Ignored),
                                 Either(AllowDynamic),
                                 Either(IsRequired),
                                 Values(IsFullscreen::Yes),
                                 Values(IsSecure::No),
                                 Values(IsCCPromotable::Yes),
                                 Values(IsExpectingRelayout::No),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None)));

INSTANTIATE_TEST_SUITE_P(RequiredUsesOverlay,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::Yes),
                                 Values(IsRequired::Yes),
                                 Either(IsFullscreen),
                                 Either(IsSecure),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None,
                                        MiscFlags::Persistent)));

// Secure textures should use an overlay if the compositor will promote them.
// We don't care about relayout, since it's transient; either behavior is okay
// if a relayout is epected.  Similarly, hidden frames are fine either way.
INSTANTIATE_TEST_SUITE_P(SecureUsesOverlayIfPromotable,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::No),
                                 Either(AllowDynamic),
                                 Either(IsRequired),
                                 Either(IsFullscreen),
                                 Values(IsSecure::Yes),
                                 Values(IsCCPromotable::Yes),
                                 Values(IsExpectingRelayout::No),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None)));

// For all dynamic cases, we shouldn't use an overlay if the compositor won't
// promote it, unless it's marked as required.  This includes secure surfaces,
// so that L3 will fall back to TextureOwner.  Non-dynamic is excluded, since
// we don't get (or use) compositor feedback before the first frame.  At that
// point, we've already chosen the output surface and can't switch it.
INSTANTIATE_TEST_SUITE_P(NotCCPromotableNotRequiredUsesTextureOwner,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::No),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::Yes),
                                 Values(IsRequired::No),
                                 Either(IsFullscreen),
                                 Either(IsSecure),
                                 Values(IsCCPromotable::No),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 AnyMisc));

// If we're expecting a relayout, then we should never use an overlay unless
// it's required.
INSTANTIATE_TEST_SUITE_P(InsecureExpectingRelayoutUsesTextureOwner,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::No),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::Yes),
                                 Values(IsRequired::No),
                                 Either(IsFullscreen),
                                 Either(IsSecure),
                                 Either(IsCCPromotable),
                                 Values(IsExpectingRelayout::Yes),
                                 Either(PromoteAggressively),
                                 AnyMisc));

// "is_fullscreen" should be enough to trigger an overlay pre-M.
INSTANTIATE_TEST_SUITE_P(NotDynamicInFullscreenUsesOverlay,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::No),
                                 Either(IsRequired),
                                 Values(IsFullscreen::Yes),
                                 Either(IsSecure),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None,
                                        MiscFlags::Persistent)));

// "is_secure" should be enough to trigger an overlay pre-M.
INSTANTIATE_TEST_SUITE_P(NotDynamicSecureUsesOverlay,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::No),
                                 Either(IsRequired),
                                 Either(IsFullscreen),
                                 Values(IsSecure::Yes),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None,
                                        MiscFlags::Persistent)));

// "is_required" should be enough to trigger an overlay pre-M.
INSTANTIATE_TEST_SUITE_P(NotDynamicRequiredUsesOverlay,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::No),
                                 Values(AllowDynamic::No),
                                 Values(IsRequired::Yes),
                                 Either(IsFullscreen),
                                 Either(IsSecure),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::None,
                                        MiscFlags::Persistent)));

// If we're promoting aggressively, then we should request power efficient.
INSTANTIATE_TEST_SUITE_P(AggressiveOverlayIsPowerEfficient,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::Yes),
                                 Values(ShouldBePowerEfficient::Yes),
                                 Values(AllowDynamic::Yes),
                                 Values(IsRequired::No),
                                 Values(IsFullscreen::No),
                                 Values(IsSecure::No),
                                 Values(IsCCPromotable::Yes),
                                 Values(IsExpectingRelayout::No),
                                 Values(PromoteAggressively::Yes),
                                 Values(MiscFlags::None)));

// Rotated video is unsupported for overlays in all cases.
INSTANTIATE_TEST_SUITE_P(IsVideoRotatedUsesTextureOwner,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::No),
                                 Either(ShouldBePowerEfficient),
                                 Either(AllowDynamic),
                                 Either(IsRequired),
                                 Either(IsFullscreen),
                                 Either(IsSecure),
                                 Either(IsCCPromotable),
                                 Either(IsExpectingRelayout),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::Rotated)));

// Persistent, non-required video should not use an overlay.
INSTANTIATE_TEST_SUITE_P(FullscreenPersistentVideoUsesSurfaceTexture,
                         AndroidVideoSurfaceChooserImplTest,
                         Combine(Values(ShouldUseOverlay::No),
                                 Values(ShouldBePowerEfficient::Ignored),
                                 Values(AllowDynamic::Yes),
                                 Values(IsRequired::No),
                                 Values(IsFullscreen::Yes),
                                 Either(IsSecure),
                                 Values(IsCCPromotable::Yes),
                                 Values(IsExpectingRelayout::No),
                                 Either(PromoteAggressively),
                                 Values(MiscFlags::Persistent)));

}  // namespace media