michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "TestBugs.h" michael@0: #include "2D.h" michael@0: #include michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::gfx; michael@0: michael@0: TestBugs::TestBugs() michael@0: { michael@0: REGISTER_TEST(TestBugs, CairoClip918671); michael@0: REGISTER_TEST(TestBugs, PushPopClip950550); michael@0: } michael@0: michael@0: void michael@0: TestBugs::CairoClip918671() michael@0: { michael@0: RefPtr dt = Factory::CreateDrawTarget(BackendType::CAIRO, michael@0: IntSize(100, 100), michael@0: SurfaceFormat::B8G8R8A8); michael@0: RefPtr ref = Factory::CreateDrawTarget(BackendType::CAIRO, michael@0: IntSize(100, 100), michael@0: SurfaceFormat::B8G8R8A8); michael@0: // Create a path that extends around the center rect but doesn't intersect it. michael@0: RefPtr pb1 = dt->CreatePathBuilder(); michael@0: pb1->MoveTo(Point(10, 10)); michael@0: pb1->LineTo(Point(90, 10)); michael@0: pb1->LineTo(Point(90, 20)); michael@0: pb1->LineTo(Point(10, 20)); michael@0: pb1->Close(); michael@0: pb1->MoveTo(Point(90, 90)); michael@0: pb1->LineTo(Point(91, 90)); michael@0: pb1->LineTo(Point(91, 91)); michael@0: pb1->LineTo(Point(91, 90)); michael@0: pb1->Close(); michael@0: michael@0: RefPtr path1 = pb1->Finish(); michael@0: dt->PushClip(path1); michael@0: michael@0: // This center rect must NOT be rectilinear! michael@0: RefPtr pb2 = dt->CreatePathBuilder(); michael@0: pb2->MoveTo(Point(50, 50)); michael@0: pb2->LineTo(Point(55, 51)); michael@0: pb2->LineTo(Point(54, 55)); michael@0: pb2->LineTo(Point(50, 56)); michael@0: pb2->Close(); michael@0: michael@0: RefPtr path2 = pb2->Finish(); michael@0: dt->PushClip(path2); michael@0: michael@0: dt->FillRect(Rect(0, 0, 100, 100), ColorPattern(Color(1,0,0))); michael@0: michael@0: RefPtr surf1 = dt->Snapshot(); michael@0: RefPtr surf2 = ref->Snapshot(); michael@0: michael@0: RefPtr dataSurf1 = surf1->GetDataSurface(); michael@0: RefPtr dataSurf2 = surf2->GetDataSurface(); michael@0: michael@0: for (int y = 0; y < dt->GetSize().height; y++) { michael@0: VERIFY(memcmp(dataSurf1->GetData() + y * dataSurf1->Stride(), michael@0: dataSurf2->GetData() + y * dataSurf2->Stride(), michael@0: dataSurf1->GetSize().width * 4) == 0); michael@0: } michael@0: michael@0: } michael@0: michael@0: void michael@0: TestBugs::PushPopClip950550() michael@0: { michael@0: RefPtr dt = Factory::CreateDrawTarget(BackendType::CAIRO, michael@0: IntSize(500, 500), michael@0: SurfaceFormat::B8G8R8A8); michael@0: dt->PushClipRect(Rect(0, 0, 100, 100)); michael@0: Matrix m(1, 0, 0, 1, 45, -100); michael@0: dt->SetTransform(m); michael@0: dt->PopClip(); michael@0: michael@0: // We fail the test if we assert in this call because our draw target's michael@0: // transforms are out of sync. michael@0: dt->FillRect(Rect(50, 50, 50, 50), ColorPattern(Color(0.5f, 0, 0, 1.0f))); michael@0: } michael@0: