| 1 |
/* |
| 2 |
* Copyright 2023 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/SkCanvas.h" |
| 10 |
#include "include/core/SkPaint.h" |
| 11 |
#include "include/core/SkRect.h" |
| 12 |
#include "include/core/SkString.h" |
| 13 |
|
| 14 |
namespace skiagm { |
| 15 |
|
| 16 |
// From crbug.com/1442854. Draws two rects (equivalent in device space) but which vary wildly |
| 17 |
// in their sizes and scales. In both cases the clip is what is actually determining the |
| 18 |
// final drawn geometry. For the red rectangle case the inverted skews were becoming very small and |
| 19 |
// ran afoul of some logic in the DMSAA code that zeroed them out. |
| 20 |
class ScaledRectsGM : public GM { |
| 21 |
public: |
| 22 |
ScaledRectsGM() { |
| 23 |
this->setBGColor(0xFFCCCCCC); |
| 24 |
} |
| 25 |
|
| 26 |
protected: |
| 27 |
SkString getName() const override { return SkString("scaledrects"); } |
| 28 |
|
| 29 |
SkISize getISize() override { return SkISize::Make(128, 64); } |
| 30 |
|
| 31 |
void onDraw(SkCanvas* canvas) override { |
| 32 |
canvas->clipRect(SkRect::MakeXYWH(10, 50, 100, 10)); |
| 33 |
|
| 34 |
{ |
| 35 |
SkPaint blue; |
| 36 |
blue.setColor(SK_ColorBLUE); |
| 37 |
|
| 38 |
canvas->setMatrix(SkMatrix::MakeAll( 3.0f, -0.5f, 0.0f, |
| 39 |
-0.5f, -3.0f, 0.0f, |
| 40 |
0.0f, 0.0f, 1.0f)); |
| 41 |
|
| 42 |
canvas->drawRect(SkRect::MakeXYWH(-1000, -1000, 2000, 2000), blue); |
| 43 |
} |
| 44 |
|
| 45 |
{ |
| 46 |
SkPaint red; |
| 47 |
red.setColor(SK_ColorRED); |
| 48 |
red.setBlendMode(SkBlendMode::kPlus); |
| 49 |
|
| 50 |
canvas->setMatrix(SkMatrix::MakeAll(3000.0f, -500.0f, 0.0f, |
| 51 |
-500.0f, -3000.0f, 0.0f, |
| 52 |
0.0f, 0.0f, 1.0f)); |
| 53 |
|
| 54 |
canvas->drawRect(SkRect::MakeXYWH(-1, -1, 2, 2), red); |
| 55 |
} |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
////////////////////////////////////////////////////////////////////////////// |
| 60 |
|
| 61 |
DEF_GM(return new ScaledRectsGM;) |
| 62 |
|
| 63 |
DEF_SIMPLE_GM(cliplargerect, canvas, 256, 256) { |
| 64 |
canvas->save(); |
| 65 |
canvas->clipIRect({0, 0, 120, 256}); |
| 66 |
canvas->save(); |
| 67 |
canvas->translate(1e24f, 0.f); |
| 68 |
canvas->clear(SK_ColorGREEN); |
| 69 |
canvas->restore(); |
| 70 |
canvas->restore(); |
| 71 |
|
| 72 |
SkPaint line; |
| 73 |
line.setStyle(SkPaint::kStroke_Style); |
| 74 |
line.setColor(SK_ColorBLACK); |
| 75 |
canvas->drawLine(120.f, 0.f, 120.f, 256.f, line); |
| 76 |
} |
| 77 |
|
| 78 |
} // namespace skiagm |