mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
Bug 333178 fix image cursors for cairo-gtk2 builds
r=bryner sr=roc
This commit is contained in:
parent
4f55f337d0
commit
12ba7928f8
@ -56,7 +56,7 @@
|
||||
#include "imgIContainer.h"
|
||||
#include "nsIImage.h"
|
||||
#ifdef MOZ_WIDGET_GTK2
|
||||
#include "nsIGdkPixbufImage.h"
|
||||
#include "nsIImageToPixbuf.h"
|
||||
#endif
|
||||
#include "nsColor.h"
|
||||
|
||||
@ -353,11 +353,12 @@ WriteImage(const nsCString& aPath, gfxIImageFrame* aImage)
|
||||
#ifndef MOZ_WIDGET_GTK2
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
#else
|
||||
nsCOMPtr<nsIGdkPixbufImage> pixImg(do_QueryInterface(img));
|
||||
if (!pixImg)
|
||||
nsCOMPtr<nsIImageToPixbuf> imgToPixbuf =
|
||||
do_GetService("@mozilla.org/widget/image-to-gdk-pixbuf;1");
|
||||
if (!imgToPixbuf)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
GdkPixbuf* pixbuf = pixImg->GetGdkPixbuf();
|
||||
GdkPixbuf* pixbuf = imgToPixbuf->ConvertImageToPixbuf(img);
|
||||
if (!pixbuf)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
|
@ -105,6 +105,7 @@ CPPSRCS = \
|
||||
nsDeviceContextSpecFactoryG.cpp \
|
||||
nsDeviceContextSpecG.cpp \
|
||||
nsPrintOptionsGTK.cpp \
|
||||
nsImageToPixbuf.cpp \
|
||||
$(NULL)
|
||||
|
||||
# build our subdirs, too
|
||||
@ -131,6 +132,7 @@ endif
|
||||
|
||||
EXPORTS = \
|
||||
nsIGdkPixbufImage.h \
|
||||
nsIImageToPixbuf.h \
|
||||
mozdrawingarea.h \
|
||||
mozcontainer.h \
|
||||
$(NULL)
|
||||
|
64
widget/src/gtk2/nsIImageToPixbuf.h
Normal file
64
widget/src/gtk2/nsIImageToPixbuf.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* ***** 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.org widget code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 NSIIMAGETOPIXBUF_H_
|
||||
#define NSIIMAGETOPIXBUF_H_
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
// dfa4ac93-83f2-4ab8-9b2a-0ff7022aebe2
|
||||
#define NSIIMAGETOPIXBUF_IID \
|
||||
{ 0xdfa4ac93, 0x83f2, 0x4ab8, \
|
||||
{ 0x9b, 0x2a, 0x0f, 0xf7, 0x02, 0x2a, 0xeb, 0xe2 } }
|
||||
|
||||
class nsIImage;
|
||||
typedef struct _GdkPixbuf GdkPixbuf;
|
||||
|
||||
/**
|
||||
* An interface that allows converting an nsIImage to a GdkPixbuf*. It is
|
||||
* similar to nsIGdkPixbufImage but more general, as it doesn't require the
|
||||
* image to implement nsIGdkPixbufImage.
|
||||
*/
|
||||
class nsIImageToPixbuf : public nsISupports {
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NSIIMAGETOPIXBUF_IID)
|
||||
|
||||
NS_IMETHOD_(GdkPixbuf*) ConvertImageToPixbuf(nsIImage* aImage) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIImageToPixbuf, NSIIMAGETOPIXBUF_IID)
|
||||
|
||||
#endif
|
152
widget/src/gtk2/nsImageToPixbuf.cpp
Normal file
152
widget/src/gtk2/nsImageToPixbuf.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
/* vim:set sw=4 sts=4 et cin: */
|
||||
/* ***** 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.org widget code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 <gdk-pixbuf/gdk-pixbuf.h>
|
||||
|
||||
#ifdef MOZ_CAIRO_GFX
|
||||
#include "gfxASurface.h"
|
||||
#include "gfxImageSurface.h"
|
||||
#include "gfxContext.h"
|
||||
#endif
|
||||
|
||||
#include "nsIGdkPixbufImage.h"
|
||||
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "nsImageToPixbuf.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsImageToPixbuf, nsIImageToPixbuf)
|
||||
|
||||
inline unsigned char
|
||||
unpremultiply (unsigned char color,
|
||||
unsigned char alpha)
|
||||
{
|
||||
if (alpha == 0)
|
||||
return 0;
|
||||
// plus alpha/2 to round instead of truncate
|
||||
return (color * 255 + alpha / 2) / alpha;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(GdkPixbuf*)
|
||||
nsImageToPixbuf::ConvertImageToPixbuf(nsIImage* aImage)
|
||||
{
|
||||
return ImageToPixbuf(aImage);
|
||||
}
|
||||
|
||||
GdkPixbuf*
|
||||
nsImageToPixbuf::ImageToPixbuf(nsIImage* aImage)
|
||||
{
|
||||
#ifdef MOZ_CAIRO_GFX
|
||||
PRInt32 width = aImage->GetWidth(),
|
||||
height = aImage->GetHeight();
|
||||
|
||||
nsRefPtr<gfxASurface> surface;
|
||||
aImage->GetSurface(getter_AddRefs(surface));
|
||||
|
||||
nsRefPtr<gfxImageSurface> imgSurface;
|
||||
if (surface->GetType() == gfxASurface::SurfaceTypeImage) {
|
||||
imgSurface = NS_STATIC_CAST(gfxImageSurface*,
|
||||
NS_STATIC_CAST(gfxASurface*, surface.get()));
|
||||
} else {
|
||||
imgSurface = new gfxImageSurface(gfxImageSurface::ImageFormatARGB32,
|
||||
width, height);
|
||||
if (!imgSurface)
|
||||
return nsnull;
|
||||
|
||||
nsRefPtr<gfxContext> context = new gfxContext(imgSurface);
|
||||
if (!context)
|
||||
return nsnull;
|
||||
|
||||
context->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
context->SetSource(surface);
|
||||
context->Paint();
|
||||
}
|
||||
|
||||
GdkPixbuf* pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, PR_TRUE, 8,
|
||||
width, height);
|
||||
if (!pixbuf)
|
||||
return nsnull;
|
||||
|
||||
PRUint32 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
||||
guchar* pixels = gdk_pixbuf_get_pixels (pixbuf);
|
||||
|
||||
long cairoStride = imgSurface->Stride();
|
||||
unsigned char* cairoData = imgSurface->Data();
|
||||
|
||||
gfxASurface::gfxImageFormat format = imgSurface->Format();
|
||||
|
||||
for (PRInt32 row = 0; row < height; ++row) {
|
||||
for (PRInt32 col = 0; col < width; ++col) {
|
||||
guchar* pixel = pixels + row * rowstride + 4 * col;
|
||||
|
||||
PRUint32* cairoPixel = NS_REINTERPRET_CAST(PRUint32*,
|
||||
(cairoData + row * cairoStride + 4 * col));
|
||||
|
||||
if (format == gfxASurface::ImageFormatARGB32) {
|
||||
const PRUint8 a = (*cairoPixel >> 24) & 0xFF;
|
||||
const PRUint8 r = unpremultiply((*cairoPixel >> 16) & 0xFF, a);
|
||||
const PRUint8 g = unpremultiply((*cairoPixel >> 8) & 0xFF, a);
|
||||
const PRUint8 b = unpremultiply((*cairoPixel >> 0) & 0xFF, a);
|
||||
|
||||
*pixel++ = r;
|
||||
*pixel++ = g;
|
||||
*pixel++ = b;
|
||||
*pixel++ = a;
|
||||
} else {
|
||||
NS_ASSERTION(format == gfxASurface::ImageFormatRGB24,
|
||||
"unexpected format");
|
||||
const PRUint8 r = (*cairoPixel >> 16) & 0xFF;
|
||||
const PRUint8 g = (*cairoPixel >> 8) & 0xFF;
|
||||
const PRUint8 b = (*cairoPixel >> 0) & 0xFF;
|
||||
|
||||
*pixel++ = r;
|
||||
*pixel++ = g;
|
||||
*pixel++ = b;
|
||||
*pixel++ = 0xFF; // A
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pixbuf;
|
||||
#else
|
||||
nsCOMPtr<nsIGdkPixbufImage> img(do_QueryInterface(aImage));
|
||||
if (img)
|
||||
return img->GetGdkPixbuf();
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
61
widget/src/gtk2/nsImageToPixbuf.h
Normal file
61
widget/src/gtk2/nsImageToPixbuf.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* vim:set sw=4 sts=4 et cin: */
|
||||
/* ***** 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.org widget code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Christian Biesinger <cbiesinger@web.de>.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 NSIMAGETOPIXBUF_H_
|
||||
#define NSIMAGETOPIXBUF_H_
|
||||
|
||||
#include "nsIImageToPixbuf.h"
|
||||
|
||||
class nsImageToPixbuf : public nsIImageToPixbuf {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_IMETHOD_(GdkPixbuf*) ConvertImageToPixbuf(nsIImage* aImage);
|
||||
|
||||
// Friendlier version of ConvertImageToPixbuf for callers inside of
|
||||
// widget
|
||||
static GdkPixbuf* ImageToPixbuf(nsIImage* aImage);
|
||||
private:
|
||||
~nsImageToPixbuf() {}
|
||||
};
|
||||
|
||||
|
||||
// fc2389b8-c650-4093-9e42-b05e5f0685b7
|
||||
#define NS_IMAGE_TO_PIXBUF_CID \
|
||||
{ 0xfc2389b8, 0xc650, 0x4093, \
|
||||
{ 0x9e, 0x42, 0xb0, 0x5e, 0x5f, 0x06, 0x85, 0xb7 } }
|
||||
|
||||
#endif
|
@ -59,6 +59,7 @@
|
||||
#include "nsDeviceContextSpecFactoryG.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsImageToPixbuf.h"
|
||||
|
||||
#ifdef NATIVE_THEME_SUPPORT
|
||||
#include "nsNativeThemeGTK.h"
|
||||
@ -95,6 +96,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeGTK)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintOptionsGTK, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsPrinterEnumeratorGTK)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
|
||||
|
||||
static NS_IMETHODIMP
|
||||
nsFilePickerConstructor(nsISupports *aOuter, REFNSIID aIID,
|
||||
@ -269,6 +271,10 @@ static const nsModuleComponentInfo components[] =
|
||||
// "@mozilla.org/gfx/device_context_spec_factory/gtk;1",
|
||||
"@mozilla.org/gfx/devicecontextspecfactory;1",
|
||||
nsDeviceContextSpecFactoryGTKConstructor },
|
||||
{ "Image to gdk-pixbuf converter",
|
||||
NS_IMAGE_TO_PIXBUF_CID,
|
||||
"@mozilla.org/widget/image-to-gdk-pixbuf;1",
|
||||
nsImageToPixbufConstructor },
|
||||
};
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
|
@ -92,7 +92,7 @@ static const char sAccessibilityKey [] = "config.use_system_prefs.accessibility"
|
||||
#include "gfxIImageFrame.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsIImage.h"
|
||||
#include "nsIGdkPixbufImage.h"
|
||||
#include "nsImageToPixbuf.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
@ -929,11 +929,7 @@ nsWindow::SetCursor(imgIContainer* aCursor,
|
||||
if (!img)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCOMPtr<nsIGdkPixbufImage> pixImg(do_QueryInterface(img));
|
||||
if (!pixImg)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
GdkPixbuf* pixbuf = pixImg->GetGdkPixbuf();
|
||||
GdkPixbuf* pixbuf = nsImageToPixbuf::ImageToPixbuf(img);
|
||||
if (!pixbuf)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user