LCOV - code coverage report
Current view: directory - gfx/2d - HelpersCairo.h (source / functions) Found Hit Coverage
Test: app.info Lines: 74 0 0.0 %
Date: 2012-06-02 Functions: 11 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                 :  *
      23                 :  * Alternatively, the contents of this file may be used under the terms of
      24                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      25                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      26                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      27                 :  * of those above. If you wish to allow use of your version of this file only
      28                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      29                 :  * use your version of this file under the terms of the MPL, indicate your
      30                 :  * decision by deleting the provisions above and replace them with the notice
      31                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      32                 :  * the provisions above, a recipient may use your version of this file under
      33                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      34                 :  *
      35                 :  * ***** END LICENSE BLOCK ***** */
      36                 : 
      37                 : #ifndef MOZILLA_GFX_HELPERSCAIRO_H_
      38                 : #define MOZILLA_GFX_HELPERSCAIRO_H_
      39                 : 
      40                 : #include "2D.h"
      41                 : #include "cairo.h"
      42                 : 
      43                 : namespace mozilla {
      44                 : namespace gfx {
      45                 : 
      46                 : static inline cairo_operator_t
      47               0 : GfxOpToCairoOp(CompositionOp op)
      48                 : {
      49               0 :   switch (op)
      50                 :   {
      51                 :     case OP_OVER:
      52               0 :       return CAIRO_OPERATOR_OVER;
      53                 :     case OP_ADD:
      54               0 :       return CAIRO_OPERATOR_ADD;
      55                 :     case OP_ATOP:
      56               0 :       return CAIRO_OPERATOR_ATOP;
      57                 :     case OP_OUT:
      58               0 :       return CAIRO_OPERATOR_OUT;
      59                 :     case OP_IN:
      60               0 :       return CAIRO_OPERATOR_IN;
      61                 :     case OP_SOURCE:
      62               0 :       return CAIRO_OPERATOR_SOURCE;
      63                 :     case OP_DEST_IN:
      64               0 :       return CAIRO_OPERATOR_DEST_IN;
      65                 :     case OP_DEST_OUT:
      66               0 :       return CAIRO_OPERATOR_DEST_OUT;
      67                 :     case OP_DEST_OVER:
      68               0 :       return CAIRO_OPERATOR_DEST_OVER;
      69                 :     case OP_DEST_ATOP:
      70               0 :       return CAIRO_OPERATOR_DEST_ATOP;
      71                 :     case OP_XOR:
      72               0 :       return CAIRO_OPERATOR_XOR;
      73                 :     case OP_COUNT:
      74               0 :       break;
      75                 :   }
      76                 : 
      77               0 :   return CAIRO_OPERATOR_OVER;
      78                 : }
      79                 : 
      80                 : static inline cairo_filter_t
      81               0 : GfxFilterToCairoFilter(Filter filter)
      82                 : {
      83               0 :   switch (filter)
      84                 :   {
      85                 :     case FILTER_LINEAR:
      86               0 :       return CAIRO_FILTER_BILINEAR;
      87                 :     case FILTER_POINT:
      88               0 :       return CAIRO_FILTER_NEAREST;
      89                 :   }
      90                 : 
      91                 :   return CAIRO_FILTER_BILINEAR;
      92                 : }
      93                 : 
      94                 : static inline cairo_extend_t
      95               0 : GfxExtendToCairoExtend(ExtendMode extend)
      96                 : {
      97               0 :   switch (extend)
      98                 :   {
      99                 :     case EXTEND_CLAMP:
     100               0 :       return CAIRO_EXTEND_PAD;
     101                 :     case EXTEND_REPEAT:
     102               0 :       return CAIRO_EXTEND_REPEAT;
     103                 :     case EXTEND_REFLECT:
     104               0 :       return CAIRO_EXTEND_REFLECT;
     105                 :   }
     106                 : 
     107               0 :   return CAIRO_EXTEND_PAD;
     108                 : }
     109                 : 
     110                 : static inline cairo_format_t
     111               0 : GfxFormatToCairoFormat(SurfaceFormat format)
     112                 : {
     113               0 :   switch (format)
     114                 :   {
     115                 :     case FORMAT_B8G8R8A8:
     116               0 :       return CAIRO_FORMAT_ARGB32;
     117                 :     case FORMAT_B8G8R8X8:
     118               0 :       return CAIRO_FORMAT_RGB24;
     119                 :     case FORMAT_A8:
     120               0 :       return CAIRO_FORMAT_A8;
     121                 :     default:
     122               0 :       return CAIRO_FORMAT_ARGB32;
     123                 :   }
     124                 : }
     125                 : 
     126                 : static inline cairo_content_t
     127               0 : GfxFormatToCairoContent(SurfaceFormat format)
     128                 : {
     129               0 :   switch (format)
     130                 :   {
     131                 :     case FORMAT_B8G8R8A8:
     132               0 :       return CAIRO_CONTENT_COLOR_ALPHA;
     133                 :     case FORMAT_B8G8R8X8:
     134               0 :       return CAIRO_CONTENT_COLOR;
     135                 :     case FORMAT_A8:
     136               0 :       return CAIRO_CONTENT_ALPHA;
     137                 :     default:
     138               0 :       return CAIRO_CONTENT_COLOR_ALPHA;
     139                 :   }
     140                 : }
     141                 : 
     142                 : static inline cairo_line_join_t
     143               0 : GfxLineJoinToCairoLineJoin(JoinStyle style)
     144                 : {
     145               0 :   switch (style)
     146                 :   {
     147                 :     case JOIN_BEVEL:
     148               0 :       return CAIRO_LINE_JOIN_BEVEL;
     149                 :     case JOIN_ROUND:
     150               0 :       return CAIRO_LINE_JOIN_ROUND;
     151                 :     case JOIN_MITER:
     152               0 :       return CAIRO_LINE_JOIN_MITER;
     153                 :     case JOIN_MITER_OR_BEVEL:
     154               0 :       return CAIRO_LINE_JOIN_MITER;
     155                 :   }
     156                 : 
     157                 :   return CAIRO_LINE_JOIN_MITER;
     158                 : }
     159                 : 
     160                 : static inline cairo_line_cap_t
     161               0 : GfxLineCapToCairoLineCap(CapStyle style)
     162                 : {
     163               0 :   switch (style)
     164                 :   {
     165                 :     case CAP_BUTT:
     166               0 :       return CAIRO_LINE_CAP_BUTT;
     167                 :     case CAP_ROUND:
     168               0 :       return CAIRO_LINE_CAP_ROUND;
     169                 :     case CAP_SQUARE:
     170               0 :       return CAIRO_LINE_CAP_SQUARE;
     171                 :   }
     172                 : 
     173               0 :   return CAIRO_LINE_CAP_BUTT;
     174                 : }
     175                 : 
     176                 : static inline SurfaceFormat
     177               0 : CairoContentToGfxFormat(cairo_content_t content)
     178                 : {
     179               0 :   switch (content)
     180                 :   {
     181                 :     case CAIRO_CONTENT_COLOR_ALPHA:
     182               0 :       return FORMAT_B8G8R8A8;
     183                 :     case CAIRO_CONTENT_COLOR:
     184               0 :       return FORMAT_B8G8R8X8;
     185                 :     case CAIRO_CONTENT_ALPHA:
     186               0 :       return FORMAT_A8;
     187                 :   }
     188                 : 
     189               0 :   return FORMAT_B8G8R8A8;
     190                 : }
     191                 : 
     192                 : static inline void
     193               0 : GfxMatrixToCairoMatrix(const Matrix& mat, cairo_matrix_t& retval)
     194                 : {
     195               0 :   cairo_matrix_init(&retval, mat._11, mat._12, mat._21, mat._22, mat._31, mat._32);
     196               0 : }
     197                 : 
     198                 : static inline void
     199               0 : SetCairoStrokeOptions(cairo_t* aCtx, const StrokeOptions& aStrokeOptions)
     200                 : {
     201               0 :   cairo_set_line_width(aCtx, aStrokeOptions.mLineWidth);
     202                 : 
     203               0 :   cairo_set_miter_limit(aCtx, aStrokeOptions.mMiterLimit);
     204                 : 
     205               0 :   if (aStrokeOptions.mDashPattern) {
     206                 :     // Convert array of floats to array of doubles
     207               0 :     std::vector<double> dashes(aStrokeOptions.mDashLength);
     208               0 :     for (size_t i = 0; i < aStrokeOptions.mDashLength; ++i) {
     209               0 :       dashes[i] = aStrokeOptions.mDashPattern[i];
     210                 :     }
     211               0 :     cairo_set_dash(aCtx, &dashes[0], aStrokeOptions.mDashLength,
     212               0 :                    aStrokeOptions.mDashOffset);
     213                 :   }
     214                 : 
     215               0 :   cairo_set_line_join(aCtx, GfxLineJoinToCairoLineJoin(aStrokeOptions.mLineJoin));
     216                 : 
     217               0 :   cairo_set_line_cap(aCtx, GfxLineCapToCairoLineCap(aStrokeOptions.mLineCap));
     218               0 : }
     219                 : 
     220                 : static inline cairo_fill_rule_t
     221               0 : GfxFillRuleToCairoFillRule(FillRule rule)
     222                 : {
     223               0 :   switch (rule)
     224                 :   {
     225                 :     case FILL_WINDING:
     226               0 :       return CAIRO_FILL_RULE_WINDING;
     227                 :     case FILL_EVEN_ODD:
     228               0 :       return CAIRO_FILL_RULE_EVEN_ODD;
     229                 :   }
     230                 : 
     231                 :   return CAIRO_FILL_RULE_WINDING;
     232                 : }
     233                 : 
     234                 : }
     235                 : }
     236                 : 
     237                 : #endif /* MOZILLA_GFX_HELPERSCAIRO_H_ */

Generated by: LCOV version 1.7