Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit dcdb088

Browse files
committed
Bug 527707: Add Direct2D and DirectWrite backend integration to thebes and widget. Preffed off by default r=jrmuizel r=jmathies r=jfkthame
1 parent 61d588d commit dcdb088

21 files changed

+2633
-33
lines changed

gfx/thebes/public/Makefile.in

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ EXPORTS += gfxFT2Fonts.h \
5151
gfxDDrawSurface.h \
5252
$(NULL)
5353
else
54-
EXPORTS += gfxWindowsFonts.h
54+
EXPORTS += gfxWindowsFonts.h
55+
EXPORTS += gfxDWriteFonts.h
56+
EXPORTS += gfxD2DSurface.h
5557
endif
5658

5759
endif

gfx/thebes/public/gfxD2DSurface.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2+
* ***** BEGIN LICENSE BLOCK *****
3+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4+
*
5+
* The contents of this file are subject to the Mozilla Public License Version
6+
* 1.1 (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* http://www.mozilla.org/MPL/
9+
*
10+
* Software distributed under the License is distributed on an "AS IS" basis,
11+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12+
* for the specific language governing rights and limitations under the
13+
* License.
14+
*
15+
* The Initial Developer of the Original Code is Mozilla Foundation.
16+
* Portions created by the Initial Developer are Copyright (C) 2010
17+
* the Initial Developer. All Rights Reserved.
18+
*
19+
* Contributor(s):
20+
* Bas Schouten <bschouten@mozilla.com>
21+
*
22+
* Alternatively, the contents of this file may be used under the terms of
23+
* either the GNU General Public License Version 2 or later (the "GPL"), or
24+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25+
* in which case the provisions of the GPL or the LGPL are applicable instead
26+
* of those above. If you wish to allow use of your version of this file only
27+
* under the terms of either the GPL or the LGPL, and not to allow others to
28+
* use your version of this file under the terms of the MPL, indicate your
29+
* decision by deleting the provisions above and replace them with the notice
30+
* and other provisions required by the GPL or the LGPL. If you do not delete
31+
* the provisions above, a recipient may use your version of this file under
32+
* the terms of any one of the MPL, the GPL or the LGPL.
33+
*
34+
* ***** END LICENSE BLOCK ***** */
35+
36+
#ifndef GFX_D2DSURFACE_H
37+
#define GFX_D2DSURFACE_H
38+
39+
#include "gfxASurface.h"
40+
#include "nsPoint.h"
41+
#include "nsRect.h"
42+
43+
#include <windows.h>
44+
45+
class THEBES_API gfxD2DSurface : public gfxASurface {
46+
public:
47+
48+
gfxD2DSurface(HWND wnd);
49+
50+
gfxD2DSurface(const gfxIntSize& size,
51+
gfxImageFormat imageFormat = ImageFormatRGB24);
52+
53+
54+
gfxD2DSurface(cairo_surface_t *csurf);
55+
56+
virtual ~gfxD2DSurface();
57+
58+
59+
void Present();
60+
void Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip);
61+
62+
};
63+
64+
#endif /* GFX_D2DSURFACE_H */

