blob: 7b58ed76a8c6128dedae995920d15c36ca808797 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkPixelXorXfermode.h"
11#include "SkColorPriv.h"
12
13// we always return an opaque color, 'cause I don't know what to do with
14// the alpha-component and still return a valid premultiplied color.
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000015SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000016 SkPMColor res = src ^ dst ^ fOpColor;
17 res |= (SK_A32_MASK << SK_A32_SHIFT); // force it to be opaque
18 return res;
19}
20
djsollen@google.com54924242012-03-29 15:18:04 +000021void SkPixelXorXfermode::flatten(SkFlattenableWriteBuffer& wb) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 this->INHERITED::flatten(wb);
23 wb.write32(fOpColor);
24}
25
26SkPixelXorXfermode::SkPixelXorXfermode(SkFlattenableReadBuffer& rb)
djsollen@google.com54924242012-03-29 15:18:04 +000027 : INHERITED(rb) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000028 fOpColor = rb.readU32();
29}
30
caryclark@google.comd26147a2011-12-15 14:16:43 +000031SK_DEFINE_FLATTENABLE_REGISTRAR(SkPixelXorXfermode)