Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: Source/core/platform/graphics/skia/SkiaUtils.cpp

Issue 13637006: Add canvas blending modes under a runtime flag (Closed) Base URL: http://src.chromium.org/blink/trunk/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved. 2 * Copyright (c) 2006,2007,2008, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 { CompositeSourceAtop, SkXfermode::kSrcATop_Mode }, 54 { CompositeSourceAtop, SkXfermode::kSrcATop_Mode },
55 { CompositeDestinationOver, SkXfermode::kDstOver_Mode }, 55 { CompositeDestinationOver, SkXfermode::kDstOver_Mode },
56 { CompositeDestinationIn, SkXfermode::kDstIn_Mode }, 56 { CompositeDestinationIn, SkXfermode::kDstIn_Mode },
57 { CompositeDestinationOut, SkXfermode::kDstOut_Mode }, 57 { CompositeDestinationOut, SkXfermode::kDstOut_Mode },
58 { CompositeDestinationAtop, SkXfermode::kDstATop_Mode }, 58 { CompositeDestinationAtop, SkXfermode::kDstATop_Mode },
59 { CompositeXOR, SkXfermode::kXor_Mode }, 59 { CompositeXOR, SkXfermode::kXor_Mode },
60 { CompositePlusDarker, SkXfermode::kDarken_Mode }, 60 { CompositePlusDarker, SkXfermode::kDarken_Mode },
61 { CompositePlusLighter, SkXfermode::kPlus_Mode } 61 { CompositePlusLighter, SkXfermode::kPlus_Mode }
62 }; 62 };
63 63
64 SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op) 64 // keep this array in sync with BlendMode enum in GraphicsTypes.h
eseidel 2013/05/08 19:34:44 We can COMPILE_ASSERT That these match, no?
rosca 2013/05/08 21:37:17 Yes, we can compile_assert, but I'm not sure it wo
65 static const uint8_t gMapBlendOpsToXfermodeModes[] = {
66 SkXfermode::kClear_Mode, // BlendModeNormal
67 SkXfermode::kMultiply_Mode, // BlendModeMultiply
68 SkXfermode::kScreen_Mode, // BlendModeScreen
69 SkXfermode::kOverlay_Mode, // BlendModeOverlay
70 SkXfermode::kDarken_Mode, // BlendModeDarken
71 SkXfermode::kLighten_Mode, // BlendModeLighten
72 SkXfermode::kColorDodge_Mode, // BlendModeColorDodge
73 SkXfermode::kColorBurn_Mode, // BlendModeColorBurn
74 SkXfermode::kHardLight_Mode, // BlendModeHardLight
75 SkXfermode::kSoftLight_Mode, // BlendModeSoftLight
76 SkXfermode::kDifference_Mode, // BlendModeDifference
77 SkXfermode::kExclusion_Mode, // BlendModeExclusion
78 SkXfermode::kHue_Mode, // BlendModeHue
79 SkXfermode::kSaturation_Mode, // BlendModeSaturation
80 SkXfermode::kColor_Mode, // BlendModeColor
81 SkXfermode::kLuminosity_Mode // BlendModeLuminosity
82 };
83
84 SkXfermode::Mode WebCoreCompositeToSkiaComposite(CompositeOperator op, BlendMode blendMode)
65 { 85 {
86 if (blendMode != BlendModeNormal) {
87 if ((uint8_t)blendMode >= SK_ARRAY_COUNT(gMapBlendOpsToXfermodeModes)) {
88 SkDEBUGF(("GraphicsContext::setPlatformCompositeOperation unknown Bl endMode %d\n", blendMode));
89 return SkXfermode::kSrcOver_Mode;
90 }
91 return (SkXfermode::Mode)gMapBlendOpsToXfermodeModes[(uint8_t)blendMode] ;
92 }
93
66 const CompositOpToXfermodeMode* table = gMapCompositOpsToXfermodeModes; 94 const CompositOpToXfermodeMode* table = gMapCompositOpsToXfermodeModes;
67 95
68 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMapCompositOpsToXfermodeModes); i++ ) { 96 for (unsigned i = 0; i < SK_ARRAY_COUNT(gMapCompositOpsToXfermodeModes); i++ ) {
69 if (table[i].mCompositOp == op) 97 if (table[i].mCompositOp == op)
70 return (SkXfermode::Mode)table[i].m_xfermodeMode; 98 return (SkXfermode::Mode)table[i].m_xfermodeMode;
71 } 99 }
72 100
73 SkDEBUGF(("GraphicsContext::setPlatformCompositeOperation unknown CompositeO perator %d\n", op)); 101 SkDEBUGF(("GraphicsContext::setPlatformCompositeOperation unknown CompositeO perator %d\n", op));
74 return SkXfermode::kSrcOver_Mode; // fall-back 102 return SkXfermode::kSrcOver_Mode; // fall-back
75 } 103 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 188
161 GraphicsContext* scratchContext() 189 GraphicsContext* scratchContext()
162 { 190 {
163 static ImageBuffer* scratch = ImageBuffer::create(IntSize(1, 1)).leakPtr(); 191 static ImageBuffer* scratch = ImageBuffer::create(IntSize(1, 1)).leakPtr();
164 // We don't bother checking for failure creating the ImageBuffer, since our 192 // We don't bother checking for failure creating the ImageBuffer, since our
165 // ImageBuffer initializer won't fail. 193 // ImageBuffer initializer won't fail.
166 return scratch->context(); 194 return scratch->context();
167 } 195 }
168 196
169 } // namespace WebCore 197 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698