2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-19 17:56:50 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2005-11-02 11:56:27 +00:00
|
|
|
|
2020-08-04 21:36:11 +00:00
|
|
|
#pragma once
|
2005-11-02 11:56:27 +00:00
|
|
|
|
|
|
|
#include <basegfx/point/b2ipoint.hxx>
|
|
|
|
#include <basegfx/vector/b2isize.hxx>
|
|
|
|
|
|
|
|
namespace canvas
|
|
|
|
{
|
tdf#40534 correctly match page with memory slab
LO has a page manager to match system memory backbuffers with
graphics memory on DX accelerated Windows. Internally this uses
an other rectangle implementation, the SurfaceRect, which had
some great comments like:
// a size of [0,0] therefore denotes a one-by-one rectangle.
In commit 230dbe2e43f3ee2cd285f9cdfe0d57e1ca08b8fe ("#144866# Add
one pixel border around textures, a bunch of drivers clobber those
with dirt), the allocation was increased by a pixel border, but
this doesn't work correctly, because now an allocation of the
page size wouldn't fit anymore into a page, because the pages size
is decreased before comparison. In the end the mixup suffered from
hard to handle off-by-one problems.
This patch fixes the bug, but eventually SurfaceRect should be
replaced by an extended basegfx::B2IBox. But since B2IBox uses two
ranges, instead of a point and a size, it would need a lot of
conversations to I2Point and I2Size objects with the current
Page::insert algorithm.
Change-Id: Ia725b4f8ed4fb270f2eb3734e492062bc7f13793
Reviewed-on: https://gerrit.libreoffice.org/80628
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
2019-10-10 14:48:22 +02:00
|
|
|
/**
|
|
|
|
* This implements some equivalent to basegfx::B2IBox, but instead of two
|
|
|
|
* BasicBox ranges, it uses a position and a size. maPos and maSize could
|
|
|
|
* be replaced by:
|
|
|
|
* - B2IPoint(getMinX(), getMinY()) and
|
|
|
|
* - B2ISize(getMaxX()-getMinX(), getMaxY()-getMinY())
|
|
|
|
*
|
|
|
|
* The current allocation algorithm uses size and pos a lot. Not sure how
|
|
|
|
* time-critical any of this code is and if that would be a problem.
|
|
|
|
*/
|
2005-11-02 11:56:27 +00:00
|
|
|
struct SurfaceRect
|
|
|
|
{
|
|
|
|
::basegfx::B2IPoint maPos;
|
|
|
|
::basegfx::B2ISize maSize;
|
|
|
|
|
2007-11-01 17:01:23 +00:00
|
|
|
explicit SurfaceRect( const ::basegfx::B2ISize &rSize ) :
|
2005-11-02 11:56:27 +00:00
|
|
|
maPos(),
|
2015-11-25 13:51:15 +02:00
|
|
|
maSize(rSize)
|
2005-11-02 11:56:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pointInside( sal_Int32 px, sal_Int32 py ) const
|
|
|
|
{
|
|
|
|
const sal_Int32 x1(maPos.getX());
|
|
|
|
const sal_Int32 y1(maPos.getY());
|
2022-09-21 12:17:00 +02:00
|
|
|
const sal_Int32 x2(x1 + maSize.getWidth());
|
|
|
|
const sal_Int32 y2(y1 + maSize.getHeight());
|
2005-11-02 11:56:27 +00:00
|
|
|
if(px < x1) return false;
|
|
|
|
if(px >= x2) return false;
|
|
|
|
if(py < y1) return false;
|
|
|
|
if(py >= y2) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-15 15:36:14 +02:00
|
|
|
/// returns true if the passed rect intersects this one.
|
2005-11-02 11:56:27 +00:00
|
|
|
bool intersection( const SurfaceRect& r ) const
|
|
|
|
{
|
|
|
|
const sal_Int32 x1(maPos.getX());
|
|
|
|
const sal_Int32 y1(maPos.getY());
|
2022-09-21 12:17:00 +02:00
|
|
|
const sal_Int32 x1w(x1 + maSize.getWidth() - 1);
|
|
|
|
const sal_Int32 y1h(y1 + maSize.getHeight() - 1);
|
tdf#40534 correctly match page with memory slab
LO has a page manager to match system memory backbuffers with
graphics memory on DX accelerated Windows. Internally this uses
an other rectangle implementation, the SurfaceRect, which had
some great comments like:
// a size of [0,0] therefore denotes a one-by-one rectangle.
In commit 230dbe2e43f3ee2cd285f9cdfe0d57e1ca08b8fe ("#144866# Add
one pixel border around textures, a bunch of drivers clobber those
with dirt), the allocation was increased by a pixel border, but
this doesn't work correctly, because now an allocation of the
page size wouldn't fit anymore into a page, because the pages size
is decreased before comparison. In the end the mixup suffered from
hard to handle off-by-one problems.
This patch fixes the bug, but eventually SurfaceRect should be
replaced by an extended basegfx::B2IBox. But since B2IBox uses two
ranges, instead of a point and a size, it would need a lot of
conversations to I2Point and I2Size objects with the current
Page::insert algorithm.
Change-Id: Ia725b4f8ed4fb270f2eb3734e492062bc7f13793
Reviewed-on: https://gerrit.libreoffice.org/80628
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
2019-10-10 14:48:22 +02:00
|
|
|
|
|
|
|
const sal_Int32 x2(r.maPos.getX());
|
|
|
|
const sal_Int32 y2(r.maPos.getY());
|
2022-09-21 12:17:00 +02:00
|
|
|
const sal_Int32 x2w(x2 + r.maSize.getWidth() - 1);
|
|
|
|
const sal_Int32 y2h(y2 + r.maSize.getHeight() - 1);
|
tdf#40534 correctly match page with memory slab
LO has a page manager to match system memory backbuffers with
graphics memory on DX accelerated Windows. Internally this uses
an other rectangle implementation, the SurfaceRect, which had
some great comments like:
// a size of [0,0] therefore denotes a one-by-one rectangle.
In commit 230dbe2e43f3ee2cd285f9cdfe0d57e1ca08b8fe ("#144866# Add
one pixel border around textures, a bunch of drivers clobber those
with dirt), the allocation was increased by a pixel border, but
this doesn't work correctly, because now an allocation of the
page size wouldn't fit anymore into a page, because the pages size
is decreased before comparison. In the end the mixup suffered from
hard to handle off-by-one problems.
This patch fixes the bug, but eventually SurfaceRect should be
replaced by an extended basegfx::B2IBox. But since B2IBox uses two
ranges, instead of a point and a size, it would need a lot of
conversations to I2Point and I2Size objects with the current
Page::insert algorithm.
Change-Id: Ia725b4f8ed4fb270f2eb3734e492062bc7f13793
Reviewed-on: https://gerrit.libreoffice.org/80628
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
2019-10-10 14:48:22 +02:00
|
|
|
|
|
|
|
return !((x1w < x2) || (x2w < x1) || (y1h < y2) || (y2h < y1));
|
2005-11-02 11:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool inside( const SurfaceRect& r ) const
|
|
|
|
{
|
|
|
|
const sal_Int32 x1(maPos.getX());
|
|
|
|
const sal_Int32 y1(maPos.getY());
|
2022-09-21 12:17:00 +02:00
|
|
|
const sal_Int32 x2(x1 + maSize.getWidth() - 1);
|
|
|
|
const sal_Int32 y2(y1 + maSize.getHeight() - 1);
|
2005-11-02 11:56:27 +00:00
|
|
|
if(!(r.pointInside(x1,y1))) return false;
|
|
|
|
if(!(r.pointInside(x2,y2))) return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|