gfx/2d/unittest/TestBugs.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial