Added new cairo-qt surface from Vlad's patch

New created files moved in sandbox/qt_port.. cairo and gfxQPainterSurface
Changes for existing files applyed from 100_qt-qpainter-cairo.diff
Fixed building non deb mozilla with build_non_deb.sh script
Fixed tab-spaces in new created file cairo-qpainter-surface.cpp
This commit is contained in:
romashin 2008-04-19 18:43:23 +03:00
parent 6ff4d879bf
commit 7831d65b1a
6 changed files with 1529 additions and 174 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,71 @@
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
/* cairo - a vector graphics library with display and print output
*
* Copyright © 2008 Mozilla Corporation
*
* This library is free software; you can redistribute it and/or
* modify it either under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation
* (the "LGPL") or, at your option, under the terms of the Mozilla
* Public License Version 1.1 (the "MPL"). If you do not alter this
* notice, a recipient may use your version of this file under either
* the MPL or the LGPL.
*
* You should have received a copy of the LGPL along with this library
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the MPL along with this library
* in the file COPYING-MPL-1.1
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (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.mozilla.org/MPL/
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
* the specific language governing rights and limitations.
*
* The Original Code is the cairo graphics library.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@mozilla.com>
*/
#ifndef CAIRO_QPAINTER_H
#define CAIRO_QPAINTER_H
#include <cairo.h>
#if CAIRO_HAS_QPAINTER_SURFACE
class QPainter;
CAIRO_BEGIN_DECLS
cairo_public cairo_surface_t *
cairo_qpainter_surface_create (QPainter *painter);
cairo_public cairo_surface_t *
cairo_qpainter_surface_create_with_qimage (cairo_format_t format,
int width,
int height);
cairo_public cairo_surface_t *
cairo_qpainter_surface_create_with_qpixmap (int width,
int height);
cairo_public QPainter *
cairo_qpainter_surface_get_qpainter (cairo_surface_t *surface);
CAIRO_END_DECLS
#else /* CAIRO_HAS_QPAINTER_SURFACE */
# error Cairo was not compiled with support for the QPainter backend
#endif /* CAIRO_HAS_QPAINTER_SURFACE */
#endif /* CAIRO_QPAINTER_H_ */

View File

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Corporation code.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef GFX_QPAINTERSURFACE_H
#define GFX_QPAINTERSURFACE_H
#include "gfxASurface.h"
#include "gfxImageSurface.h"
class QPainter;
class THEBES_API gfxQPainterSurface : public gfxASurface {
public:
gfxQPainterSurface(QPainter *painter);
gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format);
gfxQPainterSurface(const gfxIntSize& size);
gfxQPainterSurface(cairo_surface_t *csurf);
virtual ~gfxQPainterSurface();
QPainter *GetQPainter() { return mPainter; }
protected:
QPainter *mPainter;
};
#endif /* GFX_QPAINTERSURFACE_H */

View File

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Corporation code.
*
* The Initial Developer of the Original Code is Mozilla Corporation.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "gfxQPainterSurface.h"
#include "cairo-qpainter.h"
gfxQPainterSurface::gfxQPainterSurface(QPainter *painter)
{
cairo_surface_t *csurf = cairo_qpainter_surface_create (painter);
mPainter = painter;
Init (csurf);
}
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size, gfxImageFormat format)
{
cairo_surface_t *csurf = cairo_qpainter_surface_create_with_qimage ((cairo_format_t) format,
size.width,
size.height);
mPainter = cairo_qpainter_surface_get_qpainter (csurf);
Init (csurf);
}
gfxQPainterSurface::gfxQPainterSurface(const gfxIntSize& size)
{
cairo_surface_t *csurf = cairo_qpainter_surface_create_with_qpixmap (size.width,
size.height);
mPainter = cairo_qpainter_surface_get_qpainter (csurf);
Init (csurf);
}
gfxQPainterSurface::gfxQPainterSurface(cairo_surface_t *csurf)
{
mPainter = cairo_qpainter_surface_get_qpainter (csurf);
Init(csurf, PR_TRUE);
}
gfxQPainterSurface::~gfxQPainterSurface()
{
}

View File

