1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/unittest/TestBugs.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,86 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "TestBugs.h" 1.10 +#include "2D.h" 1.11 +#include <string.h> 1.12 + 1.13 +using namespace mozilla; 1.14 +using namespace mozilla::gfx; 1.15 + 1.16 +TestBugs::TestBugs() 1.17 +{ 1.18 + REGISTER_TEST(TestBugs, CairoClip918671); 1.19 + REGISTER_TEST(TestBugs, PushPopClip950550); 1.20 +} 1.21 + 1.22 +void 1.23 +TestBugs::CairoClip918671() 1.24 +{ 1.25 + RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO, 1.26 + IntSize(100, 100), 1.27 + SurfaceFormat::B8G8R8A8); 1.28 + RefPtr<DrawTarget> ref = Factory::CreateDrawTarget(BackendType::CAIRO, 1.29 + IntSize(100, 100), 1.30 + SurfaceFormat::B8G8R8A8); 1.31 + // Create a path that extends around the center rect but doesn't intersect it. 1.32 + RefPtr<PathBuilder> pb1 = dt->CreatePathBuilder(); 1.33 + pb1->MoveTo(Point(10, 10)); 1.34 + pb1->LineTo(Point(90, 10)); 1.35 + pb1->LineTo(Point(90, 20)); 1.36 + pb1->LineTo(Point(10, 20)); 1.37 + pb1->Close(); 1.38 + pb1->MoveTo(Point(90, 90)); 1.39 + pb1->LineTo(Point(91, 90)); 1.40 + pb1->LineTo(Point(91, 91)); 1.41 + pb1->LineTo(Point(91, 90)); 1.42 + pb1->Close(); 1.43 + 1.44 + RefPtr<Path> path1 = pb1->Finish(); 1.45 + dt->PushClip(path1); 1.46 + 1.47 + // This center rect must NOT be rectilinear! 1.48 + RefPtr<PathBuilder> pb2 = dt->CreatePathBuilder(); 1.49 + pb2->MoveTo(Point(50, 50)); 1.50 + pb2->LineTo(Point(55, 51)); 1.51 + pb2->LineTo(Point(54, 55)); 1.52 + pb2->LineTo(Point(50, 56)); 1.53 + pb2->Close(); 1.54 + 1.55 + RefPtr<Path> path2 = pb2->Finish(); 1.56 + dt->PushClip(path2); 1.57 + 1.58 + dt->FillRect(Rect(0, 0, 100, 100), ColorPattern(Color(1,0,0))); 1.59 + 1.60 + RefPtr<SourceSurface> surf1 = dt->Snapshot(); 1.61 + RefPtr<SourceSurface> surf2 = ref->Snapshot(); 1.62 + 1.63 + RefPtr<DataSourceSurface> dataSurf1 = surf1->GetDataSurface(); 1.64 + RefPtr<DataSourceSurface> dataSurf2 = surf2->GetDataSurface(); 1.65 + 1.66 + for (int y = 0; y < dt->GetSize().height; y++) { 1.67 + VERIFY(memcmp(dataSurf1->GetData() + y * dataSurf1->Stride(), 1.68 + dataSurf2->GetData() + y * dataSurf2->Stride(), 1.69 + dataSurf1->GetSize().width * 4) == 0); 1.70 + } 1.71 + 1.72 +} 1.73 + 1.74 +void 1.75 +TestBugs::PushPopClip950550() 1.76 +{ 1.77 + RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(BackendType::CAIRO, 1.78 + IntSize(500, 500), 1.79 + SurfaceFormat::B8G8R8A8); 1.80 + dt->PushClipRect(Rect(0, 0, 100, 100)); 1.81 + Matrix m(1, 0, 0, 1, 45, -100); 1.82 + dt->SetTransform(m); 1.83 + dt->PopClip(); 1.84 + 1.85 + // We fail the test if we assert in this call because our draw target's 1.86 + // transforms are out of sync. 1.87 + dt->FillRect(Rect(50, 50, 50, 50), ColorPattern(Color(0.5f, 0, 0, 1.0f))); 1.88 +} 1.89 +