aboutsummaryrefslogtreecommitdiff
path: root/src/libANGLE/angletypes_unittest.cpp
blob: 27e5ea94763368b134028edc3ee47d3c3615248f (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
//
// Copyright 2020 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//

// angletypes_unittest.cpp: Unit tests of the BlendStateExt class.

#include <gtest/gtest.h>

#include "libANGLE/angletypes.h"

namespace angle
{

#if defined(ANGLE_IS_64_BIT_CPU)
constexpr bool is64Bit = true;
#else
constexpr bool is64Bit = false;
#endif

void checkInitState(const gl::BlendStateExt &blendStateExt)
{
    for (size_t i = 0; i < blendStateExt.mMaxDrawBuffers; ++i)
    {
        ASSERT_FALSE(blendStateExt.mEnabledMask.test(i));

        bool r, g, b, a;
        blendStateExt.getColorMaskIndexed(i, &r, &g, &b, &a);
        ASSERT_TRUE(r);
        ASSERT_TRUE(g);
        ASSERT_TRUE(b);
        ASSERT_TRUE(a);

        ASSERT_EQ(blendStateExt.getEquationColorIndexed(i), static_cast<GLenum>(GL_FUNC_ADD));
        ASSERT_EQ(blendStateExt.getEquationAlphaIndexed(i), static_cast<GLenum>(GL_FUNC_ADD));

        ASSERT_EQ(blendStateExt.getSrcColorIndexed(i), static_cast<GLenum>(GL_ONE));
        ASSERT_EQ(blendStateExt.getDstColorIndexed(i), static_cast<GLenum>(GL_ZERO));
        ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(i), static_cast<GLenum>(GL_ONE));
        ASSERT_EQ(blendStateExt.getDstAlphaIndexed(i), static_cast<GLenum>(GL_ZERO));
    }
}

// Test the initial state of BlendStateExt
TEST(BlendStateExt, Init)
{
    {
        const gl::BlendStateExt blendStateExt = gl::BlendStateExt(1);
        ASSERT_EQ(blendStateExt.mMaxDrawBuffers, 1u);
        ASSERT_EQ(blendStateExt.mMaxEnabledMask.to_ulong(), 1u);
        ASSERT_EQ(blendStateExt.mAllColorMask, 0xFu);
        ASSERT_EQ(blendStateExt.mMaxEquationMask, 0xFFu);
        ASSERT_EQ(blendStateExt.mMaxFactorMask, 0xFFu);
        checkInitState(blendStateExt);
    }

    {
        const gl::BlendStateExt blendStateExt = gl::BlendStateExt(4);
        ASSERT_EQ(blendStateExt.mMaxDrawBuffers, 4u);
        ASSERT_EQ(blendStateExt.mMaxEnabledMask.to_ulong(), 0xFu);
        ASSERT_EQ(blendStateExt.mAllColorMask, is64Bit ? 0x0F0F0F0Fu : 0xFFFFu);
        ASSERT_EQ(blendStateExt.mMaxEquationMask, 0xFFFFFFFFu);
        ASSERT_EQ(blendStateExt.mMaxFactorMask, 0xFFFFFFFFu);
        checkInitState(blendStateExt);
    }

    {
        const gl::BlendStateExt blendStateExt = gl::BlendStateExt(8);
        ASSERT_EQ(blendStateExt.mMaxDrawBuffers, 8u);
        ASSERT_EQ(blendStateExt.mMaxEnabledMask.to_ulong(), 0xFFu);
        ASSERT_EQ(blendStateExt.mAllColorMask, is64Bit ? 0x0F0F0F0F0F0F0F0Fu : 0xFFFFFFFFu);
        ASSERT_EQ(blendStateExt.mMaxEquationMask, 0xFFFFFFFFFFFFFFFFu);
        ASSERT_EQ(blendStateExt.mMaxFactorMask, 0xFFFFFFFFFFFFFFFFu);
        checkInitState(blendStateExt);
    }
}

// Test blend enabled flags
TEST(BlendStateExt, BlendEnabled)
{
    gl::BlendStateExt blendStateExt = gl::BlendStateExt(3);

    blendStateExt.setEnabled(true);
    ASSERT_EQ(blendStateExt.mEnabledMask.to_ulong(), 7u);

    blendStateExt.setEnabledIndexed(1, false);
    ASSERT_EQ(blendStateExt.mEnabledMask.to_ulong(), 5u);
}

// Test color write mask manipulations
TEST(BlendStateExt, ColorMask)
{
    gl::BlendStateExt blendStateExt = gl::BlendStateExt(5);

    blendStateExt.setColorMask(true, false, true, false);
    ASSERT_EQ(blendStateExt.mColorMask, is64Bit ? 0x0505050505u : 0x55555u);

    blendStateExt.setColorMaskIndexed(3, false, true, false, true);
    ASSERT_EQ(blendStateExt.mColorMask, is64Bit ? 0x050A050505u : 0x5A555u);

    blendStateExt.setColorMaskIndexed(3, 0xF);
    ASSERT_EQ(blendStateExt.getColorMaskIndexed(3), 0xF);

    blendStateExt.setColorMaskIndexed(3, 0xA);
    ASSERT_EQ(blendStateExt.getColorMaskIndexed(3), 0xA);

    bool r, g, b, a;
    blendStateExt.getColorMaskIndexed(3, &r, &g, &b, &a);
    ASSERT_FALSE(r);
    ASSERT_TRUE(g);
    ASSERT_FALSE(b);
    ASSERT_TRUE(a);

    gl::BlendStateExt::ColorMaskStorage::Type otherColorMask =
        blendStateExt.expandColorMaskIndexed(3);
    ASSERT_EQ(otherColorMask, is64Bit ? 0x0A0A0A0A0Au : 0xAAAAAu);

    const gl::DrawBufferMask diff = blendStateExt.compareColorMask(otherColorMask);
    ASSERT_EQ(diff.to_ulong(), 23u);
}

// Test that all-enabled color mask correctly compares with the current color mask
TEST(BlendStateExt, MaxColorMask)
{
    gl::BlendStateExt blendStateExt = gl::BlendStateExt(4);

    blendStateExt.setColorMaskIndexed(2, true, false, true, false);

    const gl::DrawBufferMask diff = blendStateExt.compareColorMask(blendStateExt.mAllColorMask);
    ASSERT_EQ(diff.to_ulong(), 4u);
}

// Test blend equations manipulations
TEST(BlendStateExt, BlendEquations)
{
    gl::BlendStateExt blendStateExt = gl::BlendStateExt(7);

    blendStateExt.setEquations(GL_MIN, GL_FUNC_SUBTRACT);
    ASSERT_EQ(blendStateExt.mEquationColor, 0x01010101010101u);
    ASSERT_EQ(blendStateExt.mEquationAlpha, 0x04040404040404u);

    blendStateExt.setEquationsIndexed(3, GL_MAX, GL_FUNC_SUBTRACT);
    blendStateExt.setEquationsIndexed(5, GL_MIN, GL_FUNC_ADD);
    ASSERT_EQ(blendStateExt.mEquationColor, 0x01010102010101u);
    ASSERT_EQ(blendStateExt.mEquationAlpha, 0x04000404040404u);
    ASSERT_EQ(blendStateExt.getEquationColorIndexed(3), static_cast<GLenum>(GL_MAX));
    ASSERT_EQ(blendStateExt.getEquationAlphaIndexed(5), static_cast<GLenum>(GL_FUNC_ADD));

    gl::BlendStateExt::EquationStorage::Type otherEquationColor =
        blendStateExt.expandEquationColorIndexed(0);
    gl::BlendStateExt::EquationStorage::Type otherEquationAlpha =
        blendStateExt.expandEquationAlphaIndexed(0);

    ASSERT_EQ(otherEquationColor, 0x01010101010101u);
    ASSERT_EQ(otherEquationAlpha, 0x04040404040404u);

    const gl::DrawBufferMask diff =
        blendStateExt.compareEquations(otherEquationColor, otherEquationAlpha);
    ASSERT_EQ(diff.to_ulong(), 40u);

    // Copy buffer 3 to buffer 0
    blendStateExt.setEquationsIndexed(0, 3, blendStateExt);
    ASSERT_EQ(blendStateExt.getEquationColorIndexed(0), static_cast<GLenum>(GL_MAX));
    ASSERT_EQ(blendStateExt.getEquationAlphaIndexed(0), static_cast<GLenum>(GL_FUNC_SUBTRACT));

    // Copy buffer 5 to buffer 0
    blendStateExt.setEquationsIndexed(0, 5, blendStateExt);
    ASSERT_EQ(blendStateExt.getEquationColorIndexed(0), static_cast<GLenum>(GL_MIN));
    ASSERT_EQ(blendStateExt.getEquationAlphaIndexed(0), static_cast<GLenum>(GL_FUNC_ADD));
}

// Test blend factors manipulations
TEST(BlendStateExt, BlendFactors)
{
    gl::BlendStateExt blendStateExt = gl::BlendStateExt(8);

    blendStateExt.setFactors(GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_DST_ALPHA);
    ASSERT_EQ(blendStateExt.mSrcColor, 0x0202020202020202u);
    ASSERT_EQ(blendStateExt.mDstColor, 0x0808080808080808u);
    ASSERT_EQ(blendStateExt.mSrcAlpha, 0x0404040404040404u);
    ASSERT_EQ(blendStateExt.mDstAlpha, 0x0606060606060606u);

    blendStateExt.setFactorsIndexed(0, GL_ONE, GL_DST_COLOR, GL_SRC_ALPHA, GL_DST_ALPHA);
    blendStateExt.setFactorsIndexed(3, GL_SRC_COLOR, GL_ONE, GL_SRC_ALPHA, GL_DST_ALPHA);
    blendStateExt.setFactorsIndexed(5, GL_SRC_COLOR, GL_DST_COLOR, GL_ONE, GL_DST_ALPHA);
    blendStateExt.setFactorsIndexed(7, GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE);
    ASSERT_EQ(blendStateExt.mSrcColor, 0x0202020202020201u);
    ASSERT_EQ(blendStateExt.mDstColor, 0x0808080801080808u);
    ASSERT_EQ(blendStateExt.mSrcAlpha, 0x0404010404040404u);
    ASSERT_EQ(blendStateExt.mDstAlpha, 0x0106060606060606u);

    ASSERT_EQ(blendStateExt.getSrcColorIndexed(0), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getDstColorIndexed(3), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(5), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getDstAlphaIndexed(7), static_cast<GLenum>(GL_ONE));

    gl::BlendStateExt::FactorStorage::Type otherSrcColor = blendStateExt.expandSrcColorIndexed(1);
    gl::BlendStateExt::FactorStorage::Type otherDstColor = blendStateExt.expandDstColorIndexed(1);
    gl::BlendStateExt::FactorStorage::Type otherSrcAlpha = blendStateExt.expandSrcAlphaIndexed(1);
    gl::BlendStateExt::FactorStorage::Type otherDstAlpha = blendStateExt.expandDstAlphaIndexed(1);

    ASSERT_EQ(otherSrcColor, 0x0202020202020202u);
    ASSERT_EQ(otherDstColor, 0x0808080808080808u);
    ASSERT_EQ(otherSrcAlpha, 0x0404040404040404u);
    ASSERT_EQ(otherDstAlpha, 0x0606060606060606u);

    const gl::DrawBufferMask diff =
        blendStateExt.compareFactors(otherSrcColor, otherDstColor, otherSrcAlpha, otherDstAlpha);
    ASSERT_EQ(diff.to_ulong(), 169u);

    // Copy buffer 0 to buffer 1
    blendStateExt.setFactorsIndexed(1, 0, blendStateExt);
    ASSERT_EQ(blendStateExt.getSrcColorIndexed(1), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getDstColorIndexed(1), static_cast<GLenum>(GL_DST_COLOR));
    ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(1), static_cast<GLenum>(GL_SRC_ALPHA));
    ASSERT_EQ(blendStateExt.getDstAlphaIndexed(1), static_cast<GLenum>(GL_DST_ALPHA));

    // Copy buffer 3 to buffer 1
    blendStateExt.setFactorsIndexed(1, 3, blendStateExt);
    ASSERT_EQ(blendStateExt.getSrcColorIndexed(1), static_cast<GLenum>(GL_SRC_COLOR));
    ASSERT_EQ(blendStateExt.getDstColorIndexed(1), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(1), static_cast<GLenum>(GL_SRC_ALPHA));
    ASSERT_EQ(blendStateExt.getDstAlphaIndexed(1), static_cast<GLenum>(GL_DST_ALPHA));

    // Copy buffer 5 to buffer 1
    blendStateExt.setFactorsIndexed(1, 5, blendStateExt);
    ASSERT_EQ(blendStateExt.getSrcColorIndexed(1), static_cast<GLenum>(GL_SRC_COLOR));
    ASSERT_EQ(blendStateExt.getDstColorIndexed(1), static_cast<GLenum>(GL_DST_COLOR));
    ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(1), static_cast<GLenum>(GL_ONE));
    ASSERT_EQ(blendStateExt.getDstAlphaIndexed(1), static_cast<GLenum>(GL_DST_ALPHA));

    // Copy buffer 7 to buffer 1
    blendStateExt.setFactorsIndexed(1, 7, blendStateExt);
    ASSERT_EQ(blendStateExt.getSrcColorIndexed(1), static_cast<GLenum>(GL_SRC_COLOR));
    ASSERT_EQ(blendStateExt.getDstColorIndexed(1), static_cast<GLenum>(GL_DST_COLOR));
    ASSERT_EQ(blendStateExt.getSrcAlphaIndexed(1), static_cast<GLenum>(GL_SRC_ALPHA));
    ASSERT_EQ(blendStateExt.getDstAlphaIndexed(1), static_cast<GLenum>(GL_ONE));
}