@ -142,12 +142,6 @@ static const nsModuleComponentInfo components[] =
NS_SCREENMANAGER_CID,
"@mozilla.org/gfx/screenmanager;1",
nsScreenManagerQtConstructor },
/*
{ "Qt Native Scrollbar",
NS_NATIVESCROLLBAR_CID,
"@mozilla.org/widget/nativescrollbar/qt;1",
nsNativeScrollbarConstructor},
*/
{ "Qt Clipboard",
NS_CLIPBOARD_CID,
"@mozilla.org/widget/clipboard;1",
@ -177,11 +171,13 @@ static const nsModuleComponentInfo components[] =
NS_FILEPICKER_CID,
"@mozilla.org/filepicker;1",
nsFilePickerConstructor },
*/
#if 0
{ "Native Theme Renderer",
NS_THEMERENDERER_CID,
"@mozilla.org/chrome/chrome-native-theme;1",
nsNativeThemeQtConstructor }
*/
#endif
};
PR_STATIC_CALLBACK(void)

View File

@ -90,14 +90,10 @@
#include "gfxPlatformQt.h"
#include "gfxXlibSurface.h"
#include "gfxQPainterSurface.h"
#include "gfxContext.h"
#include "gfxImageSurface.h"
#ifdef MOZ_ENABLE_GLITZ
#include "gfxGlitzSurface.h"
#include "glitz-glx.h"
#endif
#include <qapplication.h>
#include <qdesktopwidget.h>
#include <qwidget.h>
@ -1032,9 +1028,18 @@ nsWindow::LoseFocus(void)
LOGFOCUS((" widget lost focus [%p]\n", (void *)this));
}
static int gDoubleBuffering = -1;
bool
nsWindow::OnExposeEvent(QPaintEvent *aEvent)
{
if (gDoubleBuffering == -1) {
if (getenv("MOZ_NO_DOUBLEBUFFER"))
gDoubleBuffering = 0;
else
gDoubleBuffering = 1;
}
if (mIsDestroyed) {
LOG(("Expose event on destroyed window [%p] window %p\n",
(void *)this, mDrawingarea));
@ -1063,22 +1068,26 @@ nsWindow::OnExposeEvent(QPaintEvent *aEvent)
LOGDRAW(("\t%d %d %d %d\n", r.x(), r.y(), r.width(), r.height()));
}
nsCOMPtr<nsIRenderingContext> rc = getter_AddRefs(GetRenderingContext());
if (NS_UNLIKELY(!rc)) {
QPainter painter(mDrawingarea);
nsRefPtr<gfxQPainterSurface> targetSurface = new gfxQPainterSurface(&painter);
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
nsCOMPtr<nsIRenderingContext> rc;
GetDeviceContext()->CreateRenderingContextInstance(*getter_AddRefs(rc));
if (NS_UNLIKELY(!rc))
return FALSE;
}
rc->Init(GetDeviceContext(), ctx);
PRBool translucent;
GetHasTransparentBackground(translucent);
nsIntRect boundsRect;
QPixmap* bufferPixmap = nsnull;
nsRefPtr<gfxXlibSurface> bufferPixmapSurface;
updateRegion->GetBoundingBox(&boundsRect.x, &boundsRect.y,
&boundsRect.width, &boundsRect.height);
// do double-buffering and clipping here
nsRefPtr<gfxContext> ctx = rc->ThebesContext();
ctx->Save();
ctx->NewPath();
if (translucent) {
@ -1099,41 +1108,8 @@ nsWindow::OnExposeEvent(QPaintEvent *aEvent)
// double buffer
if (translucent) {
ctx->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
} else {
#ifdef MOZ_ENABLE_GLITZ
} else if (gDoubleBuffering) {
ctx->PushGroup(gfxASurface::CONTENT_COLOR);
#else // MOZ_ENABLE_GLITZ
// Instead of just doing PushGroup we're going to do a little dance
// to ensure that GDK creates the pixmap, so it doesn't go all
// XGetGeometry on us in gdk_pixmap_foreign_new_for_display when we
// paint native themes
bufferPixmap = new QPixmap(boundsRect.width, boundsRect.height);
if (bufferPixmap) {
bufferPixmapSurface =
new gfxXlibSurface(bufferPixmap->x11Info().display(),
bufferPixmap->handle(),
static_cast<Visual*>(bufferPixmap->x11Info().visual()),
gfxIntSize(boundsRect.width, boundsRect.height));
if (bufferPixmapSurface) {
bufferPixmapSurface->SetDeviceOffset(gfxPoint(-boundsRect.x, -boundsRect.y));
nsCOMPtr<nsIRenderingContext> newRC;
nsresult rv = GetDeviceContext()->
CreateRenderingContextInstance(*getter_AddRefs(newRC));
if (NS_FAILED(rv)) {
bufferPixmapSurface = nsnull;
} else {
rv = newRC->Init(GetDeviceContext(), bufferPixmapSurface);
if (NS_FAILED(rv)) {
bufferPixmapSurface = nsnull;
} else {
rc = newRC;
}
}
}
}
#endif // MOZ_ENABLE_GLITZ
}
#if 0
@ -1162,60 +1138,44 @@ nsWindow::OnExposeEvent(QPaintEvent *aEvent)
// DispatchEvent can Destroy us (bug 378273), avoid doing any paint
// operations below if that happened - it will lead to XError and exit().
if (NS_LIKELY(!mIsDestroyed)) {
if (status != nsEventStatus_eIgnore) {
if (translucent) {
nsRefPtr<gfxPattern> pattern = ctx->PopGroup();
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->SetPattern(pattern);
ctx->Paint();
nsRefPtr<gfxImageSurface> img =
new gfxImageSurface(gfxIntSize(boundsRect.width, boundsRect.height),
gfxImageSurface::ImageFormatA8);
if (img && !img->CairoStatus()) {
img->SetDeviceOffset(gfxPoint(-boundsRect.x, -boundsRect.y));
nsRefPtr<gfxContext> imgCtx = new gfxContext(img);
if (imgCtx) {
imgCtx->SetPattern(pattern);
imgCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
imgCtx->Paint();
}
UpdateTranslucentWindowAlphaInternal(nsRect(boundsRect.x, boundsRect.y,
boundsRect.width, boundsRect.height),
img->Data(), img->Stride());
}
} else {
#ifdef MOZ_ENABLE_GLITZ
ctx->PopGroupToSource();
ctx->Paint();
#else // MOZ_ENABLE_GLITZ
if (bufferPixmapSurface) {
ctx->SetSource(bufferPixmapSurface);
ctx->Paint();
}
#endif // MOZ_ENABLE_GLITZ
}
} else {
// ignore
if (translucent) {
ctx->PopGroup();
} else {
#ifdef MOZ_ENABLE_GLITZ
ctx->PopGroup();
#endif // MOZ_ENABLE_GLITZ
}
}
if (bufferPixmap) {
delete bufferPixmap;
}
if (NS_UNLIKELY(mIsDestroyed))
return ignoreEvent(status);
if (status == nsEventStatus_eIgnore) {
ctx->Restore();
return ignoreEvent(status);
}
if (translucent) {
nsRefPtr<gfxPattern> pattern = ctx->PopGroup();
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
ctx->SetPattern(pattern);
ctx->Paint();
nsRefPtr<gfxImageSurface> img =
new gfxImageSurface(gfxIntSize(boundsRect.width, boundsRect.height),
gfxImageSurface::ImageFormatA8);
if (img && !img->CairoStatus()) {
img->SetDeviceOffset(gfxPoint(-boundsRect.x, -boundsRect.y));
nsRefPtr<gfxContext> imgCtx = new gfxContext(img);
if (imgCtx) {
imgCtx->SetPattern(pattern);
imgCtx->SetOperator(gfxContext::OPERATOR_SOURCE);
imgCtx->Paint();
}
UpdateTranslucentWindowAlphaInternal(nsRect(boundsRect.x, boundsRect.y,
boundsRect.width, boundsRect.height),
img->Data(), img->Stride());
}
} else if (gDoubleBuffering) {
ctx->PopGroupToSource();
ctx->Paint();
}
ctx->Restore();
// check the return value!
return ignoreEvent(status);
}
@ -1799,31 +1759,6 @@ nsWindow::NativeCreate(nsIWidget *aParent,
else
parent = (QWidget*)aNativeParent;
#ifdef MOZ_ENABLE_GLITZ
GdkVisual* visual = nsnull;
if (gfxPlatform::UseGlitz()) {
nsCOMPtr<nsIDeviceContext> dc = aContext;
if (!dc) {
nsCOMPtr<nsIDeviceContext> dc = do_CreateInstance(kDeviceContextCID);
// no parent widget to initialize with
dc->Init(nsnull);
}
Display* dpy = ;
int defaultScreen = gdk_x11_get_default_screen();
glitz_drawable_format_t* format = glitz_glx_find_window_format (dpy, defaultScreen,
0, NULL, 0);
if (format) {
XVisualInfo* vinfo = glitz_glx_get_visual_info_from_format(dpy, defaultScreen, format);
GdkScreen* screen = gdk_display_get_screen(gdk_x11_lookup_xdisplay(dpy), defaultScreen);
visual = gdk_x11_screen_lookup_visual(screen, vinfo->visualid);
} else {
// couldn't find a GLX visual; force Glitz off
gfxPlatform::SetUseGlitz(PR_FALSE);
}
}
#endif
// ok, create our windows
mDrawingarea = createQWidget(parent, aInitData);
@ -2714,6 +2649,7 @@ nsWindow::GetThebesSurface()
mThebesSurface = nsnull;
if (!mThebesSurface) {
#if 0
qint32 x_offset = 0, y_offset = 0;
qint32 width = mDrawingarea->width(), height = mDrawingarea->height();
@ -2721,57 +2657,22 @@ nsWindow::GetThebesSurface()
width = PR_MIN(32767, width);
height = PR_MIN(32767, height);
if (!gfxPlatform::UseGlitz()) {
mThebesSurface = new gfxXlibSurface
(mDrawingarea->x11Info().display(),
(Drawable)mDrawingarea->handle(),
static_cast<Visual*>(mDrawingarea->x11Info().visual()),
gfxIntSize(width, height));
// if the surface creation is reporting an error, then
// we don't have a surface to give back
if (mThebesSurface && mThebesSurface->CairoStatus() != 0)
mThebesSurface = nsnull;
} else {
#ifdef MOZ_ENABLE_GLITZ
glitz_surface_t *gsurf;
glitz_drawable_t *gdraw;
glitz_drawable_format_t *gdformat = glitz_glx_find_window_format (Qt::Key_DISPLAY(),
gdk_x11_get_default_screen(),
0, NULL, 0);
if (!gdformat)
NS_ERROR("Failed to find glitz drawable format");
Display* dpy = Qt::Key_WINDOW_XDISPLAY(d);
Window wnd = Qt::Key_WINDOW_XWINDOW(d);
gdraw =
glitz_glx_create_drawable_for_window (dpy,
DefaultScreen(dpy),
gdformat,
wnd,
width,
height);
glitz_format_t *gformat =
glitz_find_standard_format (gdraw, GLITZ_STANDARD_RGB24);
gsurf =
glitz_surface_create (gdraw,
gformat,
width,
height,
0,
NULL);
glitz_surface_attach (gsurf, gdraw, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
//fprintf (stderr, "## nsThebesDrawingSurface::Init Glitz DRAWABLE %p (DC: %p)\n", aWidget, aDC);
mThebesSurface = new gfxGlitzSurface (gdraw, gsurf, PR_TRUE);
#endif
}
mThebesSurface = new gfxXlibSurface
(mDrawingarea->x11Info().display(),
(Drawable)mDrawingarea->handle(),
static_cast<Visual*>(mDrawingarea->x11Info().visual()),
gfxIntSize(width, height));
// if the surface creation is reporting an error, then
// we don't have a surface to give back
if (mThebesSurface && mThebesSurface->CairoStatus() != 0)
mThebesSurface = nsnull;
if (mThebesSurface) {
mThebesSurface->SetDeviceOffset(gfxPoint(-x_offset, -y_offset));
}
#else
mThebesSurface = new gfxQPainterSurface(gfxIntSize(5,5));
#endif
}
return mThebesSurface;