Bug 1703443 - pt 6. Move RunNextCollectorTimer() into CCGCScheduler r=smaug
[gecko.git] / gfx / thebes / gfxDWriteCommon.h
blob6d8f3afd40da7cd9f5bfa7844a01f3baa5423e7e
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef GFX_DWRITECOMMON_H
7 #define GFX_DWRITECOMMON_H
9 // Mozilla includes
10 #include "mozilla/MemoryReporting.h"
11 #include "mozilla/FontPropertyTypes.h"
12 #include "nscore.h"
13 #include "nsCOMPtr.h"
14 #include "cairo-features.h"
15 #include "gfxFontConstants.h"
16 #include "nsTArray.h"
17 #include "gfxWindowsPlatform.h"
19 #include <windows.h>
20 #include <dwrite.h>
22 static inline DWRITE_FONT_STRETCH DWriteFontStretchFromStretch(
23 mozilla::FontStretch aStretch) {
24 if (aStretch == mozilla::FontStretch::UltraCondensed()) {
25 return DWRITE_FONT_STRETCH_ULTRA_CONDENSED;
27 if (aStretch == mozilla::FontStretch::ExtraCondensed()) {
28 return DWRITE_FONT_STRETCH_EXTRA_CONDENSED;
30 if (aStretch == mozilla::FontStretch::Condensed()) {
31 return DWRITE_FONT_STRETCH_CONDENSED;
33 if (aStretch == mozilla::FontStretch::SemiCondensed()) {
34 return DWRITE_FONT_STRETCH_SEMI_CONDENSED;
36 if (aStretch == mozilla::FontStretch::Normal()) {
37 return DWRITE_FONT_STRETCH_NORMAL;
39 if (aStretch == mozilla::FontStretch::SemiExpanded()) {
40 return DWRITE_FONT_STRETCH_SEMI_EXPANDED;
42 if (aStretch == mozilla::FontStretch::Expanded()) {
43 return DWRITE_FONT_STRETCH_EXPANDED;
45 if (aStretch == mozilla::FontStretch::ExtraExpanded()) {
46 return DWRITE_FONT_STRETCH_EXTRA_EXPANDED;
48 if (aStretch == mozilla::FontStretch::UltraExpanded()) {
49 return DWRITE_FONT_STRETCH_ULTRA_EXPANDED;
51 return DWRITE_FONT_STRETCH_UNDEFINED;
54 static inline mozilla::FontStretch FontStretchFromDWriteStretch(
55 DWRITE_FONT_STRETCH aStretch) {
56 switch (aStretch) {
57 case DWRITE_FONT_STRETCH_ULTRA_CONDENSED:
58 return mozilla::FontStretch::UltraCondensed();
59 case DWRITE_FONT_STRETCH_EXTRA_CONDENSED:
60 return mozilla::FontStretch::ExtraCondensed();
61 case DWRITE_FONT_STRETCH_CONDENSED:
62 return mozilla::FontStretch::Condensed();
63 case DWRITE_FONT_STRETCH_SEMI_CONDENSED:
64 return mozilla::FontStretch::SemiCondensed();
65 case DWRITE_FONT_STRETCH_NORMAL:
66 return mozilla::FontStretch::Normal();
67 case DWRITE_FONT_STRETCH_SEMI_EXPANDED:
68 return mozilla::FontStretch::SemiExpanded();
69 case DWRITE_FONT_STRETCH_EXPANDED:
70 return mozilla::FontStretch::Expanded();
71 case DWRITE_FONT_STRETCH_EXTRA_EXPANDED:
72 return mozilla::FontStretch::ExtraExpanded();
73 case DWRITE_FONT_STRETCH_ULTRA_EXPANDED:
74 return mozilla::FontStretch::UltraExpanded();
75 default:
76 return mozilla::FontStretch::Normal();
80 class gfxDWriteFontFileLoader : public IDWriteFontFileLoader {
81 public:
82 gfxDWriteFontFileLoader() {}
84 // IUnknown interface
85 IFACEMETHOD(QueryInterface)(IID const& iid, OUT void** ppObject) {
86 if (iid == __uuidof(IDWriteFontFileLoader)) {
87 *ppObject = static_cast<IDWriteFontFileLoader*>(this);
88 return S_OK;
89 } else if (iid == __uuidof(IUnknown)) {
90 *ppObject = static_cast<IUnknown*>(this);
91 return S_OK;
92 } else {
93 return E_NOINTERFACE;
97 IFACEMETHOD_(ULONG, AddRef)() { return 1; }
99 IFACEMETHOD_(ULONG, Release)() { return 1; }
101 // IDWriteFontFileLoader methods
103 * Important! Note the key here -has- to be a pointer to a uint64_t.
105 virtual HRESULT STDMETHODCALLTYPE CreateStreamFromKey(
106 void const* fontFileReferenceKey, UINT32 fontFileReferenceKeySize,
107 OUT IDWriteFontFileStream** fontFileStream);
110 * Gets the singleton loader instance. Note that when using this font
111 * loader, the key must be a pointer to a unint64_t.
113 static IDWriteFontFileLoader* Instance() {
114 if (!mInstance) {
115 mInstance = new gfxDWriteFontFileLoader();
116 mozilla::gfx::Factory::GetDWriteFactory()->RegisterFontFileLoader(
117 mInstance);
119 return mInstance;
123 * Creates a IDWriteFontFile and IDWriteFontFileStream from aFontData.
124 * The data from aFontData will be copied internally, so the caller
125 * is free to dispose of it once this method returns.
127 * @param aFontData the font data for the custom font file
128 * @param aLength length of the font data
129 * @param aFontFile out param for the created font file
130 * @param aFontFileStream out param for the corresponding stream
131 * @return HRESULT of internal calls
133 static HRESULT CreateCustomFontFile(const uint8_t* aFontData,
134 uint32_t aLength,
135 IDWriteFontFile** aFontFile,
136 IDWriteFontFileStream** aFontFileStream);
138 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
140 private:
141 static IDWriteFontFileLoader* mInstance;
144 #endif /* GFX_DWRITECOMMON_H */