gfx/2d/unittest/TestBugs.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:1035deb57b0d
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "TestBugs.h"
7 #include "2D.h"
8 #include <string.h>
9
10 using namespace mozilla;
11 using namespace mozilla::gfx;
12
13 TestBugs::TestBugs()
14 {
15 REGISTER_TEST(TestBugs, CairoClip918671);
16 REGISTER_TEST(TestBugs, PushPopClip950550);
17 }
18
19 void
20 TestBugs::CairoClip918671()
21 {
22 RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO,
23 IntSize(100, 100),
24 SurfaceFormat::B8G8R8A8);
25 RefPtr<DrawTarget> ref = Factory::CreateDrawTarget(BackendType::CAIRO,
26 IntSize(100, 100),
27 SurfaceFormat::B8G8R8A8);
28 // Create a path that extends around the center rect but doesn't intersect it.
29 RefPtr<PathBuilder> pb1 = dt->CreatePathBuilder();
30 pb1->MoveTo(Point(10, 10));
31 pb1->LineTo(Point(90, 10));
32 pb1->LineTo(Point(90, 20));
33 pb1->LineTo(Point(10, 20));
34 pb1->Close();
35 pb1->MoveTo(Point(90, 90));
36 pb1->LineTo(Point(91, 90));
37 pb1->LineTo(Point(91, 91));
38 pb1->LineTo(Point(91, 90));
39 pb1->Close();
40
41 RefPtr<Path> path1 = pb1->Finish();
42 dt->PushClip(path1);
43
44 // This center rect must NOT be rectilinear!
45 RefPtr<PathBuilder> pb2 = dt->CreatePathBuilder();
46 pb2->MoveTo(Point(50, 50));
47 pb2->LineTo(Point(55, 51));
48 pb2->LineTo(Point(54, 55));
49 pb2->LineTo(Point(50, 56));
50 pb2->Close();
51
52 RefPtr<Path> path2 = pb2->Finish();
53 dt->PushClip(path2);
54
55 dt->FillRect(Rect(0, 0, 100, 100), ColorPattern(Color(1,0,0)));
56
57 RefPtr<SourceSurface> surf1 = dt->Snapshot();
58 RefPtr<SourceSurface> surf2 = ref->Snapshot();
59
60 RefPtr<DataSourceSurface> dataSurf1 = surf1->GetDataSurface();
61 RefPtr<DataSourceSurface> dataSurf2 = surf2->GetDataSurface();
62
63 for (int y = 0; y < dt->GetSize().height; y++) {
64 VERIFY(memcmp(dataSurf1->GetData() + y * dataSurf1->Stride(),
65 dataSurf2->GetData() + y * dataSurf2->Stride(),
66 dataSurf1->GetSize().width * 4) == 0);
67 }
68
69 }
70
71 void
72 TestBugs::PushPopClip950550()
73 {
74 RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO,
75 IntSize(500, 500),
76 SurfaceFormat::B8G8R8A8);
77 dt->PushClipRect(Rect(0, 0, 100, 100));
78 Matrix m(1, 0, 0, 1, 45, -100);
79 dt->SetTransform(m);
80 dt->PopClip();
81
82 // We fail the test if we assert in this call because our draw target's
83 // transforms are out of sync.
84 dt->FillRect(Rect(50, 50, 50, 50), ColorPattern(Color(0.5f, 0, 0, 1.0f)));
85 }
86

mercurial