LCOV - code coverage report
Current view: directory - gfx/2d - HelpersSkia.h (source / functions) Found Hit Coverage
Test: app.info Lines: 36 0 0.0 %
Date: 2012-06-02 Functions: 5 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                 :  *   Matt Woodrow <mwoodrow@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 MOZILLA_GFX_HELPERSSKIA_H_
      39                 : #define MOZILLA_GFX_HELPERSSKIA_H_
      40                 : 
      41                 : #include "2D.h"
      42                 : #include "skia/SkCanvas.h"
      43                 : #include "skia/SkDashPathEffect.h"
      44                 : 
      45                 : namespace mozilla {
      46                 : namespace gfx {
      47                 : 
      48                 : static inline SkBitmap::Config
      49               0 : GfxFormatToSkiaConfig(SurfaceFormat format)
      50                 : {
      51               0 :   switch (format)
      52                 :   {
      53                 :     case FORMAT_B8G8R8A8:
      54               0 :       return SkBitmap::kARGB_8888_Config;
      55                 :     case FORMAT_B8G8R8X8:
      56                 :       // We probably need to do something here.
      57               0 :       return SkBitmap::kARGB_8888_Config;
      58                 :     case FORMAT_R5G6B5:
      59               0 :       return SkBitmap::kRGB_565_Config;
      60                 :     case FORMAT_A8:
      61               0 :       return SkBitmap::kA8_Config;
      62                 : 
      63                 :   }
      64                 : 
      65                 :   return SkBitmap::kARGB_8888_Config;
      66                 : }
      67                 : 
      68                 : static inline void
      69               0 : GfxMatrixToSkiaMatrix(const Matrix& mat, SkMatrix& retval)
      70                 : {
      71                 :     retval.setAll(SkFloatToScalar(mat._11), SkFloatToScalar(mat._21), SkFloatToScalar(mat._31),
      72                 :                   SkFloatToScalar(mat._12), SkFloatToScalar(mat._22), SkFloatToScalar(mat._32),
      73               0 :                   0, 0, SK_Scalar1);
      74               0 : }
      75                 : 
      76                 : static inline SkPaint::Cap
      77               0 : CapStyleToSkiaCap(CapStyle aCap)
      78                 : {
      79               0 :   switch (aCap)
      80                 :   {
      81                 :     case CAP_BUTT:
      82               0 :       return SkPaint::kButt_Cap;
      83                 :     case CAP_ROUND:
      84               0 :       return SkPaint::kRound_Cap;
      85                 :     case CAP_SQUARE:
      86               0 :       return SkPaint::kSquare_Cap;
      87                 :   }
      88               0 :   return SkPaint::kDefault_Cap;
      89                 : }
      90                 : 
      91                 : static inline SkPaint::Join
      92               0 : JoinStyleToSkiaJoin(JoinStyle aJoin)
      93                 : {
      94               0 :   switch (aJoin)
      95                 :   {
      96                 :     case JOIN_BEVEL:
      97               0 :       return SkPaint::kBevel_Join;
      98                 :     case JOIN_ROUND:
      99               0 :       return SkPaint::kRound_Join;
     100                 :     case JOIN_MITER:
     101                 :     case JOIN_MITER_OR_BEVEL:
     102               0 :       return SkPaint::kMiter_Join;
     103                 :   }
     104                 :   return SkPaint::kDefault_Join;
     105                 : }
     106                 : 
     107                 : static inline bool
     108               0 : StrokeOptionsToPaint(SkPaint& aPaint, const StrokeOptions &aOptions)
     109                 : {
     110                 :   // Skia rendewrs 0 width strokes with a width of 1 (and in black),
     111                 :   // so we should just skip the draw call entirely.
     112               0 :   if (!aOptions.mLineWidth) {
     113               0 :     return false;
     114                 :   }
     115               0 :   aPaint.setStrokeWidth(SkFloatToScalar(aOptions.mLineWidth));
     116               0 :   aPaint.setStrokeMiter(SkFloatToScalar(aOptions.mMiterLimit));
     117               0 :   aPaint.setStrokeCap(CapStyleToSkiaCap(aOptions.mLineCap));
     118               0 :   aPaint.setStrokeJoin(JoinStyleToSkiaJoin(aOptions.mLineJoin));
     119               0 :   if (aOptions.mDashLength > 1) {
     120               0 :     std::vector<SkScalar> pattern;
     121               0 :     pattern.resize(aOptions.mDashLength);
     122               0 :     for (uint32_t i = 0; i < aOptions.mDashLength; i++) {
     123               0 :       pattern[i] = SkFloatToScalar(aOptions.mDashPattern[i]);
     124                 :     }
     125                 :     
     126                 :     SkDashPathEffect* dash = new SkDashPathEffect(&pattern.front(), 
     127                 :                                                   aOptions.mDashLength, 
     128               0 :                                                   SkFloatToScalar(aOptions.mDashOffset));
     129               0 :     SkSafeUnref(aPaint.setPathEffect(dash));
     130                 :   }
     131               0 :   aPaint.setStyle(SkPaint::kStroke_Style);
     132               0 :   return true;
     133                 : }
     134                 : 
     135                 : }
     136                 : }
     137                 : 
     138                 : #endif /* MOZILLA_GFX_HELPERSSKIA_H_ */

Generated by: LCOV version 1.7