gfx/thebes/public/gfxDWriteFonts.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2+
* ***** BEGIN LICENSE BLOCK *****
3+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4+
*
5+
* The contents of this file are subject to the Mozilla Public License Version
6+
* 1.1 (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* http://www.mozilla.org/MPL/
9+
*
10+
* Software distributed under the License is distributed on an "AS IS" basis,
11+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12+
* for the specific language governing rights and limitations under the
13+
* License.
14+
*
15+
* The Original Code is Mozilla Foundation code.
16+
*
17+
* The Initial Developer of the Original Code is Mozilla Foundation.
18+
* Portions created by the Initial Developer are Copyright (C) 2010
19+
* the Initial Developer. All Rights Reserved.
20+
*
21+
* Contributor(s):
22+
* Bas Schouten <bschouten@mozilla.com>
23+
*
24+
* Alternatively, the contents of this file may be used under the terms of
25+
* either the GNU General Public License Version 2 or later (the "GPL"), or
26+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27+
* in which case the provisions of the GPL or the LGPL are applicable instead
28+
* of those above. If you wish to allow use of your version of this file only
29+
* under the terms of either the GPL or the LGPL, and not to allow others to
30+
* use your version of this file under the terms of the MPL, indicate your
31+
* decision by deleting the provisions above and replace them with the notice
32+
* and other provisions required by the GPL or the LGPL. If you do not delete
33+
* the provisions above, a recipient may use your version of this file under
34+
* the terms of any one of the MPL, the GPL or the LGPL.
35+
*
36+
* ***** END LICENSE BLOCK ***** */
37+
38+
#ifndef GFX_WINDOWSDWRITEFONTS_H
39+
#define GFX_WINDOWSDWRITEFONTS_H
40+
41+
#include <dwrite.h>
42+
43+
#include "gfxFont.h"
44+
#include "gfxUserFontSet.h"
45+
#include "cairo-win32.h"
46+
47+
/**
48+
* \brief Class representing a font face for a font entry.
49+
*/
50+
class gfxDWriteFont : public gfxFont
51+
{
52+
public:
53+
gfxDWriteFont(gfxFontEntry *aFontEntry,
54+
const gfxFontStyle *aFontStyle);
55+
~gfxDWriteFont();
56+
57+
static already_AddRefed<gfxDWriteFont>
58+
GetOrMakeFont(gfxFontEntry *aFontEntry,
59+
const gfxFontStyle *aStyle,
60+
PRBool aNeedsBold = PR_FALSE);
61+
62+
virtual nsString GetUniqueName();
63+
64+
virtual const gfxFont::Metrics& GetMetrics();
65+
66+
virtual PRUint32 GetSpaceGlyph();
67+
68+
virtual PRBool SetupCairoFont(gfxContext *aContext);
69+
70+
virtual PRBool IsValid() { return mFontFace != NULL; }
71+
protected:
72+
friend class gfxDWriteFontGroup;
73+
74+
void ComputeMetrics();
75+
76+
cairo_font_face_t *CairoFontFace();
77+
78+
cairo_scaled_font_t *CairoScaledFont();
79+
80+
nsRefPtr<IDWriteFontFace> mFontFace;
81+
cairo_font_face_t *mCairoFontFace;
82+
cairo_scaled_font_t *mCairoScaledFont;
83+
84+
gfxFont::Metrics *mMetrics;
85+
PRBool mNeedsOblique;
86+
};
87+
88+
/**
89+
* \brief Class representing a DWrite windows font group.
90+
*/
91+
class gfxDWriteFontGroup : public gfxFontGroup
92+
{
93+
public:
94+
gfxDWriteFontGroup(const nsAString& aFamilies,
95+
const gfxFontStyle *aStyle,
96+
gfxUserFontSet *aUserFontSet);
97+
virtual ~gfxDWriteFontGroup();
98+
99+
gfxFontGroup *Copy(const gfxFontStyle *aStyle);
100+
101+
/**
102+
* Gets the font at a certain position in the font list, it will
103+
* create this font if it hasn't actually been created yet.
104+
*
105+
* \param i Position in the font list
106+
* \return Object representing the font
107+
*/
108+
virtual gfxDWriteFont *GetFontAt(PRInt32 i);
109+
110+
virtual gfxTextRun *MakeTextRun(const PRUnichar *aString, PRUint32 aLength,
111+
const Parameters *aParams, PRUint32 aFlags);
112+
virtual gfxTextRun *MakeTextRun(const PRUint8 *aString, PRUint32 aLength,
113+
const Parameters *aParams, PRUint32 aFlags);
114+
};
115+
116+
#endif

gfx/thebes/public/gfxWindowsPlatform.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@
4343
#define MOZ_FT2_FONTS 1
4444
#endif
4545

46+
47+
/**
48+
* XXX to get CAIRO_HAS_DDRAW_SURFACE, CAIRO_HAS_D2D_SURFACE and
49+
* CAIRO_HAS_DWRITE_FONT
50+
*/
51+
#include "cairo.h"
52+
4653
#include "gfxFontUtils.h"
4754
#include "gfxWindowsSurface.h"
4855
#ifdef MOZ_FT2_FONTS
4956
#include "gfxFT2Fonts.h"
5057
#else
5158
#include "gfxWindowsFonts.h"
59+
#ifdef CAIRO_HAS_DWRITE_FONT
60+
#include "gfxDWriteFonts.h"
61+
#endif
5262
#endif
5363
#include "gfxPlatform.h"
5464

@@ -93,6 +103,9 @@ class THEBES_API gfxWindowsPlatform : public gfxPlatform {
93103
/* Use DirectDraw with OpenGL on Windows CE */
94104
RENDER_DDRAW_GL,
95105

106+
/* Use Direct2D rendering */
107+
RENDER_DIRECT2D,
108+
96109
/* max */
97110
RENDER_MODE_MAX
98111
};
@@ -147,6 +160,10 @@ class THEBES_API gfxWindowsPlatform : public gfxPlatform {
147160

148161
void ClearPrefFonts() { mPrefFonts.Clear(); }
149162

163+
#ifdef CAIRO_HAS_DWRITE_FONT
164+
IDWriteFactory *GetDWriteFactory() { return mDWriteFactory; }
165+
#endif
166+
150167
#ifdef MOZ_FT2_FONTS
151168
FT_Library GetFTLibrary();
152169
#endif
@@ -159,6 +176,10 @@ class THEBES_API gfxWindowsPlatform : public gfxPlatform {
159176
private:
160177
void Init();
161178

179+
#ifdef CAIRO_HAS_DWRITE_FONT
180+
nsRefPtr<IDWriteFactory> mDWriteFactory;
181+
#endif
182+
162183
virtual qcms_profile* GetPlatformCMSOutputProfile();
163184

164185
// TODO: unify this with mPrefFonts (NB: holds families, not fonts) in gfxPlatformFontList

gfx/thebes/src/Makefile.in

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ EXTRA_DSO_LDOPTS += \
4848
$(QCMS_LIBS) \
4949
$(NULL)
5050

51-
5251
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
5352
CPPSRCS += gfxWindowsPlatform.cpp \
5453
gfxWindowsSurface.cpp \
@@ -66,7 +65,12 @@ CPPSRCS += gfxFT2Fonts.cpp \
6665
EXTRA_DSO_LDOPTS += ddraw.lib
6766
else
6867
CPPSRCS += gfxWindowsFonts.cpp \
68+
gfxDWriteFonts.cpp \
69+
gfxDWriteTextAnalysis.cpp \
70+
gfxDWriteCommon.cpp \
71+
gfxD2DSurface.cpp \
6972
gfxGDIFontList.cpp \
73+
gfxDWriteFontList.cpp \
7074
$(NULL)
7175
endif
7276

@@ -202,4 +206,3 @@ endif
202206
ifeq ($(MOZ_WIDGET_TOOLKIT),qt)
203207
CXXFLAGS += $(CAIRO_FT_CFLAGS)
204208
endif
205-

gfx/thebes/src/gfxASurface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
#ifdef CAIRO_HAS_WIN32_SURFACE
4646
#include "gfxWindowsSurface.h"
4747
#endif
48+
#ifdef CAIRO_HAS_D2D_SURFACE
49+
#include "gfxD2DSurface.h"
50+
#endif
4851

4952
#ifdef MOZ_X11
5053
#include "gfxXlibSurface.h"
@@ -162,6 +165,11 @@ gfxASurface::Wrap (cairo_surface_t *csurf)
162165
result = new gfxWindowsSurface(csurf);
163166
}
164167
#endif
168+
#ifdef CAIRO_HAS_D2D_SURFACE
169+
else if (stype == CAIRO_SURFACE_TYPE_D2D) {
170+
result = new gfxD2DSurface(csurf);
171+
}
172+
#endif
165173
#ifdef MOZ_X11
166174
else if (stype == CAIRO_SURFACE_TYPE_XLIB) {
167175
result = new gfxXlibSurface(csurf);

gfx/thebes/src/gfxD2DSurface.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2+
* ***** BEGIN LICENSE BLOCK *****
3+
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4+
*
5+
* The contents of this file are subject to the Mozilla Public License Version
6+
* 1.1 (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
* http://www.mozilla.org/MPL/
9+
*
10+
* Software distributed under the License is distributed on an "AS IS" basis,
11+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12+
* for the specific language governing rights and limitations under the
13+
* License.
14+
*
15+
* The Initial Developer of the Original Code is Mozilla Foundation.
16+
* Portions created by the Initial Developer are Copyright (C) 2010
17+
* the Initial Developer. All Rights Reserved.
18+
*
19+
* Contributor(s):
20+
* Bas Schouten <bschouten@mozilla.com>
21+
*
22+
* Alternatively, the contents of this file may be used under the terms of
23+
* either the GNU General Public License Version 2 or later (the "GPL"), or
24+
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25+
* in which case the provisions of the GPL or the LGPL are applicable instead
26+
* of those above. If you wish to allow use of your version of this file only
27+
* under the terms of either the GPL or the LGPL, and not to allow others to
28+
* use your version of this file under the terms of the MPL, indicate your
29+
* decision by deleting the provisions above and replace them with the notice
30+
* and other provisions required by the GPL or the LGPL. If you do not delete
31+
* the provisions above, a recipient may use your version of this file under
32+
* the terms of any one of the MPL, the GPL or the LGPL.
33+
*
34+
* ***** END LICENSE BLOCK ***** */
35+
36+
#include "gfxD2DSurface.h"
37+
#include "cairo.h"
38+
#include "cairo-win32.h"
39+
40+
gfxD2DSurface::gfxD2DSurface(HWND aWnd)
41+
{
42+
Init(cairo_d2d_surface_create_for_hwnd(aWnd));
43+
}
44+
45+
gfxD2DSurface::gfxD2DSurface(cairo_surface_t *csurf)
46+
{
47+
Init(csurf, PR_TRUE);
48+
}
49+
50+
gfxD2DSurface::gfxD2DSurface(const gfxIntSize& size,
51+
gfxImageFormat imageFormat)
52+
{
53+
Init(cairo_d2d_surface_create((cairo_format_t)imageFormat, size.width, size.height));
54+
}
55+
56+
gfxD2DSurface::~gfxD2DSurface()
57+
{
58+
}
59+
60+
void
61+
gfxD2DSurface::Present()
62+
{
63+
cairo_d2d_present_backbuffer(CairoSurface());
64+
}
65+
66+
void
67+
gfxD2DSurface::Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip)
68+
{
69+
cairo_rectangle_t rect;
70+
rect.x = aClip.x;
71+
rect.y = aClip.y;
72+
rect.width = aClip.width;
73+
rect.height = aClip.height;
74+
cairo_d2d_scroll(CairoSurface(), aDelta.x, aDelta.y, &rect);
75+
}

0 commit comments

Comments
 (0)