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
|
/*
* Copyright (C) 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 "CanvasLayerWebKitThread.h"
#include "LayerCompositingThread.h"
#if USE(ACCELERATED_COMPOSITING) && ENABLE(ACCELERATED_2D_CANVAS)
#include <BlackBerryPlatformGLES2Program.h>
using BlackBerry::Platform::Graphics::GLES2Program;
namespace WebCore {
void CanvasLayerWebKitThread::deleteTextures()
{
}
class CanvasLayerCompositingThreadClient : public LayerCompositingThreadClient {
public:
CanvasLayerCompositingThreadClient(BlackBerry::Platform::Graphics::Buffer*, const IntSize&);
void layerCompositingThreadDestroyed(LayerCompositingThread*) { }
void layerVisibilityChanged(LayerCompositingThread*, bool) { }
void uploadTexturesIfNeeded(LayerCompositingThread*) { }
void drawTextures(LayerCompositingThread*, const GLES2Program&, double scale, const FloatRect& clipRect);
void deleteTextures(LayerCompositingThread*);
void commitPendingTextureUploads(LayerCompositingThread*);
void clearBuffer() { m_buffer = 0; }
private:
BlackBerry::Platform::Graphics::Buffer* m_buffer;
IntSize m_size;
};
CanvasLayerCompositingThreadClient::CanvasLayerCompositingThreadClient(BlackBerry::Platform::Graphics::Buffer* buffer, const IntSize& size)
: m_buffer(buffer)
, m_size(size)
{
}
void CanvasLayerCompositingThreadClient::drawTextures(LayerCompositingThread* layer, const GLES2Program&, double, const FloatRect& /*clipRect*/)
{
if (!m_buffer)
return;
TransformationMatrix dt = layer->drawTransform();
dt.translate(-layer->bounds().width() / 2.0, -layer->bounds().height() / 2.0);
dt.scaleNonUniform(static_cast<double>(layer->bounds().width()) / m_size.width(), static_cast<double>(layer->bounds().height()) / m_size.height());
blitToBuffer(0, m_buffer, reinterpret_cast<BlackBerry::Platform::TransformationMatrix&>(dt),
BlackBerry::Platform::Graphics::SourceOver, static_cast<unsigned char>(layer->drawOpacity() * 255));
}
void CanvasLayerCompositingThreadClient::deleteTextures(LayerCompositingThread*)
{
// Nothing to do here, the buffer is not owned by us.
}
void CanvasLayerCompositingThreadClient::commitPendingTextureUploads(LayerCompositingThread*)
{
if (!m_buffer)
return;
// This method is called during a synchronization point between WebKit and compositing thread.
// This is our only chance to transfer the back display list to the front display list without
// race conditions.
// 1. Flush back display list to front
BlackBerry::Platform::Graphics::releaseBufferDrawable(m_buffer);
// 2. Draw front display list to FBO
BlackBerry::Platform::Graphics::updateBufferBackingSurface(m_buffer);
}
CanvasLayerWebKitThread::CanvasLayerWebKitThread(BlackBerry::Platform::Graphics::Buffer* buffer, const IntSize& size)
: LayerWebKitThread(CanvasLayer, 0)
{
m_compositingThreadClient = new CanvasLayerCompositingThreadClient(buffer, size);
layerCompositingThread()->setClient(m_compositingThreadClient);
}
CanvasLayerWebKitThread::~CanvasLayerWebKitThread()
{
layerCompositingThread()->setClient(0);
delete m_compositingThreadClient;
}
void CanvasLayerWebKitThread::clearBuffer(CanvasLayerWebKitThread* layer)
{
layer->m_compositingThreadClient->clearBuffer();
}
}
#endif // USE(ACCELERATED_COMPOSITING) && ENABLE(ACCELERATED_2D_CANVAS)
|