1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* Copyright (C) 2009, 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include "BackingStoreTile.h"
#include "GraphicsContext.h"
#include "SurfacePool.h"
#include <BlackBerryPlatformGraphics.h>
namespace BlackBerry {
namespace WebKit {
Fence::~Fence()
{
if (m_platformSync)
SurfacePool::globalSurfacePool()->destroyPlatformSync(m_platformSync);
}
TileBuffer::TileBuffer(const Platform::IntSize& size)
: m_size(size)
, m_fence(Fence::create())
, m_buffer(0)
, m_scale(1.0)
{
}
TileBuffer::~TileBuffer()
{
destroyBuffer(m_buffer);
}
Platform::IntSize TileBuffer::size() const
{
return m_size;
}
Platform::IntRect TileBuffer::rect() const
{
return Platform::IntRect(Platform::IntPoint::zero(), m_size);
}
bool TileBuffer::isRendered(double scale) const
{
return isRendered(rect(), scale);
}
bool TileBuffer::isRendered(const Platform::IntRectRegion& contents, double scale) const
{
return m_scale == scale && Platform::IntRectRegion::subtractRegions(contents, m_renderedRegion).isEmpty();
}
void TileBuffer::clearRenderedRegion(const Platform::IntRectRegion& region)
{
m_renderedRegion = Platform::IntRectRegion::subtractRegions(m_renderedRegion, region);
}
void TileBuffer::clearRenderedRegion()
{
m_renderedRegion = Platform::IntRectRegion();
}
void TileBuffer::addRenderedRegion(const Platform::IntRectRegion& region)
{
m_renderedRegion = Platform::IntRectRegion::unionRegions(region, m_renderedRegion);
}
Platform::IntRectRegion TileBuffer::renderedRegion() const
{
return m_renderedRegion;
}
Platform::IntRectRegion TileBuffer::notRenderedRegion() const
{
return Platform::IntRectRegion::subtractRegions(rect(), renderedRegion());
}
Platform::Graphics::Buffer* TileBuffer::nativeBuffer() const
{
if (!m_buffer)
m_buffer = createBuffer(m_size, Platform::Graphics::TileBuffer, SurfacePool::globalSurfacePool()->sharedPixmapGroup());
return m_buffer;
}
bool TileBuffer::wasNativeBufferCreated() const
{
return static_cast<bool>(m_buffer);
}
BackingStoreTile::BackingStoreTile(const Platform::IntSize& size, BufferingMode mode)
: m_bufferingMode(mode)
, m_committed(false)
, m_backgroundPainted(false)
, m_horizontalShift(0)
, m_verticalShift(0)
{
m_frontBuffer = new TileBuffer(size);
}
BackingStoreTile::~BackingStoreTile()
{
delete m_frontBuffer;
m_frontBuffer = 0;
}
Platform::IntSize BackingStoreTile::size() const
{
return frontBuffer()->size();
}
Platform::IntRect BackingStoreTile::rect() const
{
return frontBuffer()->rect();
}
TileBuffer* BackingStoreTile::frontBuffer() const
{
ASSERT(m_frontBuffer);
return m_frontBuffer;
}
TileBuffer* BackingStoreTile::backBuffer() const
{
if (m_bufferingMode == SingleBuffered)
return frontBuffer();
return SurfacePool::globalSurfacePool()->backBuffer();
}
void BackingStoreTile::swapBuffers()
{
if (m_bufferingMode == SingleBuffered)
return;
// Store temps.
unsigned front = reinterpret_cast<unsigned>(frontBuffer());
unsigned back = reinterpret_cast<unsigned>(backBuffer());
// Atomic change.
_smp_xchg(reinterpret_cast<unsigned*>(&m_frontBuffer), back);
_smp_xchg(reinterpret_cast<unsigned*>(&SurfacePool::globalSurfacePool()->m_backBuffer), front);
}
void BackingStoreTile::reset()
{
setCommitted(false);
frontBuffer()->clearRenderedRegion();
backBuffer()->clearRenderedRegion();
clearShift();
}
void BackingStoreTile::paintBackground()
{
m_backgroundPainted = true;
clearBuffer(backBuffer()->nativeBuffer(), 0, 0, 0, 0);
}
}
}
|