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