// Test clip rectangle
TEST(Rectangle, Clip)
{
    const gl::Rectangle source(0, 0, 100, 200);
    const gl::Rectangle clip1(0, 0, 50, 100);
    gl::Rectangle result;

    ASSERT_TRUE(gl::ClipRectangle(source, clip1, &result));
    ASSERT_EQ(result.x, 0);
    ASSERT_EQ(result.y, 0);
    ASSERT_EQ(result.width, 50);
    ASSERT_EQ(result.height, 100);

    gl::Rectangle clip2(10, 20, 30, 40);

    ASSERT_TRUE(gl::ClipRectangle(source, clip2, &result));
    ASSERT_EQ(result.x, 10);
    ASSERT_EQ(result.y, 20);
    ASSERT_EQ(result.width, 30);
    ASSERT_EQ(result.height, 40);

    gl::Rectangle clip3(-20, -30, 10000, 400000);

    ASSERT_TRUE(gl::ClipRectangle(source, clip3, &result));
    ASSERT_EQ(result.x, 0);
    ASSERT_EQ(result.y, 0);
    ASSERT_EQ(result.width, 100);
    ASSERT_EQ(result.height, 200);

    gl::Rectangle clip4(50, 100, -20, -30);

    ASSERT_TRUE(gl::ClipRectangle(source, clip4, &result));
    ASSERT_EQ(result.x, 30);
    ASSERT_EQ(result.y, 70);
    ASSERT_EQ(result.width, 20);
    ASSERT_EQ(result.height, 30);

    // Non-overlapping rectangles
    gl::Rectangle clip5(-100, 0, 99, 200);
    ASSERT_FALSE(gl::ClipRectangle(source, clip5, nullptr));

    gl::Rectangle clip6(0, -100, 100, 99);
    ASSERT_FALSE(gl::ClipRectangle(source, clip6, nullptr));

    gl::Rectangle clip7(101, 0, 99, 200);
    ASSERT_FALSE(gl::ClipRectangle(source, clip7, nullptr));

    gl::Rectangle clip8(0, 201, 100, 99);
    ASSERT_FALSE(gl::ClipRectangle(source, clip8, nullptr));

    // Zero-width/height rectangles
    gl::Rectangle clip9(50, 0, 0, 200);
    ASSERT_FALSE(gl::ClipRectangle(source, clip9, nullptr));
    ASSERT_FALSE(gl::ClipRectangle(clip9, source, nullptr));

    gl::Rectangle clip10(0, 100, 100, 0);
    ASSERT_FALSE(gl::ClipRectangle(source, clip10, nullptr));
    ASSERT_FALSE(gl::ClipRectangle(clip10, source, nullptr));
}

