-
Notifications
You must be signed in to change notification settings - Fork 33
Description
Refer to https://www.x.org/releases/current/doc/xproto/x11protocol.html#requests:CreateGC .
With function and plane-mask on CreateGC, client can tell server to draw with bitwise operations:
((src FUNC dst) AND plane-mask) OR (dst AND (NOT plane-mask))
| Function | Operation |
|---|---|
| Clear | 0 |
| And | src AND dst |
| AndReverse | src AND (NOT dst) |
| Copy | src |
| AndInverted | (NOT src) AND dst |
| NoOp | dst |
| Xor | src XOR dst |
| Or | src OR dst |
| Nor | (NOT src) AND (NOT dst) |
| Equiv | (NOT src) XOR dst |
| Invert | NOT dst |
| OrReverse | src OR (NOT dst) |
| CopyInverted | NOT src |
| OrInverted | (NOT src) OR dst |
| Nand | (NOT src) OR (NOT dst) |
| Set | 1 |
I failed to find an efficient way to implement these bitwise operation after spending many hours. I think it might be difficult to implement a paint with bitwise Xfermode. As a result, it is hard to draw via methods of canvas.
TL;DR:
Android doesn't have bitwise Xfermode now. PixelXorXfermode has been removed, and Xfermode has only one subclass PorterDuffXfermode now, which has no bitwise operation, and PorterDuff.Mode.XOR is xor operation for area but not for color, which is misused in
| _paint.setXfermode(new PorterDuffXfermode(Mode.XOR)); |
I tried to write our own Xfermode subclass, so that we can still use methods of canvas to draw. But finally found that Paint uses native code and hardcodes PorterDuffXfermode, even if Paint.setXfermode accepts Xfermode.
ColorMatrixColorFilter can be used to implement bitwise NOT on src but not dst.