1
2/*
3 * 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.
7 */
8
9
10#include "SkPixelXorXfermode.h"
11#include "SkColorPriv.h"
12#include "SkReadBuffer.h"
13#include "SkWriteBuffer.h"
14#include "SkString.h"
15
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.
18SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) const {
19    SkPMColor res = src ^ dst ^ fOpColor;
20    res |= (SK_A32_MASK << SK_A32_SHIFT);   // force it to be opaque
21    return res;
22}
23
24void SkPixelXorXfermode::flatten(SkWriteBuffer& wb) const {
25    wb.writeColor(fOpColor);
26}
27
28#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
29SkPixelXorXfermode::SkPixelXorXfermode(SkReadBuffer& rb) : INHERITED(rb) {
30    fOpColor = rb.readColor();
31}
32#endif
33
34SkFlattenable* SkPixelXorXfermode::CreateProc(SkReadBuffer& buffer) {
35    return Create(buffer.readColor());
36}
37
38#ifndef SK_IGNORE_TO_STRING
39void SkPixelXorXfermode::toString(SkString* str) const {
40    str->append("SkPixelXorXfermode: ");
41    str->appendHex(fOpColor);
42}
43#endif
44