blob: b4bbaf970cecb2c7f1e5e1f9fe8d8bece2df111d [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
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000021void SkPixelXorXfermode::flatten(SkFlattenableWriteBuffer& wb) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000022 this->INHERITED::flatten(wb);
23 wb.write32(fOpColor);
24}
25
26SkPixelXorXfermode::SkPixelXorXfermode(SkFlattenableReadBuffer& rb)
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000027 : SkXfermode(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)