xref: /aosp_15_r20/external/skia/gm/luminosity.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "gm/gm.h"
9 #include "include/core/SkBlendMode.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkColor.h"
12 #include "include/core/SkPaint.h"
13 #include "include/core/SkRect.h"
14 
15 DEF_SIMPLE_GM(luminosity_overflow, canvas, 256, 256) {
16     // As reported in b/359049360:
17     // The luminosity blend mode includes a division that can behave badly (black results) when
18     // drawing low-alpha content over bright backgrounds. This GM reproduced the effect on several
19     // GPUs. Proper rendering should be various near-white colors, with no black boxes.
20     constexpr int kRGBs[] = {243, 247, 251, 255};
21     canvas->save();
22     for (int r : kRGBs) {
23         for (int g : kRGBs) {
24             for (int b : kRGBs) {
25                 SkPaint p;
26                 p.setColor(SkColorSetARGB(255, r, g, b));
27                 canvas->drawRect(SkRect::MakeWH(4, 256), p);
28                 canvas->translate(4, 0);
29             }
30         }
31     }
32     canvas->restore();
33 
34     for (int a = 1; a <= 16; ++a) {
35         SkPaint p;
36         p.setColor(SkColorSetARGB(a, 255, 255, 255));
37         p.setBlendMode(SkBlendMode::kLuminosity);
38         canvas->drawRect(SkRect::MakeWH(256, 16), p);
39         canvas->translate(0, 16);
40     }
41 }
42