LCOV - app.info - gfx/2d/Factory.cpp

LCOV - code coverage report
| Current view: | directory - gfx/2d - Factory.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 26 | 0 | 0.0 %
| Date: | 2012-06-02 | Functions: | 4 | 0 | 0.0 %

           1                 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
           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 Corporation code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
          18                 :  * Portions created by the Initial Developer are Copyright (C) 2011
          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                 : #include "2D.h"
          39                 :
          40                 : #ifdef USE_CAIRO
          41                 : #include "DrawTargetCairo.h"
          42                 : #include "ScaledFontBase.h"
          43                 : #endif
          44                 :
          45                 : #ifdef USE_SKIA
          46                 : #include "DrawTargetSkia.h"
          47                 : #include "ScaledFontBase.h"
          48                 : #include "ScaledFontFreetype.h"
          49                 : #endif
          50                 :
          51                 : #ifdef WIN32
          52                 : #include "ScaledFontWin.h"
          53                 : #endif
          54                 :
          55                 : #ifdef XP_MACOSX
          56                 : #include "ScaledFontMac.h"
          57                 : #endif
          58                 :
          59                 :
          60                 : #ifdef XP_MACOSX
          61                 : #include "DrawTargetCG.h"
          62                 : #endif
          63                 :
          64                 : #ifdef WIN32
          65                 : #include "DrawTargetD2D.h"
          66                 : #include "ScaledFontDWrite.h"
          67                 : #include <d3d10_1.h>
          68                 : #endif
          69                 :
          70                 :
          71                 : #include "Logging.h"
          72                 :
          73                 : #ifdef PR_LOGGING
          74                 : PRLogModuleInfo *sGFX2DLog = PR_NewLogModule("gfx2d");
          75                 : #endif
          76                 :
          77                 : namespace mozilla {
          78                 : namespace gfx {
          79                 :
          80                 : // XXX - Need to define an API to set this.
          81                 : int sGfxLogLevel = LOG_DEBUG;
          82                 :
          83                 : #ifdef WIN32
          84                 : ID3D10Device1 *Factory::mD3D10Device;
          85                 : #endif
          86                 :
          87                 : TemporaryRef<DrawTarget>
          88               0 : Factory::CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat)
          89                 : {
          90               0 :   switch (aBackend) {
          91                 : #ifdef WIN32
          92                 :   case BACKEND_DIRECT2D:
          93                 :     {
          94                 :       RefPtr<DrawTargetD2D> newTarget;
          95                 :       newTarget = new DrawTargetD2D();
          96                 :       if (newTarget->Init(aSize, aFormat)) {
          97                 :         return newTarget;
          98                 :       }
          99                 :       break;
         100                 :     }
         101                 : #elif defined XP_MACOSX || defined ANDROID || defined LINUX
         102                 : #ifdef USE_SKIA
         103                 :   case BACKEND_SKIA:
         104                 :     {
         105               0 :       RefPtr<DrawTargetSkia> newTarget;
         106               0 :       newTarget = new DrawTargetSkia();
         107               0 :       if (newTarget->Init(aSize, aFormat)) {
         108               0 :         return newTarget;
         109                 :       }
         110               0 :       break;
         111                 :     }
         112                 : #endif
         113                 : #ifdef XP_MACOSX
         114                 :   case BACKEND_COREGRAPHICS:
         115                 :     {
         116                 :       RefPtr<DrawTargetCG> newTarget;
         117                 :       newTarget = new DrawTargetCG();
         118                 :       if (newTarget->Init(aSize, aFormat)) {
         119                 :         return newTarget;
         120                 :       }
         121                 :       break;
         122                 :     }
         123                 : #endif
         124                 : #endif
         125                 :   default:
         126               0 :     gfxDebug() << "Invalid draw target type specified.";
         127               0 :     return NULL;
         128                 :   }
         129                 :
         130               0 :   gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize;
         131                 :   // Failed
         132               0 :   return NULL;
         133                 : }
         134                 :
         135                 : TemporaryRef<ScaledFont>
         136               0 : Factory::CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize)
         137                 : {
         138               0 :   switch (aNativeFont.mType) {
         139                 : #ifdef WIN32
         140                 :   case NATIVE_FONT_DWRITE_FONT_FACE:
         141                 :     {
         142                 :       return new ScaledFontDWrite(static_cast<IDWriteFontFace*>(aNativeFont.mFont), aSize);
         143                 :     }
         144                 : #endif
         145                 : #ifdef XP_MACOSX
         146                 :   case NATIVE_FONT_MAC_FONT_FACE:
         147                 :     {
         148                 :       return new ScaledFontMac(static_cast<CGFontRef>(aNativeFont.mFont), aSize);
         149                 :     }
         150                 : #endif
         151                 : #ifdef USE_SKIA
         152                 : #ifdef WIN32
         153                 :   case NATIVE_FONT_GDI_FONT_FACE:
         154                 :     {
         155                 :       return new ScaledFontWin(static_cast<gfxGDIFont*>(aNativeFont.mFont), aSize);
         156                 :     }
         157                 : #endif
         158                 :   case NATIVE_FONT_SKIA_FONT_FACE:
         159                 :     {
         160               0 :       return new ScaledFontFreetype(static_cast<gfxFont*>(aNativeFont.mFont), aSize);
         161                 :     }
         162                 : #endif
         163                 : #ifdef USE_CAIRO
         164                 :   case NATIVE_FONT_CAIRO_FONT_FACE:
         165                 :     {
         166               0 :       return new ScaledFontBase(aSize);
         167                 :     }
         168                 : #endif
         169                 :   default:
         170               0 :     gfxWarning() << "Invalid native font type specified.";
         171               0 :     return NULL;
         172                 :   }
         173                 : }
         174                 :
         175                 : TemporaryRef<ScaledFont>
         176               0 : Factory::CreateScaledFontWithCairo(const NativeFont& aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont)
         177                 : {
         178                 : #ifdef USE_CAIRO
         179                 :   // In theory, we could pull the NativeFont out of the cairo_scaled_font_t*,
         180                 :   // but that would require a lot of code that would be otherwise repeated in
         181                 :   // various backends.
         182                 :   // Therefore, we just reuse CreateScaledFontForNativeFont's implementation.
         183               0 :   RefPtr<ScaledFont> font = CreateScaledFontForNativeFont(aNativeFont, aSize);
         184               0 :   static_cast<ScaledFontBase*>(font.get())->SetCairoScaledFont(aScaledFont);
         185               0 :   return font;
         186                 : #else
         187                 :   return NULL;
         188                 : #endif
         189                 : }
         190                 :
         191                 : #ifdef WIN32
         192                 : TemporaryRef<DrawTarget>
         193                 : Factory::CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat)
         194                 : {
         195                 :   RefPtr<DrawTargetD2D> newTarget;
         196                 :
         197                 :   newTarget = new DrawTargetD2D();
         198                 :   if (newTarget->Init(aTexture, aFormat)) {
         199                 :     return newTarget;
         200                 :   }
         201                 :
         202                 :   gfxWarning() << "Failed to create draw target for D3D10 texture.";
         203                 :
         204                 :   // Failed
         205                 :   return NULL;
         206                 : }
         207                 :
         208                 : void
         209                 : Factory::SetDirect3D10Device(ID3D10Device1 *aDevice)
         210                 : {
         211                 :   mD3D10Device = aDevice;
         212                 : }
         213                 :
         214                 : ID3D10Device1*
         215                 : Factory::GetDirect3D10Device()
         216                 : {
         217                 :   return mD3D10Device;
         218                 : }
         219                 :
         220                 : #endif // XP_WIN
         221                 :
         222                 : #ifdef USE_CAIRO
         223                 : TemporaryRef<DrawTarget>
         224               0 : Factory::CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface)
         225                 : {
         226               0 :   RefPtr<DrawTargetCairo> newTarget = new DrawTargetCairo();
         227               0 :   if (newTarget->Init(aSurface)) {
         228               0 :     return newTarget;
         229                 :   }
         230                 :
         231               0 :   return NULL;
         232                 : }
         233                 : #endif
         234                 :
         235                 : }
         236                 : }

Generated by: LCOV version 1.7