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
|
/*
Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "UpdateAtlas.h"
#if USE(COORDINATED_GRAPHICS)
#include "GraphicsContext.h"
#include "IntRect.h"
#include <wtf/MathExtras.h>
using namespace WebCore;
namespace WebKit {
UpdateAtlas::UpdateAtlas(UpdateAtlasClient* client, int dimension, ShareableBitmap::Flags flags)
: m_client(client)
, m_flags(flags)
, m_inactivityInSeconds(0)
, m_isVaild(true)
{
static int nextID = 0;
m_ID = ++nextID;
IntSize size = nextPowerOfTwo(IntSize(dimension, dimension));
m_surface = ShareableSurface::create(size, flags, ShareableSurface::SupportsGraphicsSurface);
if (!m_surface->createHandle(m_handle)) {
m_isVaild = false;
return;
}
m_client->createUpdateAtlas(m_ID, m_handle);
}
UpdateAtlas::~UpdateAtlas()
{
if (m_isVaild)
m_client->removeUpdateAtlas(m_ID);
}
void UpdateAtlas::buildLayoutIfNeeded()
{
if (!m_areaAllocator) {
m_areaAllocator = adoptPtr(new GeneralAreaAllocator(size()));
m_areaAllocator->setMinimumAllocation(IntSize(32, 32));
}
}
void UpdateAtlas::didSwapBuffers()
{
m_areaAllocator.clear();
}
PassOwnPtr<GraphicsContext> UpdateAtlas::beginPaintingOnAvailableBuffer(int& atlasID, const WebCore::IntSize& size, IntPoint& offset)
{
m_inactivityInSeconds = 0;
buildLayoutIfNeeded();
IntRect rect = m_areaAllocator->allocate(size);
// No available buffer was found, returning null.
if (rect.isEmpty())
return PassOwnPtr<GraphicsContext>();
if (!m_isVaild)
return PassOwnPtr<GraphicsContext>();
atlasID = m_ID;
// FIXME: Use tri-state buffers, to allow faster updates.
offset = rect.location();
OwnPtr<GraphicsContext> graphicsContext = m_surface->createGraphicsContext(rect);
if (flags() & ShareableBitmap::SupportsAlpha) {
graphicsContext->setCompositeOperation(CompositeCopy);
graphicsContext->fillRect(IntRect(IntPoint::zero(), size), Color::transparent, ColorSpaceDeviceRGB);
graphicsContext->setCompositeOperation(CompositeSourceOver);
}
return graphicsContext.release();
}
}
#endif
|