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:53:52 +00:00
|
|
|
|
2015-08-10 14:04:31 -05:00
|
|
|
#include <sal/config.h>
|
|
|
|
|
2005-11-02 11:53:52 +00:00
|
|
|
#include "page.hxx"
|
|
|
|
|
|
|
|
namespace canvas
|
|
|
|
{
|
2016-06-09 10:41:10 +01:00
|
|
|
Page::Page( const std::shared_ptr<IRenderModule> &rRenderModule ) :
|
2005-11-02 11:53:52 +00:00
|
|
|
mpRenderModule(rRenderModule),
|
|
|
|
mpSurface(rRenderModule->createSurface(::basegfx::B2ISize()))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Page::validate()
|
|
|
|
{
|
|
|
|
if(!(isValid()))
|
|
|
|
{
|
2015-08-15 15:19:18 +02:00
|
|
|
for( const auto& rFragmentPtr : mpFragments )
|
|
|
|
rFragmentPtr->refresh();
|
2005-11-02 11:53:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Page::isValid() const
|
|
|
|
{
|
|
|
|
return mpSurface && mpSurface->isValid();
|
|
|
|
}
|
|
|
|
|
|
|
|
FragmentSharedPtr Page::allocateSpace( const ::basegfx::B2ISize& rSize )
|
|
|
|
{
|
|
|
|
SurfaceRect rect(rSize);
|
|
|
|
if(insert(rect))
|
|
|
|
{
|
2020-01-23 15:17:46 +02:00
|
|
|
FragmentSharedPtr pFragment = std::make_shared<PageFragment>(rect,this);
|
2005-11-02 11:53:52 +00:00
|
|
|
mpFragments.push_back(pFragment);
|
|
|
|
return pFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FragmentSharedPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Page::nakedFragment( const FragmentSharedPtr& pFragment )
|
|
|
|
{
|
|
|
|
SurfaceRect rect(pFragment->getSize());
|
|
|
|
if(insert(rect))
|
|
|
|
{
|
|
|
|
pFragment->setPage(this);
|
|
|
|
mpFragments.push_back(pFragment);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Page::free( const FragmentSharedPtr& pFragment )
|
|
|
|
{
|
|
|
|
// the fragment passes as argument is no longer
|
|
|
|
// dedicated to this page. either it is about to
|
|
|
|
// be relocated to some other page or it will
|
|
|
|
// currently be deleted. in either case, simply
|
|
|
|
// remove the reference from our internal storage.
|
|
|
|
FragmentContainer_t::iterator it(
|
|
|
|
std::remove(
|
|
|
|
mpFragments.begin(),mpFragments.end(),pFragment));
|
|
|
|
mpFragments.erase(it,mpFragments.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Page::insert( SurfaceRect& r )
|
|
|
|
{
|
2015-08-25 12:24:33 -04:00
|
|
|
for( const auto& pFragment : mpFragments )
|
2005-11-02 11:53:52 +00:00
|
|
|
{
|
2015-08-25 12:24:33 -04:00
|
|
|
const SurfaceRect &rect = pFragment->getRect();
|
2005-11-02 11:53:52 +00:00
|
|
|
const sal_Int32 x = rect.maPos.getX();
|
|
|
|
const sal_Int32 y = rect.maPos.getY();
|
2007-11-01 17:01:05 +00:00
|
|
|
// to avoid interpolation artifacts from other textures,
|
|
|
|
// one pixel gap between them
|
|
|
|
const sal_Int32 w = rect.maSize.getX()+1;
|
|
|
|
const sal_Int32 h = rect.maSize.getY()+1;
|
2005-11-02 11:53:52 +00:00
|
|
|
|
|
|
|
// probe location to the right
|
|
|
|
r.maPos.setX(x+w);
|
|
|
|
r.maPos.setY(y);
|
|
|
|
if(isValidLocation(r))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// probe location at bottom
|
|
|
|
r.maPos.setX(x);
|
|
|
|
r.maPos.setY(y+h);
|
|
|
|
if(isValidLocation(r))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
r.maPos.setX(0);
|
|
|
|
r.maPos.setY(0);
|
|
|
|
|
|
|
|
return isValidLocation(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Page::isValidLocation( const SurfaceRect& r ) const
|
|
|
|
{
|
|
|
|
// the rectangle passed as argument has a valid
|
|
|
|
// location if and only if there's no intersection
|
|
|
|
// with existing areas.
|
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
|
|
|
SurfaceRect aBoundary(mpRenderModule->getPageSize());
|
2005-11-02 11:53:52 +00:00
|
|
|
if( !r.inside(aBoundary) )
|
|
|
|
return false;
|
|
|
|
|
2015-08-25 12:24:33 -04:00
|
|
|
for( const auto& pFragment : mpFragments )
|
2005-11-02 11:53:52 +00:00
|
|
|
{
|
2015-08-25 12:24:33 -04:00
|
|
|
if( r.intersection( pFragment->getRect() ) )
|
2005-11-02 11:53:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|