blob: 129f1823d5fc4c6e1220f0c347ba1339fd4c3ca8 [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"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000012#include "SkReadBuffer.h"
13#include "SkWriteBuffer.h"
robertphillips@google.comb83b6b42013-01-22 14:32:09 +000014#include "SkString.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015
16// we always return an opaque color, 'cause I don't know what to do with
17// the alpha-component and still return a valid premultiplied color.
mike@reedtribe.org61490fa2012-12-24 14:38:46 +000018SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000019 SkPMColor res = src ^ dst ^ fOpColor;
20 res |= (SK_A32_MASK << SK_A32_SHIFT); // force it to be opaque
21 return res;
22}
23
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000024void SkPixelXorXfermode::flatten(SkWriteBuffer& wb) const {
reed@android.com8a1c16f2008-12-17 15:59:43 +000025 this->INHERITED::flatten(wb);
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000026 wb.writeColor(fOpColor);
reed@android.com8a1c16f2008-12-17 15:59:43 +000027}
28
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +000029SkPixelXorXfermode::SkPixelXorXfermode(SkReadBuffer& rb)
djsollen@google.com54924242012-03-29 15:18:04 +000030 : INHERITED(rb) {
djsollen@google.comc73dd5c2012-08-07 15:54:32 +000031 fOpColor = rb.readColor();
reed@android.com8a1c16f2008-12-17 15:59:43 +000032}
robertphillips@google.comb83b6b42013-01-22 14:32:09 +000033
commit-bot@chromium.org0f10f7b2014-03-13 18:02:17 +000034#ifndef SK_IGNORE_TO_STRING
robertphillips@google.comb83b6b42013-01-22 14:32:09 +000035void SkPixelXorXfermode::toString(SkString* str) const {
36 str->append("SkPixelXorXfermode: ");
37 str->appendHex(fOpColor);
38}
39#endif