blob: dab4ebd05905f346db2086a37e21fdbbb58dfb5f [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"
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000012#include "SkFlattenableBuffers.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013
14// we always return an opaque color, 'cause I don't know what to do with
15// the alpha-component and still return a valid premultiplied color.
mike@reedtribe.org61490fa2012-12-24 14:38:46 +000016SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000017 SkPMColor res = src ^ dst ^ fOpColor;
18 res |= (SK_A32_MASK << SK_A32_SHIFT); // force it to be opaque
19 return res;
20}
21
djsollen@google.com54924242012-03-29 15:18:04 +000022void SkPixelXorXfermode::flatten(SkFlattenableWriteBuffer& wb) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 this->INHERITED::flatten(wb);
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000024 wb.writeColor(fOpColor);
reed@android.com8a1c16f2008-12-17 15:59:43 +000025}
26
27SkPixelXorXfermode::SkPixelXorXfermode(SkFlattenableReadBuffer& rb)
djsollen@google.com54924242012-03-29 15:18:04 +000028 : INHERITED(rb) {
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000029 fOpColor = rb.readColor();
reed@android.com8a1c16f2008-12-17 15:59:43 +000030}