blob: f4a74eebc5ce656d7aef8d78aa6fcd7db414a21b [file] [log] [blame]
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +00001/*
2 Copyright 2011 Google Inc.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
reed@android.com8a1c16f2008-12-17 15:59:43 +000017#include "SkPixelXorXfermode.h"
18#include "SkColorPriv.h"
19
20// we always return an opaque color, 'cause I don't know what to do with
21// the alpha-component and still return a valid premultiplied color.
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000022SkPMColor SkPixelXorXfermode::xferColor(SkPMColor src, SkPMColor dst) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023 SkPMColor res = src ^ dst ^ fOpColor;
24 res |= (SK_A32_MASK << SK_A32_SHIFT); // force it to be opaque
25 return res;
26}
27
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000028void SkPixelXorXfermode::flatten(SkFlattenableWriteBuffer& wb) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000029 this->INHERITED::flatten(wb);
30 wb.write32(fOpColor);
31}
32
33SkPixelXorXfermode::SkPixelXorXfermode(SkFlattenableReadBuffer& rb)
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000034 : SkXfermode(rb) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 fOpColor = rb.readU32();
36}
37
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000038SkFlattenable::Factory SkPixelXorXfermode::getFactory() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000039 return Create;
40}
41
mike@reedtribe.org3334c3a2011-04-20 11:39:28 +000042SkFlattenable* SkPixelXorXfermode::Create(SkFlattenableReadBuffer& rb) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000043 return SkNEW_ARGS(SkPixelXorXfermode, (rb));
44}
45
tomhudson@google.com1447c6f2011-04-27 14:09:52 +000046static SkFlattenable::Registrar
47 gSkPixelXorXfermodeReg("SkPixelXorXfermode",
48 SkPixelXorXfermode::CreateProc);