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
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
|
// Copyright 2012 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 "cc/output/gl_renderer.h"
#include "cc/output/compositor_frame_metadata.h"
#include "cc/resources/prioritized_resource_manager.h"
#include "cc/resources/resource_provider.h"
#include "cc/test/fake_impl_proxy.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/mock_quad_culler.h"
#include "cc/test/pixel_test.h"
#include "cc/test/render_pass_test_common.h"
#include "cc/test/render_pass_test_utils.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/core/SkMatrix.h"
#include "third_party/skia/include/effects/SkColorFilterImageFilter.h"
#include "third_party/skia/include/effects/SkColorMatrixFilter.h"
#include "ui/gfx/transform.h"
using testing::_;
using testing::AnyNumber;
using testing::AtLeast;
using testing::Expectation;
using testing::InSequence;
using testing::Mock;
using testing::Return;
using testing::StrictMock;
using WebKit::WebGraphicsMemoryAllocation;
using WebKit::WebGLId;
using WebKit::WebString;
using WebKit::WGC3Dbitfield;
using WebKit::WGC3Dboolean;
using WebKit::WGC3Dchar;
using WebKit::WGC3Denum;
using WebKit::WGC3Dfloat;
using WebKit::WGC3Dint;
using WebKit::WGC3Dintptr;
using WebKit::WGC3Dsizei;
using WebKit::WGC3Dsizeiptr;
using WebKit::WGC3Duint;
namespace cc {
#define EXPECT_PROGRAM_VALID(program_binding) \
do { \
EXPECT_TRUE(program_binding->program()); \
EXPECT_TRUE(program_binding->initialized()); \
} while (false)
// Explicitly named to be a friend in GLRenderer for shader access.
class GLRendererShaderPixelTest : public PixelTest {
public:
void TestShaders() {
ASSERT_FALSE(renderer_->IsContextLost());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgram());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgramOpaque());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgramAA());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgramSwizzle());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgramSwizzleOpaque());
EXPECT_PROGRAM_VALID(renderer_->GetTileProgramSwizzleAA());
EXPECT_PROGRAM_VALID(renderer_->GetTileCheckerboardProgram());
EXPECT_PROGRAM_VALID(renderer_->GetDebugBorderProgram());
EXPECT_PROGRAM_VALID(renderer_->GetSolidColorProgram());
EXPECT_PROGRAM_VALID(renderer_->GetSolidColorProgramAA());
//TestShadersWithTexCoordPrecision(TexCoordPrecisionMedium);
TestShadersWithTexCoordPrecision(TexCoordPrecisionHigh);
ASSERT_FALSE(renderer_->IsContextLost());
}
void TestShadersWithTexCoordPrecision(TexCoordPrecision precision) {
EXPECT_PROGRAM_VALID(renderer_->GetRenderPassProgram(precision));
EXPECT_PROGRAM_VALID(renderer_->GetRenderPassProgramAA(precision));
EXPECT_PROGRAM_VALID(renderer_->GetRenderPassMaskProgram(precision));
EXPECT_PROGRAM_VALID(renderer_->GetRenderPassMaskProgramAA(precision));
EXPECT_PROGRAM_VALID(
renderer_->GetRenderPassColorMatrixProgram(precision));
EXPECT_PROGRAM_VALID(
renderer_->GetRenderPassMaskColorMatrixProgramAA(precision));
EXPECT_PROGRAM_VALID(
renderer_->GetRenderPassColorMatrixProgramAA(precision));
EXPECT_PROGRAM_VALID(
renderer_->GetRenderPassMaskColorMatrixProgram(precision));
EXPECT_PROGRAM_VALID(renderer_->GetTextureProgram(precision));
EXPECT_PROGRAM_VALID(renderer_->GetTextureProgramFlip(precision));
EXPECT_PROGRAM_VALID(renderer_->GetTextureIOSurfaceProgram(precision));
EXPECT_PROGRAM_VALID(renderer_->GetVideoYUVProgram(precision));
// This is unlikely to be ever true in tests due to usage of osmesa.
if (renderer_->Capabilities().using_egl_image)
EXPECT_PROGRAM_VALID(renderer_->GetVideoStreamTextureProgram(precision));
else
EXPECT_FALSE(renderer_->GetVideoStreamTextureProgram(precision));
}
};
namespace {
#if !defined(OS_ANDROID)
TEST_F(GLRendererShaderPixelTest, AllShadersCompile) { TestShaders(); }
#endif
class FrameCountingMemoryAllocationSettingContext
: public TestWebGraphicsContext3D {
public:
FrameCountingMemoryAllocationSettingContext() : frame_(0) {}
// WebGraphicsContext3D methods.
// This method would normally do a glSwapBuffers under the hood.
virtual void prepareTexture() { frame_++; }
virtual void setMemoryAllocationChangedCallbackCHROMIUM(
WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) {
memory_allocation_changed_callback_ = callback;
}
virtual WebString getString(WebKit::WGC3Denum name) {
if (name == GL_EXTENSIONS)
return WebString(
"GL_CHROMIUM_set_visibility GL_CHROMIUM_gpu_memory_manager "
"GL_CHROMIUM_discard_backbuffer");
return WebString();
}
// Methods added for test.
int frame_count() { return frame_; }
void SetMemoryAllocation(WebGraphicsMemoryAllocation allocation) {
memory_allocation_changed_callback_->onMemoryAllocationChanged(allocation);
}
private:
int frame_;
WebGraphicsMemoryAllocationChangedCallbackCHROMIUM*
memory_allocation_changed_callback_;
};
class FakeRendererClient : public RendererClient {
public:
FakeRendererClient()
: host_impl_(&proxy_),
set_full_root_layer_damage_count_(0),
last_call_was_set_visibility_(0),
root_layer_(LayerImpl::Create(host_impl_.active_tree(), 1)),
memory_allocation_limit_bytes_(
PrioritizedResourceManager::DefaultMemoryAllocationLimit()) {
root_layer_->CreateRenderSurface();
RenderPass::Id render_pass_id =
root_layer_->render_surface()->RenderPassId();
scoped_ptr<RenderPass> root_render_pass = RenderPass::Create();
root_render_pass->SetNew(
render_pass_id, gfx::Rect(), gfx::Rect(), gfx::Transform());
render_passes_in_draw_order_.push_back(root_render_pass.Pass());
}
// RendererClient methods.
virtual gfx::Size DeviceViewportSize() const OVERRIDE {
static gfx::Size fake_size(1, 1);
return fake_size;
}
virtual const LayerTreeSettings& Settings() const OVERRIDE {
static LayerTreeSettings fake_settings;
return fake_settings;
}
virtual void DidLoseOutputSurface() OVERRIDE {}
virtual void OnSwapBuffersComplete() OVERRIDE {}
virtual void SetFullRootLayerDamage() OVERRIDE {
set_full_root_layer_damage_count_++;
}
virtual void SetManagedMemoryPolicy(const ManagedMemoryPolicy& policy)
OVERRIDE {
memory_allocation_limit_bytes_ = policy.bytes_limit_when_visible;
}
virtual void EnforceManagedMemoryPolicy(const ManagedMemoryPolicy& policy)
OVERRIDE {
if (last_call_was_set_visibility_)
*last_call_was_set_visibility_ = false;
}
virtual bool HasImplThread() const OVERRIDE { return false; }
virtual bool ShouldClearRootRenderPass() const OVERRIDE { return true; }
virtual CompositorFrameMetadata MakeCompositorFrameMetadata() const OVERRIDE {
return CompositorFrameMetadata();
}
virtual bool AllowPartialSwap() const OVERRIDE {
return true;
}
// Methods added for test.
int set_full_root_layer_damage_count() const {
return set_full_root_layer_damage_count_;
}
void set_last_call_was_set_visibility_pointer(
bool* last_call_was_set_visibility) {
last_call_was_set_visibility_ = last_call_was_set_visibility;
}
RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); }
RenderPassList* render_passes_in_draw_order() {
return &render_passes_in_draw_order_;
}
size_t memory_allocation_limit_bytes() const {
return memory_allocation_limit_bytes_;
}
private:
FakeImplProxy proxy_;
FakeLayerTreeHostImpl host_impl_;
int set_full_root_layer_damage_count_;
bool* last_call_was_set_visibility_;
scoped_ptr<LayerImpl> root_layer_;
RenderPassList render_passes_in_draw_order_;
size_t memory_allocation_limit_bytes_;
};
class FakeRendererGL : public GLRenderer {
public:
FakeRendererGL(RendererClient* client,
OutputSurface* output_surface,
ResourceProvider* resource_provider)
: GLRenderer(client, output_surface, resource_provider, 0) {}
// GLRenderer methods.
// Changing visibility to public.
using GLRenderer::Initialize;
using GLRenderer::IsBackbufferDiscarded;
using GLRenderer::DoDrawQuad;
using GLRenderer::BeginDrawingFrame;
using GLRenderer::FinishDrawingQuadList;
};
class GLRendererTest : public testing::Test {
protected:
GLRendererTest()
: suggest_have_backbuffer_yes_(1, true),
suggest_have_backbuffer_no_(1, false),
output_surface_(FakeOutputSurface::Create3d(
scoped_ptr<WebKit::WebGraphicsContext3D>(
new FrameCountingMemoryAllocationSettingContext()))),
resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
renderer_(&mock_client_,
output_surface_.get(),
resource_provider_.get()) {}
virtual void SetUp() { renderer_.Initialize(); }
void SwapBuffers() { renderer_.SwapBuffers(); }
FrameCountingMemoryAllocationSettingContext* context() {
return static_cast<FrameCountingMemoryAllocationSettingContext*>(
output_surface_->context3d());
}
WebGraphicsMemoryAllocation suggest_have_backbuffer_yes_;
WebGraphicsMemoryAllocation suggest_have_backbuffer_no_;
scoped_ptr<OutputSurface> output_surface_;
FakeRendererClient mock_client_;
scoped_ptr<ResourceProvider> resource_provider_;
FakeRendererGL renderer_;
};
// Closing the namespace here so that GLRendererShaderTest can take advantage
// of the friend relationship with GLRenderer and all of the mock classes
// declared above it.
} // namespace
class GLRendererShaderTest : public testing::Test {
protected:
GLRendererShaderTest()
: output_surface_(FakeOutputSurface::Create3d()),
resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
renderer_(GLRenderer::Create(&mock_client_, output_surface_.get(),
resource_provider_.get(), 0)) {
}
void TestRenderPassProgram() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_program_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_program_->program());
}
void TestRenderPassColorMatrixProgram() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_color_matrix_program_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_color_matrix_program_->program());
}
void TestRenderPassMaskProgram() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_mask_program_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_mask_program_->program());
}
void TestRenderPassMaskColorMatrixProgram() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_mask_color_matrix_program_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_mask_color_matrix_program_->program());
}
void TestRenderPassProgramAA() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_program_aa_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_program_aa_->program());
}
void TestRenderPassColorMatrixProgramAA() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_color_matrix_program_aa_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_color_matrix_program_aa_->program());
}
void TestRenderPassMaskProgramAA() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_mask_program_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_program_aa_->program());
}
void TestRenderPassMaskColorMatrixProgramAA() {
EXPECT_PROGRAM_VALID(renderer_->render_pass_mask_color_matrix_program_aa_);
EXPECT_TRUE(renderer_->program_shadow_ ==
renderer_->render_pass_color_matrix_program_aa_->program());
}
scoped_ptr<OutputSurface> output_surface_;
FakeRendererClient mock_client_;
scoped_ptr<ResourceProvider> resource_provider_;
scoped_ptr<GLRenderer> renderer_;
};
namespace {
// Test GLRenderer discardBackbuffer functionality:
// Suggest recreating framebuffer when one already exists.
// Expected: it does nothing.
TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) {
context()->SetMemoryAllocation(suggest_have_backbuffer_yes_);
EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count());
EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
SwapBuffers();
EXPECT_EQ(1, context()->frame_count());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Suggest discarding framebuffer when one exists and the renderer is not
// visible.
// Expected: it is discarded and damage tracker is reset.
TEST_F(
GLRendererTest,
SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayerIfNotVisible) {
renderer_.SetVisible(false);
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Suggest discarding framebuffer when one exists and the renderer is visible.
// Expected: the allocation is ignored.
TEST_F(GLRendererTest, SuggestBackbufferNoDoNothingWhenVisible) {
renderer_.SetVisible(true);
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count());
EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Suggest discarding framebuffer when one does not exist.
// Expected: it does nothing.
TEST_F(GLRendererTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) {
renderer_.SetVisible(false);
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
}
// Test GLRenderer DiscardBackbuffer functionality:
// Begin drawing a frame while a framebuffer is discarded.
// Expected: will recreate framebuffer.
TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) {
renderer_.SetVisible(false);
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
renderer_.SetVisible(true);
renderer_.DrawFrame(mock_client_.render_passes_in_draw_order());
EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
SwapBuffers();
EXPECT_EQ(1, context()->frame_count());
}
TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) {
renderer_.SetVisible(false);
context()->SetMemoryAllocation(suggest_have_backbuffer_no_);
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count());
char pixels[4];
renderer_.DrawFrame(mock_client_.render_passes_in_draw_order());
EXPECT_FALSE(renderer_.IsBackbufferDiscarded());
renderer_.GetFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1));
EXPECT_TRUE(renderer_.IsBackbufferDiscarded());
EXPECT_EQ(2, mock_client_.set_full_root_layer_damage_count());
}
class ForbidSynchronousCallContext : public TestWebGraphicsContext3D {
public:
ForbidSynchronousCallContext() {}
virtual bool getActiveAttrib(WebGLId program,
WGC3Duint index,
ActiveInfo& info) {
ADD_FAILURE();
return false;
}
virtual bool getActiveUniform(WebGLId program,
WGC3Duint index,
ActiveInfo& info) {
ADD_FAILURE();
return false;
}
virtual void getAttachedShaders(WebGLId program,
WGC3Dsizei max_count,
WGC3Dsizei* count,
WebGLId* shaders) {
ADD_FAILURE();
}
virtual WGC3Dint getAttribLocation(WebGLId program, const WGC3Dchar* name) {
ADD_FAILURE();
return 0;
}
virtual void getBooleanv(WGC3Denum pname, WGC3Dboolean* value) {
ADD_FAILURE();
}
virtual void getBufferParameteriv(WGC3Denum target,
WGC3Denum pname,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual Attributes getContextAttributes() {
ADD_FAILURE();
return attributes_;
}
virtual WGC3Denum getError() {
ADD_FAILURE();
return 0;
}
virtual void getFloatv(WGC3Denum pname, WGC3Dfloat* value) { ADD_FAILURE(); }
virtual void getFramebufferAttachmentParameteriv(WGC3Denum target,
WGC3Denum attachment,
WGC3Denum pname,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual void getIntegerv(WGC3Denum pname, WGC3Dint* value) {
if (pname == GL_MAX_TEXTURE_SIZE) {
// MAX_TEXTURE_SIZE is cached client side, so it's OK to query.
*value = 1024;
} else {
ADD_FAILURE();
}
}
// We allow querying the shader compilation and program link status in debug
// mode, but not release.
virtual void getProgramiv(WebGLId program, WGC3Denum pname, WGC3Dint* value) {
#ifndef NDEBUG
*value = 1;
#else
ADD_FAILURE();
#endif
}
virtual void getShaderiv(WebGLId shader, WGC3Denum pname, WGC3Dint* value) {
#ifndef NDEBUG
*value = 1;
#else
ADD_FAILURE();
#endif
}
virtual WebString getString(WGC3Denum name) {
// We allow querying the extension string.
// FIXME: It'd be better to check that we only do this before starting any
// other expensive work (like starting a compilation)
if (name != GL_EXTENSIONS)
ADD_FAILURE();
return WebString();
}
virtual WebString getProgramInfoLog(WebGLId program) {
ADD_FAILURE();
return WebString();
}
virtual void getRenderbufferParameteriv(WGC3Denum target,
WGC3Denum pname,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual WebString getShaderInfoLog(WebGLId shader) {
ADD_FAILURE();
return WebString();
}
virtual void getShaderPrecisionFormat(WGC3Denum shadertype,
WGC3Denum precisiontype,
WGC3Dint* range,
WGC3Dint* precision) {
ADD_FAILURE();
}
virtual WebString getShaderSource(WebGLId shader) {
ADD_FAILURE();
return WebString();
}
virtual void getTexParameterfv(WGC3Denum target,
WGC3Denum pname,
WGC3Dfloat* value) {
ADD_FAILURE();
}
virtual void getTexParameteriv(WGC3Denum target,
WGC3Denum pname,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual void getUniformfv(WebGLId program,
WGC3Dint location,
WGC3Dfloat* value) {
ADD_FAILURE();
}
virtual void getUniformiv(WebGLId program,
WGC3Dint location,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual WGC3Dint getUniformLocation(WebGLId program, const WGC3Dchar* name) {
ADD_FAILURE();
return 0;
}
virtual void getVertexAttribfv(WGC3Duint index,
WGC3Denum pname,
WGC3Dfloat* value) {
ADD_FAILURE();
}
virtual void getVertexAttribiv(WGC3Duint index,
WGC3Denum pname,
WGC3Dint* value) {
ADD_FAILURE();
}
virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index,
WGC3Denum pname) {
ADD_FAILURE();
return 0;
}
};
// This test isn't using the same fixture as GLRendererTest, and you can't mix
// TEST() and TEST_F() with the same name, Hence LRC2.
TEST(GLRendererTest2, InitializationDoesNotMakeSynchronousCalls) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new ForbidSynchronousCallContext)));
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
}
class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D {
public:
LoseContextOnFirstGetContext() : context_lost_(false) {}
virtual bool makeContextCurrent() OVERRIDE { return !context_lost_; }
virtual void getProgramiv(WebGLId program, WGC3Denum pname, WGC3Dint* value)
OVERRIDE {
context_lost_ = true;
*value = 0;
}
virtual void getShaderiv(WebGLId shader, WGC3Denum pname, WGC3Dint* value)
OVERRIDE {
context_lost_ = true;
*value = 0;
}
virtual WGC3Denum getGraphicsResetStatusARB() OVERRIDE {
return context_lost_ ? 1 : 0;
}
private:
bool context_lost_;
};
TEST(GLRendererTest2, InitializationWithQuicklyLostContextDoesNotAssert) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new LoseContextOnFirstGetContext)));
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
renderer.Initialize();
}
class ContextThatDoesNotSupportMemoryManagmentExtensions
: public TestWebGraphicsContext3D {
public:
ContextThatDoesNotSupportMemoryManagmentExtensions() {}
// WebGraphicsContext3D methods.
// This method would normally do a glSwapBuffers under the hood.
virtual void prepareTexture() {}
virtual void setMemoryAllocationChangedCallbackCHROMIUM(
WebGraphicsMemoryAllocationChangedCallbackCHROMIUM* callback) {}
virtual WebString getString(WebKit::WGC3Denum name) { return WebString(); }
};
TEST(
GLRendererTest2,
InitWithoutGpuMemManagerExtensionSupportShouldDefaultToNonZeroAllocation) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new ContextThatDoesNotSupportMemoryManagmentExtensions)));
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
renderer.Initialize();
EXPECT_GT(mock_client.memory_allocation_limit_bytes(), 0ul);
}
class ClearCountingContext : public TestWebGraphicsContext3D {
public:
ClearCountingContext() : clear_(0) {}
virtual void clear(WGC3Dbitfield) { clear_++; }
int clear_count() const { return clear_; }
private:
int clear_;
};
TEST(GLRendererTest2, OpaqueBackground) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
ClearCountingContext* context =
static_cast<ClearCountingContext*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
mock_client.root_render_pass()->has_transparent_background = false;
EXPECT_TRUE(renderer.Initialize());
renderer.DrawFrame(mock_client.render_passes_in_draw_order());
// On DEBUG builds, render passes with opaque background clear to blue to
// easily see regions that were not drawn on the screen.
#ifdef NDEBUG
EXPECT_EQ(0, context->clear_count());
#else
EXPECT_EQ(1, context->clear_count());
#endif
}
TEST(GLRendererTest2, TransparentBackground) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext)));
ClearCountingContext* context =
static_cast<ClearCountingContext*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
mock_client.root_render_pass()->has_transparent_background = true;
EXPECT_TRUE(renderer.Initialize());
renderer.DrawFrame(mock_client.render_passes_in_draw_order());
EXPECT_EQ(1, context->clear_count());
}
class VisibilityChangeIsLastCallTrackingContext
: public TestWebGraphicsContext3D {
public:
VisibilityChangeIsLastCallTrackingContext()
: last_call_was_set_visibility_(0) {}
// WebGraphicsContext3D methods.
virtual void setVisibilityCHROMIUM(bool visible) {
if (!last_call_was_set_visibility_)
return;
DCHECK(*last_call_was_set_visibility_ == false);
*last_call_was_set_visibility_ = true;
}
virtual void flush() {
if (last_call_was_set_visibility_)
*last_call_was_set_visibility_ = false;
}
virtual void deleteTexture(WebGLId) {
if (last_call_was_set_visibility_)
*last_call_was_set_visibility_ = false;
}
virtual void deleteFramebuffer(WebGLId) {
if (last_call_was_set_visibility_)
*last_call_was_set_visibility_ = false;
}
virtual void deleteRenderbuffer(WebGLId) {
if (last_call_was_set_visibility_)
*last_call_was_set_visibility_ = false;
}
// This method would normally do a glSwapBuffers under the hood.
virtual WebString getString(WebKit::WGC3Denum name) {
if (name == GL_EXTENSIONS)
return WebString(
"GL_CHROMIUM_set_visibility GL_CHROMIUM_gpu_memory_manager "
"GL_CHROMIUM_discard_backbuffer");
return WebString();
}
// Methods added for test.
void set_last_call_was_set_visibility_pointer(
bool* last_call_was_set_visibility) {
last_call_was_set_visibility_ = last_call_was_set_visibility;
}
private:
bool* last_call_was_set_visibility_;
};
TEST(GLRendererTest2, VisibilityChangeIsLastCall) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new VisibilityChangeIsLastCallTrackingContext)));
VisibilityChangeIsLastCallTrackingContext* context =
static_cast<VisibilityChangeIsLastCallTrackingContext*>(
output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
bool last_call_was_set_visiblity = false;
// Ensure that the call to setVisibilityCHROMIUM is the last call issue to the
// GPU process, after glFlush is called, and after the RendererClient's
// EnforceManagedMemoryPolicy is called. Plumb this tracking between both the
// RenderClient and the Context by giving them both a pointer to a variable on
// the stack.
context->set_last_call_was_set_visibility_pointer(
&last_call_was_set_visiblity);
mock_client.set_last_call_was_set_visibility_pointer(
&last_call_was_set_visiblity);
renderer.SetVisible(true);
renderer.DrawFrame(mock_client.render_passes_in_draw_order());
renderer.SetVisible(false);
EXPECT_TRUE(last_call_was_set_visiblity);
}
class TextureStateTrackingContext : public TestWebGraphicsContext3D {
public:
TextureStateTrackingContext() : active_texture_(GL_INVALID_ENUM) {}
virtual WebString getString(WGC3Denum name) {
if (name == GL_EXTENSIONS)
return WebString("GL_OES_EGL_image_external");
return WebString();
}
MOCK_METHOD3(texParameteri,
void(WGC3Denum target, WGC3Denum pname, WGC3Dint param));
MOCK_METHOD4(drawElements,
void(WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
WGC3Dintptr offset));
virtual void activeTexture(WGC3Denum texture) {
EXPECT_NE(texture, active_texture_);
active_texture_ = texture;
}
WGC3Denum active_texture() const { return active_texture_; }
private:
WGC3Denum active_texture_;
};
TEST(GLRendererTest2, ActiveTextureState) {
FakeRendererClient fake_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new TextureStateTrackingContext)));
TextureStateTrackingContext* context =
static_cast<TextureStateTrackingContext*>(output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&fake_client, output_surface.get(), resource_provider.get());
// During initialization we are allowed to set any texture parameters.
EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber());
EXPECT_TRUE(renderer.Initialize());
cc::RenderPass::Id id(1, 1);
scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
pass->SetNew(id,
gfx::Rect(0, 0, 100, 100),
gfx::Rect(0, 0, 100, 100),
gfx::Transform());
pass->AppendOneOfEveryQuadType(resource_provider.get(), RenderPass::Id(2, 1));
// Set up expected texture filter state transitions that match the quads
// created in AppendOneOfEveryQuadType().
Mock::VerifyAndClearExpectations(context);
{
InSequence sequence;
// yuv_quad is drawn with the default linear filter.
EXPECT_CALL(*context, drawElements(_, _, _, _));
// tile_quad is drawn with GL_NEAREST because it is not transformed or
// scaled.
EXPECT_CALL(
*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
EXPECT_CALL(
*context,
texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
EXPECT_CALL(*context, drawElements(_, _, _, _));
// transformed_tile_quad uses GL_LINEAR.
EXPECT_CALL(*context, drawElements(_, _, _, _));
// scaled_tile_quad also uses GL_LINEAR.
EXPECT_CALL(*context, drawElements(_, _, _, _));
// The remaining quads also use GL_LINEAR because nearest neighbor
// filtering is currently only used with tile quads.
EXPECT_CALL(*context, drawElements(_, _, _, _)).Times(6);
}
cc::DirectRenderer::DrawingFrame drawing_frame;
renderer.BeginDrawingFrame(&drawing_frame);
EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE0), context->active_texture());
for (cc::QuadList::BackToFrontIterator
it = pass->quad_list.BackToFrontBegin();
it != pass->quad_list.BackToFrontEnd();
++it) {
renderer.DoDrawQuad(&drawing_frame, *it);
}
renderer.FinishDrawingQuadList();
EXPECT_EQ(static_cast<unsigned>(GL_TEXTURE0), context->active_texture());
Mock::VerifyAndClearExpectations(context);
}
class NoClearRootRenderPassFakeClient : public FakeRendererClient {
public:
virtual bool ShouldClearRootRenderPass() const OVERRIDE { return false; }
};
class NoClearRootRenderPassMockContext : public TestWebGraphicsContext3D {
public:
MOCK_METHOD1(clear, void(WGC3Dbitfield mask));
MOCK_METHOD4(drawElements,
void(WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
WGC3Dintptr offset));
};
TEST(GLRendererTest2, ShouldClearRootRenderPass) {
NoClearRootRenderPassFakeClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new NoClearRootRenderPassMockContext)));
NoClearRootRenderPassMockContext* mock_context =
static_cast<NoClearRootRenderPassMockContext*>(
output_surface->context3d());
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
gfx::Rect viewport_rect(mock_client.DeviceViewportSize());
ScopedPtrVector<RenderPass>& render_passes =
*mock_client.render_passes_in_draw_order();
render_passes.clear();
RenderPass::Id root_pass_id(1, 0);
TestRenderPass* root_pass = AddRenderPass(
&render_passes, root_pass_id, viewport_rect, gfx::Transform());
AddQuad(root_pass, viewport_rect, SK_ColorGREEN);
RenderPass::Id child_pass_id(2, 0);
TestRenderPass* child_pass = AddRenderPass(
&render_passes, child_pass_id, viewport_rect, gfx::Transform());
AddQuad(child_pass, viewport_rect, SK_ColorBLUE);
AddRenderPassQuad(root_pass, child_pass);
// First render pass is not the root one, clearing should happen.
EXPECT_CALL(*mock_context, clear(GL_COLOR_BUFFER_BIT)).Times(AtLeast(1));
Expectation first_render_pass =
EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(1);
// The second render pass is the root one, clearing should be prevented.
EXPECT_CALL(*mock_context, clear(GL_COLOR_BUFFER_BIT)).Times(0)
.After(first_render_pass);
EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(AnyNumber())
.After(first_render_pass);
renderer.DecideRenderPassAllocationsForFrame(
*mock_client.render_passes_in_draw_order());
renderer.DrawFrame(mock_client.render_passes_in_draw_order());
// In multiple render passes all but the root pass should clear the
// framebuffer.
Mock::VerifyAndClearExpectations(&mock_context);
}
class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D {
public:
ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {}
virtual void clear(WGC3Dbitfield) { EXPECT_FALSE(scissor_enabled_); }
virtual void enable(WGC3Denum cap) {
if (cap == GL_SCISSOR_TEST)
scissor_enabled_ = true;
}
virtual void disable(WGC3Denum cap) {
if (cap == GL_SCISSOR_TEST)
scissor_enabled_ = false;
}
private:
bool scissor_enabled_;
};
TEST(GLRendererTest2, ScissorTestWhenClearing) {
FakeRendererClient mock_client;
scoped_ptr<OutputSurface> output_surface(
FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>(
new ScissorTestOnClearCheckingContext)));
scoped_ptr<ResourceProvider> resource_provider(
ResourceProvider::Create(output_surface.get(), 0));
FakeRendererGL renderer(
&mock_client, output_surface.get(), resource_provider.get());
EXPECT_TRUE(renderer.Initialize());
EXPECT_FALSE(renderer.Capabilities().using_partial_swap);
gfx::Rect viewport_rect(mock_client.DeviceViewportSize());
ScopedPtrVector<RenderPass>& render_passes =
*mock_client.render_passes_in_draw_order();
render_passes.clear();
gfx::Rect grand_child_rect(25, 25);
RenderPass::Id grand_child_pass_id(3, 0);
TestRenderPass* grand_child_pass = AddRenderPass(
&render_passes, grand_child_pass_id, grand_child_rect, gfx::Transform());
AddClippedQuad(grand_child_pass, grand_child_rect, SK_ColorYELLOW);
gfx::Rect child_rect(50, 50);
RenderPass::Id child_pass_id(2, 0);
TestRenderPass* child_pass = AddRenderPass(
&render_passes, child_pass_id, child_rect, gfx::Transform());
AddQuad(child_pass, child_rect, SK_ColorBLUE);
RenderPass::Id root_pass_id(1, 0);
TestRenderPass* root_pass = AddRenderPass(
&render_passes, root_pass_id, viewport_rect, gfx::Transform());
AddQuad(root_pass, viewport_rect, SK_ColorGREEN);
AddRenderPassQuad(root_pass, child_pass);
AddRenderPassQuad(child_pass, grand_child_pass);
renderer.DecideRenderPassAllocationsForFrame(
*mock_client.render_passes_in_draw_order());
renderer.DrawFrame(mock_client.render_passes_in_draw_order());
}
TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
gfx::Rect viewportRect(mock_client_.DeviceViewportSize());
ScopedPtrVector<RenderPass>* renderPasses =
mock_client_.render_passes_in_draw_order();
gfx::Rect grandChildRect(25, 25);
RenderPass::Id grandChildPassId(3, 0);
TestRenderPass* grandChildPass;
gfx::Rect childRect(50, 50);
RenderPass::Id childPassId(2, 0);
TestRenderPass* childPass;
RenderPass::Id rootPassId(1, 0);
TestRenderPass* rootPass;
cc::ResourceProvider::ResourceId mask =
resource_provider_->CreateResource(gfx::Size(20, 12),
resource_provider_->best_texture_format(),
ResourceProvider::TextureUsageAny);
resource_provider_->AllocateForTesting(mask);
SkScalar matrix[20];
float amount = 0.5f;
matrix[0] = 0.213f + 0.787f * amount;
matrix[1] = 0.715f - 0.715f * amount;
matrix[2] = 1.f - (matrix[0] + matrix[1]);
matrix[3] = matrix[4] = 0;
matrix[5] = 0.213f - 0.213f * amount;
matrix[6] = 0.715f + 0.285f * amount;
matrix[7] = 1.f - (matrix[5] + matrix[6]);
matrix[8] = matrix[9] = 0;
matrix[10] = 0.213f - 0.213f * amount;
matrix[11] = 0.715f - 0.715f * amount;
matrix[12] = 1.f - (matrix[10] + matrix[11]);
matrix[13] = matrix[14] = 0;
matrix[15] = matrix[16] = matrix[17] = matrix[19] = 0;
matrix[18] = 1;
skia::RefPtr<SkColorFilter> colorFilter(skia::AdoptRef(
new SkColorMatrixFilter(matrix)));
skia::RefPtr<SkImageFilter> filter =
skia::AdoptRef(SkColorFilterImageFilter::Create(colorFilter.get(), NULL));
gfx::Transform transform_causing_aa;
transform_causing_aa.Rotate(20.0);
// RenderPassProgram
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
gfx::Transform());
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
gfx::Transform());
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, 0, skia::RefPtr<SkImageFilter>(),
gfx::Transform());
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassProgram();
// RenderPassColorMatrixProgram
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
transform_causing_aa);
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
transform_causing_aa);
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, 0, filter, gfx::Transform());
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassColorMatrixProgram();
// RenderPassMaskProgram
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
gfx::Transform());
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
gfx::Transform());
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, mask, skia::RefPtr<SkImageFilter>(),
gfx::Transform());
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassMaskProgram();
// RenderPassMaskColorMatrixProgram
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
gfx::Transform());
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
gfx::Transform());
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, mask, filter, gfx::Transform());
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassMaskColorMatrixProgram();
// RenderPassProgramAA
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
transform_causing_aa);
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
transform_causing_aa);
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, 0, skia::RefPtr<SkImageFilter>(),
transform_causing_aa);
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassProgramAA();
// RenderPassColorMatrixProgramAA
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
transform_causing_aa);
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
transform_causing_aa);
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, 0, filter, transform_causing_aa);
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassColorMatrixProgramAA();
// RenderPassMaskProgramAA
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
transform_causing_aa);
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
transform_causing_aa);
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
gfx::Transform());
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, mask, skia::RefPtr<SkImageFilter>(),
transform_causing_aa);
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassMaskProgramAA();
// RenderPassMaskColorMatrixProgramAA
renderPasses->clear();
grandChildPass = AddRenderPass(renderPasses, grandChildPassId, grandChildRect,
transform_causing_aa);
AddClippedQuad(grandChildPass, grandChildRect, SK_ColorYELLOW);
childPass = AddRenderPass(renderPasses, childPassId, childRect,
transform_causing_aa);
AddQuad(childPass, childRect, SK_ColorBLUE);
rootPass = AddRenderPass(renderPasses, rootPassId, viewportRect,
transform_causing_aa);
AddQuad(rootPass, viewportRect, SK_ColorGREEN);
AddRenderPassQuad(rootPass, childPass, mask, filter, transform_causing_aa);
AddRenderPassQuad(childPass, grandChildPass);
renderer_->DecideRenderPassAllocationsForFrame(
*mock_client_.render_passes_in_draw_order());
renderer_->DrawFrame(mock_client_.render_passes_in_draw_order());
TestRenderPassMaskColorMatrixProgramAA();
}
class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
public:
// Specifically override methods even if they are unused (used in conjunction
// with StrictMock). We need to make sure that GLRenderer does not issue
// framebuffer-related GL calls directly. Instead these are supposed to go
// through the OutputSurface abstraction.
MOCK_METHOD0(ensureBackbufferCHROMIUM, void());
MOCK_METHOD0(discardBackbufferCHROMIUM, void());
MOCK_METHOD2(bindFramebuffer, void(WGC3Denum target, WebGLId framebuffer));
MOCK_METHOD0(prepareTexture, void());
MOCK_METHOD2(reshape, void(int width, int height));
MOCK_METHOD4(drawElements,
void(WGC3Denum mode,
WGC3Dsizei count,
WGC3Denum type,
WGC3Dintptr offset));
virtual WebString getString(WebKit::WGC3Denum name) {
if (name == GL_EXTENSIONS)
return WebString(
"GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_backbuffer");
return WebString();
}
};
class MockOutputSurface : public OutputSurface {
public:
MockOutputSurface()
: OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>(
new StrictMock<OutputSurfaceMockContext>)) {}
virtual ~MockOutputSurface() {}
MOCK_METHOD1(SendFrameToParentCompositor, void(CompositorFrame* frame));
MOCK_METHOD0(EnsureBackbuffer, void());
MOCK_METHOD0(DiscardBackbuffer, void());
MOCK_METHOD1(Reshape, void(gfx::Size size));
MOCK_METHOD0(BindFramebuffer, void());
MOCK_METHOD2(PostSubBuffer, void(gfx::Rect rect, const LatencyInfo&));
MOCK_METHOD1(SwapBuffers, void(const LatencyInfo&));
};
class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
protected:
MockOutputSurfaceTest()
: resource_provider_(ResourceProvider::Create(&output_surface_, 0)),
renderer_(this, &output_surface_, resource_provider_.get()) {}
virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); }
void SwapBuffers() { renderer_.SwapBuffers(); }
void DrawFrame() {
gfx::Rect viewport_rect(DeviceViewportSize());
ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order();
render_passes->clear();
RenderPass::Id render_pass_id(1, 0);
TestRenderPass* render_pass = AddRenderPass(
render_passes, render_pass_id, viewport_rect, gfx::Transform());
AddQuad(render_pass, viewport_rect, SK_ColorGREEN);
EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return());
EXPECT_CALL(output_surface_, Reshape(_)).Times(1);
EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1);
EXPECT_CALL(*context(), drawElements(_, _, _, _)).Times(1);
renderer_.DecideRenderPassAllocationsForFrame(
*render_passes_in_draw_order());
renderer_.DrawFrame(render_passes_in_draw_order());
}
OutputSurfaceMockContext* context() {
return static_cast<OutputSurfaceMockContext*>(output_surface_.context3d());
}
StrictMock<MockOutputSurface> output_surface_;
scoped_ptr<ResourceProvider> resource_provider_;
FakeRendererGL renderer_;
};
TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) {
DrawFrame();
EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
renderer_.SwapBuffers();
}
class MockOutputSurfaceTestWithPartialSwap : public MockOutputSurfaceTest {
public:
virtual const LayerTreeSettings& Settings() const OVERRIDE {
static LayerTreeSettings fake_settings;
fake_settings.partial_swap_enabled = true;
return fake_settings;
}
};
TEST_F(MockOutputSurfaceTestWithPartialSwap, DrawFrameAndSwap) {
DrawFrame();
EXPECT_CALL(output_surface_, PostSubBuffer(_, _)).Times(1);
renderer_.SwapBuffers();
}
class MockOutputSurfaceTestWithSendCompositorFrame
: public MockOutputSurfaceTest {
public:
virtual const LayerTreeSettings& Settings() const OVERRIDE {
static LayerTreeSettings fake_settings;
fake_settings.compositor_frame_message = true;
return fake_settings;
}
};
TEST_F(MockOutputSurfaceTestWithSendCompositorFrame, DrawFrame) {
EXPECT_CALL(output_surface_, SendFrameToParentCompositor(_)).Times(1);
DrawFrame();
}
} // namespace
} // namespace cc
|