diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-19 13:47:04 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-19 13:47:04 +0200 |
commit | 90022906e060ae0dc8ad60b5770b3b23ffd6cde1 (patch) | |
tree | 48544460bc71732cf2e30bc190125b5a1a531f0a /lib/backing_store_qt.cpp | |
parent | eb530b3752e1af68956feaa833e5b86b1e49e2e1 (diff) |
Move API layer-only classes back from the shared static lib.
Since ContentBrowserClientQt::OverrideCreateWebContentsView now
takes care of using our Qt layer at runtime without relying on
the static RenderWidgetHostView::CreateViewForWidget, we can
now avoid linking this layer into the render process.
Diffstat (limited to 'lib/backing_store_qt.cpp')
-rw-r--r-- | lib/backing_store_qt.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/lib/backing_store_qt.cpp b/lib/backing_store_qt.cpp new file mode 100644 index 000000000..cee0d093e --- /dev/null +++ b/lib/backing_store_qt.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "backing_store_qt.h" + +#include "content/browser/renderer_host/render_widget_host_impl.h" +#include "content/public/browser/render_process_host.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/rect_conversions.h" + +#include <QPainter> + +BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent) + : content::BackingStore(host, size) + , m_pixelBuffer(size.width(), size.height()) +{ +} + +BackingStoreQt::~BackingStoreQt() +{ +} + +void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect) +{ + if (m_pixelBuffer.isNull()) + return; + painter->drawPixmap(rect, m_pixelBuffer, rect); +} + +void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process, + TransportDIB::Id bitmap, + const gfx::Rect &bitmap_rect, + const std::vector<gfx::Rect> ©_rects, + float scale_factor, + const base::Closure &completion_callback, + bool *scheduled_completion_callback) +{ + if (bitmap_rect.IsEmpty()) + return; + + *scheduled_completion_callback = false; + TransportDIB* dib = process->GetTransportDIB(bitmap); + if (!dib) + return; + + gfx::Rect pixel_bitmap_rect = bitmap_rect; + + uint8_t* bitmapData = static_cast<uint8_t*>(dib->memory()); + int width = m_pixelBuffer.size().width(); + int height = m_pixelBuffer.size().height(); + const QImage img(bitmapData, pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), QImage::Format_ARGB32); + + QPainter painter(&m_pixelBuffer); + + for (size_t i = 0; i < copy_rects.size(); ++i) { + gfx::Rect copy_rect = gfx::ToEnclosedRect(gfx::ScaleRect(copy_rects[i], scale_factor)); + + QRect source = QRect( copy_rect.x() - pixel_bitmap_rect.x() + , copy_rect.y() - pixel_bitmap_rect.y() + , copy_rect.width() + , copy_rect.height()); + + QRect destination = QRect( copy_rect.x() + , copy_rect.y() + , copy_rect.width() + , copy_rect.height()); + + painter.drawImage(destination, img, source); + } +} + +void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::Rect &clip_rect, const gfx::Size &view_size) +{ + DCHECK(delta.x() == 0 || delta.y() == 0); + + m_pixelBuffer.scroll(delta.x(), delta.y(), clip_rect.x(), clip_rect.y(), clip_rect.width(), clip_rect.height()); +} + +bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output) +{ + // const int width = std::min(m_pixelBuffer.width(), rect.width()); + // const int height = std::min(m_pixelBuffer.height(), rect.height()); + + // if (!output->Allocate(width, height, true)) + // return false; + + // // This code assumes a visual mode where a pixel is + // // represented using a 32-bit unsigned int, with a byte per component. + // const SkBitmap& bitmap = output->GetBitmap(); + // SkAutoLockPixels alp(bitmap); + + // QPixmap cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height()); + // QImage img = cpy.toImage(); + + // // Convert the format and remove transparency. + // if (img.format() != QImage::Format_RGB32) + // img = img.convertToFormat(QImage::Format_RGB32); + + // const uint8_t* src = img.bits(); + // uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0)); + // memcpy(dst, src, width*height*32); + + // return true; +} + |