2011-06-24 10:41:16 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* ***** 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 Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Bas Schouten <bschouten@mozilla.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 "2D.h"
|
|
|
|
|
|
|
|
#ifdef USE_CAIRO
|
|
|
|
#include "DrawTargetCairo.h"
|
2012-01-27 10:08:46 -08:00
|
|
|
#include "ScaledFontBase.h"
|
2011-06-24 10:41:16 -07:00
|
|
|
#endif
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
#include "DrawTargetSkia.h"
|
2012-01-09 10:54:44 -08:00
|
|
|
#include "ScaledFontBase.h"
|
2012-02-13 11:58:01 -08:00
|
|
|
#include "ScaledFontFreetype.h"
|
2011-11-02 12:55:03 -07:00
|
|
|
#endif
|
2012-01-09 10:54:44 -08:00
|
|
|
|
2011-11-17 20:00:37 -08:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "ScaledFontWin.h"
|
|
|
|
#endif
|
2012-01-09 10:54:44 -08:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "ScaledFontMac.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "DrawTargetCG.h"
|
2011-11-02 12:55:03 -07:00
|
|
|
#endif
|
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
#include "DrawTargetD2D.h"
|
|
|
|
#include "ScaledFontDWrite.h"
|
|
|
|
#include <d3d10_1.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#include "Logging.h"
|
|
|
|
|
|
|
|
#ifdef PR_LOGGING
|
|
|
|
PRLogModuleInfo *sGFX2DLog = PR_NewLogModule("gfx2d");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
|
|
|
|
// XXX - Need to define an API to set this.
|
|
|
|
int sGfxLogLevel = LOG_DEBUG;
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
ID3D10Device1 *Factory::mD3D10Device;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aBackend) {
|
|
|
|
#ifdef WIN32
|
|
|
|
case BACKEND_DIRECT2D:
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetD2D> newTarget;
|
|
|
|
newTarget = new DrawTargetD2D();
|
|
|
|
if (newTarget->Init(aSize, aFormat)) {
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-01-30 17:24:27 -08:00
|
|
|
#elif defined XP_MACOSX || defined ANDROID || defined LINUX
|
2011-11-02 12:55:03 -07:00
|
|
|
#ifdef USE_SKIA
|
|
|
|
case BACKEND_SKIA:
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetSkia> newTarget;
|
|
|
|
newTarget = new DrawTargetSkia();
|
|
|
|
if (newTarget->Init(aSize, aFormat)) {
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 10:54:44 -08:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case BACKEND_COREGRAPHICS:
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetCG> newTarget;
|
|
|
|
newTarget = new DrawTargetCG();
|
|
|
|
if (newTarget->Init(aSize, aFormat)) {
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-06-24 10:41:16 -07:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
gfxDebug() << "Invalid draw target type specified.";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
|
|
|
|
// Failed
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-02 12:15:08 -07:00
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
Factory::CreateDrawTargetForData(BackendType aBackend,
|
|
|
|
unsigned char *aData,
|
|
|
|
const IntSize &aSize,
|
|
|
|
int32_t aStride,
|
|
|
|
SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aBackend) {
|
|
|
|
#ifdef USE_SKIA
|
|
|
|
case BACKEND_SKIA:
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetSkia> newTarget;
|
|
|
|
newTarget = new DrawTargetSkia();
|
|
|
|
newTarget->Init(aData, aSize, aStride, aFormat);
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
gfxDebug() << "Invalid draw target type specified.";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
|
|
|
|
// Failed
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
TemporaryRef<ScaledFont>
|
|
|
|
Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize)
|
|
|
|
{
|
|
|
|
switch (aNativeFont.mType) {
|
|
|
|
#ifdef WIN32
|
|
|
|
case NATIVE_FONT_DWRITE_FONT_FACE:
|
|
|
|
{
|
|
|
|
return new ScaledFontDWrite(static_cast<IDWriteFontFace*>(aNativeFont.mFont), aSize);
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
#endif
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case NATIVE_FONT_MAC_FONT_FACE:
|
|
|
|
{
|
|
|
|
return new ScaledFontMac(static_cast<CGFontRef>(aNativeFont.mFont), aSize);
|
|
|
|
}
|
2011-11-17 20:00:37 -08:00
|
|
|
#endif
|
2012-01-09 10:54:44 -08:00
|
|
|
#ifdef USE_SKIA
|
2011-11-17 20:00:37 -08:00
|
|
|
#ifdef WIN32
|
|
|
|
case NATIVE_FONT_GDI_FONT_FACE:
|
|
|
|
{
|
|
|
|
return new ScaledFontWin(static_cast<gfxGDIFont*>(aNativeFont.mFont), aSize);
|
|
|
|
}
|
2011-11-02 12:55:03 -07:00
|
|
|
#endif
|
|
|
|
case NATIVE_FONT_SKIA_FONT_FACE:
|
|
|
|
{
|
2012-02-13 11:58:01 -08:00
|
|
|
return new ScaledFontFreetype(static_cast<gfxFont*>(aNativeFont.mFont), aSize);
|
2011-11-02 12:55:03 -07:00
|
|
|
}
|
2011-06-24 10:41:16 -07:00
|
|
|
#endif
|
2012-01-27 10:08:46 -08:00
|
|
|
#ifdef USE_CAIRO
|
2012-01-10 10:26:59 -08:00
|
|
|
case NATIVE_FONT_CAIRO_FONT_FACE:
|
|
|
|
{
|
2012-01-27 10:08:46 -08:00
|
|
|
return new ScaledFontBase(aSize);
|
2012-01-10 10:26:59 -08:00
|
|
|
}
|
2012-01-27 10:08:46 -08:00
|
|
|
#endif
|
2011-06-24 10:41:16 -07:00
|
|
|
default:
|
|
|
|
gfxWarning() << "Invalid native font type specified.";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-27 10:08:46 -08:00
|
|
|
TemporaryRef<ScaledFont>
|
|
|
|
Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont)
|
|
|
|
{
|
|
|
|
#ifdef USE_CAIRO
|
|
|
|
// In theory, we could pull the NativeFont out of the cairo_scaled_font_t*,
|
|
|
|
// but that would require a lot of code that would be otherwise repeated in
|
|
|
|
// various backends.
|
|
|
|
// Therefore, we just reuse CreateScaledFontForNativeFont's implementation.
|
|
|
|
RefPtr<ScaledFont> font = CreateScaledFontForNativeFont(aNativeFont, aSize);
|
|
|
|
static_cast<ScaledFontBase*>(font.get())->SetCairoScaledFont(aScaledFont);
|
|
|
|
return font;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
Factory::CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetD2D> newTarget;
|
|
|
|
|
|
|
|
newTarget = new DrawTargetD2D();
|
|
|
|
if (newTarget->Init(aTexture, aFormat)) {
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxWarning() << "Failed to create draw target for D3D10 texture.";
|
|
|
|
|
|
|
|
// Failed
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
|
|
|
|
{
|
|
|
|
mD3D10Device = aDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3D10Device1*
|
|
|
|
Factory::GetDirect3D10Device()
|
|
|
|
{
|
|
|
|
return mD3D10Device;
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:20:17 -07:00
|
|
|
TemporaryRef<GlyphRenderingOptions>
|
|
|
|
Factory::CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams)
|
|
|
|
{
|
|
|
|
RefPtr<GlyphRenderingOptions> options =
|
|
|
|
new GlyphRenderingOptionsDWrite(aParams);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2011-06-24 10:41:16 -07:00
|
|
|
#endif // XP_WIN
|
|
|
|
|
|
|
|
#ifdef USE_CAIRO
|
|
|
|
TemporaryRef<DrawTarget>
|
|
|
|
Factory::CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface)
|
|
|
|
{
|
|
|
|
RefPtr<DrawTargetCairo> newTarget = new DrawTargetCairo();
|
|
|
|
if (newTarget->Init(aSurface)) {
|
|
|
|
return newTarget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|