// Test combine rectangles
TEST(Rectangle, Combine)
{
    const gl::Rectangle rect1(0, 0, 100, 200);
    const gl::Rectangle rect2(0, 0, 50, 100);
    gl::Rectangle result;

    gl::GetEnclosingRectangle(rect1, rect2, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    const gl::Rectangle rect3(50, 100, 100, 200);

    gl::GetEnclosingRectangle(rect1, rect3, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 150);
    ASSERT_EQ(result.y1(), 300);

    const gl::Rectangle rect4(-20, -30, 100, 200);

    gl::GetEnclosingRectangle(rect1, rect4, &result);
    ASSERT_EQ(result.x0(), -20);
    ASSERT_EQ(result.y0(), -30);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    const gl::Rectangle rect5(10, -30, 100, 200);

    gl::GetEnclosingRectangle(rect1, rect5, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), -30);
    ASSERT_EQ(result.x1(), 110);
    ASSERT_EQ(result.y1(), 200);
}

// Test extend rectangles
TEST(Rectangle, Extend)
{
    const gl::Rectangle source(0, 0, 100, 200);
    const gl::Rectangle extend1(0, 0, 50, 100);
    gl::Rectangle result;

    //  +------+       +------+
    //  |   |  |       |      |
    //  +---+  |  -->  |      |
    //  |      |       |      |
    //  +------+       +------+
    //
    gl::ExtendRectangle(source, extend1, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    //  +------+           +------+
    //  |S     |           |      |
    //  |   +--+---+  -->  |      |
    //  |   |  |   |       |      |
    //  +---+--+   +       +------+
    //      |      |
    //      +------+
    //
    const gl::Rectangle extend2(50, 100, 100, 200);

    gl::ExtendRectangle(source, extend2, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    //    +------+           +------+
    //    |S     |           |      |
    //  +-+------+---+  -->  |      |
    //  | |      |   |       |      |
    //  | +------+   +       |      |
    //  |            |       |      |
    //  +------------+       +------+
    //
    const gl::Rectangle extend3(-10, 100, 200, 200);

    gl::ExtendRectangle(source, extend3, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 300);

    //    +------+           +------+
    //    |S     |           |      |
    //    |      |      -->  |      |
    //    |      |           |      |
    //  +-+------+---+       |      |
    //  |            |       |      |
    //  +------------+       +------+
    //
    for (int offsetLeft = 10; offsetLeft >= 0; offsetLeft -= 10)
    {
        for (int offsetRight = 10; offsetRight >= 0; offsetRight -= 10)
        {
            const gl::Rectangle extend4(-offsetLeft, 200, 100 + offsetLeft + offsetRight, 100);

            gl::ExtendRectangle(source, extend4, &result);
            ASSERT_EQ(result.x0(), 0) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.y0(), 0) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.x1(), 100) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.y1(), 300) << offsetLeft << " " << offsetRight;
        }
    }

    // Similar to extend4, but with the second rectangle on the top, left and right.
    for (int offsetLeft = 10; offsetLeft >= 0; offsetLeft -= 10)
    {
        for (int offsetRight = 10; offsetRight >= 0; offsetRight -= 10)
        {
            const gl::Rectangle extend4(-offsetLeft, -100, 100 + offsetLeft + offsetRight, 100);

            gl::ExtendRectangle(source, extend4, &result);
            ASSERT_EQ(result.x0(), 0) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.y0(), -100) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.x1(), 100) << offsetLeft << " " << offsetRight;
            ASSERT_EQ(result.y1(), 200) << offsetLeft << " " << offsetRight;
        }
    }
    for (int offsetTop = 10; offsetTop >= 0; offsetTop -= 10)
    {
        for (int offsetBottom = 10; offsetBottom >= 0; offsetBottom -= 10)
        {
            const gl::Rectangle extend4(-50, -offsetTop, 50, 200 + offsetTop + offsetBottom);

            gl::ExtendRectangle(source, extend4, &result);
            ASSERT_EQ(result.x0(), -50) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.y0(), 0) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.x1(), 100) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.y1(), 200) << offsetTop << " " << offsetBottom;
        }
    }
    for (int offsetTop = 10; offsetTop >= 0; offsetTop -= 10)
    {
        for (int offsetBottom = 10; offsetBottom >= 0; offsetBottom -= 10)
        {
            const gl::Rectangle extend4(100, -offsetTop, 50, 200 + offsetTop + offsetBottom);

            gl::ExtendRectangle(source, extend4, &result);
            ASSERT_EQ(result.x0(), 0) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.y0(), 0) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.x1(), 150) << offsetTop << " " << offsetBottom;
            ASSERT_EQ(result.y1(), 200) << offsetTop << " " << offsetBottom;
        }
    }

    //    +------+           +------+
    //    |S     |           |      |
    //    |      |      -->  |      |
    //    |      |           |      |
    //    +------+           +------+
    //  +------------+
    //  |            |
    //  +------------+
    //
    const gl::Rectangle extend5(-10, 201, 120, 100);

    gl::ExtendRectangle(source, extend5, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    // Similar to extend5, but with the second rectangle on the top, left and right.
    const gl::Rectangle extend6(-10, -101, 120, 100);

    gl::ExtendRectangle(source, extend6, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    const gl::Rectangle extend7(-101, -10, 100, 220);

    gl::ExtendRectangle(source, extend7, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    const gl::Rectangle extend8(101, -10, 100, 220);

    gl::ExtendRectangle(source, extend8, &result);
    ASSERT_EQ(result.x0(), 0);
    ASSERT_EQ(result.y0(), 0);
    ASSERT_EQ(result.x1(), 100);
    ASSERT_EQ(result.y1(), 200);

    //  +-------------+       +-------------+
    //  |   +------+  |       |             |
    //  |   |S     |  |       |             |
    //  |   |      |  |  -->  |             |
    //  |   |      |  |       |             |
    //  |   +------+  |       |             |
    //  +-------------+       +-------------+
    //
    const gl::Rectangle extend9(-100, -100, 300, 400);

    gl::ExtendRectangle(source, extend9, &result);
    ASSERT_EQ(result.x0(), -100);
    ASSERT_EQ(result.y0(), -100);
    ASSERT_EQ(result.x1(), 200);
    ASSERT_EQ(result.y1(), 300);
}

}  // namespace angle