Use SkPMColor4f throughout clear APIs
Bug: skia:
Change-Id: I5386e27edbcf39233880d869841a6632ecb9416c
Reviewed-on: https://skia-review.googlesource.com/c/168261
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkColorData.h b/src/core/SkColorData.h
deleted file mode 100644
index b4d13fb..0000000
--- a/src/core/SkColorData.h
+++ /dev/null
@@ -1,557 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkColorData_DEFINED
-#define SkColorData_DEFINED
-
-#include "SkColor.h"
-#include "SkColorPriv.h"
-#include "SkNx.h"
-#include "SkTo.h"
-
-////////////////////////////////////////////////////////////////////////////////////////////
-// Convert a 16bit pixel to a 32bit pixel
-
-#define SK_R16_BITS 5
-#define SK_G16_BITS 6
-#define SK_B16_BITS 5
-
-#define SK_R16_SHIFT (SK_B16_BITS + SK_G16_BITS)
-#define SK_G16_SHIFT (SK_B16_BITS)
-#define SK_B16_SHIFT 0
-
-#define SK_R16_MASK ((1 << SK_R16_BITS) - 1)
-#define SK_G16_MASK ((1 << SK_G16_BITS) - 1)
-#define SK_B16_MASK ((1 << SK_B16_BITS) - 1)
-
-#define SkGetPackedR16(color) (((unsigned)(color) >> SK_R16_SHIFT) & SK_R16_MASK)
-#define SkGetPackedG16(color) (((unsigned)(color) >> SK_G16_SHIFT) & SK_G16_MASK)
-#define SkGetPackedB16(color) (((unsigned)(color) >> SK_B16_SHIFT) & SK_B16_MASK)
-
-static inline unsigned SkR16ToR32(unsigned r) {
- return (r << (8 - SK_R16_BITS)) | (r >> (2 * SK_R16_BITS - 8));
-}
-
-static inline unsigned SkG16ToG32(unsigned g) {
- return (g << (8 - SK_G16_BITS)) | (g >> (2 * SK_G16_BITS - 8));
-}
-
-static inline unsigned SkB16ToB32(unsigned b) {
- return (b << (8 - SK_B16_BITS)) | (b >> (2 * SK_B16_BITS - 8));
-}
-
-#define SkPacked16ToR32(c) SkR16ToR32(SkGetPackedR16(c))
-#define SkPacked16ToG32(c) SkG16ToG32(SkGetPackedG16(c))
-#define SkPacked16ToB32(c) SkB16ToB32(SkGetPackedB16(c))
-
-//////////////////////////////////////////////////////////////////////////////
-
-#define SkASSERT_IS_BYTE(x) SkASSERT(0 == ((x) & ~0xFF))
-
-// Reverse the bytes coorsponding to RED and BLUE in a packed pixels. Note the
-// pair of them are in the same 2 slots in both RGBA and BGRA, thus there is
-// no need to pass in the colortype to this function.
-static inline uint32_t SkSwizzle_RB(uint32_t c) {
- static const uint32_t kRBMask = (0xFF << SK_R32_SHIFT) | (0xFF << SK_B32_SHIFT);
-
- unsigned c0 = (c >> SK_R32_SHIFT) & 0xFF;
- unsigned c1 = (c >> SK_B32_SHIFT) & 0xFF;
- return (c & ~kRBMask) | (c0 << SK_B32_SHIFT) | (c1 << SK_R32_SHIFT);
-}
-
-static inline uint32_t SkPackARGB_as_RGBA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
- SkASSERT_IS_BYTE(a);
- SkASSERT_IS_BYTE(r);
- SkASSERT_IS_BYTE(g);
- SkASSERT_IS_BYTE(b);
- return (a << SK_RGBA_A32_SHIFT) | (r << SK_RGBA_R32_SHIFT) |
- (g << SK_RGBA_G32_SHIFT) | (b << SK_RGBA_B32_SHIFT);
-}
-
-static inline uint32_t SkPackARGB_as_BGRA(U8CPU a, U8CPU r, U8CPU g, U8CPU b) {
- SkASSERT_IS_BYTE(a);
- SkASSERT_IS_BYTE(r);
- SkASSERT_IS_BYTE(g);
- SkASSERT_IS_BYTE(b);
- return (a << SK_BGRA_A32_SHIFT) | (r << SK_BGRA_R32_SHIFT) |
- (g << SK_BGRA_G32_SHIFT) | (b << SK_BGRA_B32_SHIFT);
-}
-
-static inline SkPMColor SkSwizzle_RGBA_to_PMColor(uint32_t c) {
-#ifdef SK_PMCOLOR_IS_RGBA
- return c;
-#else
- return SkSwizzle_RB(c);
-#endif
-}
-
-static inline SkPMColor SkSwizzle_BGRA_to_PMColor(uint32_t c) {
-#ifdef SK_PMCOLOR_IS_BGRA
- return c;
-#else
- return SkSwizzle_RB(c);
-#endif
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-///@{
-/** See ITU-R Recommendation BT.709 at http://www.itu.int/rec/R-REC-BT.709/ .*/
-#define SK_ITU_BT709_LUM_COEFF_R (0.2126f)
-#define SK_ITU_BT709_LUM_COEFF_G (0.7152f)
-#define SK_ITU_BT709_LUM_COEFF_B (0.0722f)
-///@}
-
-///@{
-/** A float value which specifies this channel's contribution to luminance. */
-#define SK_LUM_COEFF_R SK_ITU_BT709_LUM_COEFF_R
-#define SK_LUM_COEFF_G SK_ITU_BT709_LUM_COEFF_G
-#define SK_LUM_COEFF_B SK_ITU_BT709_LUM_COEFF_B
-///@}
-
-/** Computes the luminance from the given r, g, and b in accordance with
- SK_LUM_COEFF_X. For correct results, r, g, and b should be in linear space.
-*/
-static inline U8CPU SkComputeLuminance(U8CPU r, U8CPU g, U8CPU b) {
- //The following is
- //r * SK_LUM_COEFF_R + g * SK_LUM_COEFF_G + b * SK_LUM_COEFF_B
- //with SK_LUM_COEFF_X in 1.8 fixed point (rounding adjusted to sum to 256).
- return (r * 54 + g * 183 + b * 19) >> 8;
-}
-
-/** Calculates 256 - (value * alpha256) / 255 in range [0,256],
- * for [0,255] value and [0,256] alpha256.
- */
-static inline U16CPU SkAlphaMulInv256(U16CPU value, U16CPU alpha256) {
- unsigned prod = 0xFFFF - value * alpha256;
- return (prod + (prod >> 8)) >> 8;
-}
-
-// The caller may want negative values, so keep all params signed (int)
-// so we don't accidentally slip into unsigned math and lose the sign
-// extension when we shift (in SkAlphaMul)
-static inline int SkAlphaBlend(int src, int dst, int scale256) {
- SkASSERT((unsigned)scale256 <= 256);
- return dst + SkAlphaMul(src - dst, scale256);
-}
-
-static inline uint16_t SkPackRGB16(unsigned r, unsigned g, unsigned b) {
- SkASSERT(r <= SK_R16_MASK);
- SkASSERT(g <= SK_G16_MASK);
- SkASSERT(b <= SK_B16_MASK);
-
- return SkToU16((r << SK_R16_SHIFT) | (g << SK_G16_SHIFT) | (b << SK_B16_SHIFT));
-}
-
-#define SK_R16_MASK_IN_PLACE (SK_R16_MASK << SK_R16_SHIFT)
-#define SK_G16_MASK_IN_PLACE (SK_G16_MASK << SK_G16_SHIFT)
-#define SK_B16_MASK_IN_PLACE (SK_B16_MASK << SK_B16_SHIFT)
-
-///////////////////////////////////////////////////////////////////////////////
-
-/**
- * Abstract 4-byte interpolation, implemented on top of SkPMColor
- * utility functions. Third parameter controls blending of the first two:
- * (src, dst, 0) returns dst
- * (src, dst, 0xFF) returns src
- * srcWeight is [0..256], unlike SkFourByteInterp which takes [0..255]
- */
-static inline SkPMColor SkFourByteInterp256(SkPMColor src, SkPMColor dst,
- unsigned scale) {
- unsigned a = SkAlphaBlend(SkGetPackedA32(src), SkGetPackedA32(dst), scale);
- unsigned r = SkAlphaBlend(SkGetPackedR32(src), SkGetPackedR32(dst), scale);
- unsigned g = SkAlphaBlend(SkGetPackedG32(src), SkGetPackedG32(dst), scale);
- unsigned b = SkAlphaBlend(SkGetPackedB32(src), SkGetPackedB32(dst), scale);
-
- return SkPackARGB32(a, r, g, b);
-}
-
-/**
- * Abstract 4-byte interpolation, implemented on top of SkPMColor
- * utility functions. Third parameter controls blending of the first two:
- * (src, dst, 0) returns dst
- * (src, dst, 0xFF) returns src
- */
-static inline SkPMColor SkFourByteInterp(SkPMColor src, SkPMColor dst,
- U8CPU srcWeight) {
- unsigned scale = SkAlpha255To256(srcWeight);
- return SkFourByteInterp256(src, dst, scale);
-}
-
-/**
- * 0xAARRGGBB -> 0x00AA00GG, 0x00RR00BB
- */
-static inline void SkSplay(uint32_t color, uint32_t* ag, uint32_t* rb) {
- const uint32_t mask = 0x00FF00FF;
- *ag = (color >> 8) & mask;
- *rb = color & mask;
-}
-
-/**
- * 0xAARRGGBB -> 0x00AA00GG00RR00BB
- * (note, ARGB -> AGRB)
- */
-static inline uint64_t SkSplay(uint32_t color) {
- const uint32_t mask = 0x00FF00FF;
- uint64_t agrb = (color >> 8) & mask; // 0x0000000000AA00GG
- agrb <<= 32; // 0x00AA00GG00000000
- agrb |= color & mask; // 0x00AA00GG00RR00BB
- return agrb;
-}
-
-/**
- * 0xAAxxGGxx, 0xRRxxBBxx-> 0xAARRGGBB
- */
-static inline uint32_t SkUnsplay(uint32_t ag, uint32_t rb) {
- const uint32_t mask = 0xFF00FF00;
- return (ag & mask) | ((rb & mask) >> 8);
-}
-
-/**
- * 0xAAxxGGxxRRxxBBxx -> 0xAARRGGBB
- * (note, AGRB -> ARGB)
- */
-static inline uint32_t SkUnsplay(uint64_t agrb) {
- const uint32_t mask = 0xFF00FF00;
- return SkPMColor(
- ((agrb & mask) >> 8) | // 0x00RR00BB
- ((agrb >> 32) & mask)); // 0xAARRGGBB
-}
-
-static inline SkPMColor SkFastFourByteInterp256_32(SkPMColor src, SkPMColor dst, unsigned scale) {
- SkASSERT(scale <= 256);
-
- // Two 8-bit blends per two 32-bit registers, with space to make sure the math doesn't collide.
- uint32_t src_ag, src_rb, dst_ag, dst_rb;
- SkSplay(src, &src_ag, &src_rb);
- SkSplay(dst, &dst_ag, &dst_rb);
-
- const uint32_t ret_ag = src_ag * scale + (256 - scale) * dst_ag;
- const uint32_t ret_rb = src_rb * scale + (256 - scale) * dst_rb;
-
- return SkUnsplay(ret_ag, ret_rb);
-}
-
-static inline SkPMColor SkFastFourByteInterp256_64(SkPMColor src, SkPMColor dst, unsigned scale) {
- SkASSERT(scale <= 256);
- // Four 8-bit blends in one 64-bit register, with space to make sure the math doesn't collide.
- return SkUnsplay(SkSplay(src) * scale + (256-scale) * SkSplay(dst));
-}
-
-// TODO(mtklein): Replace slow versions with fast versions, using scale + (scale>>7) everywhere.
-
-/**
- * Same as SkFourByteInterp256, but faster.
- */
-static inline SkPMColor SkFastFourByteInterp256(SkPMColor src, SkPMColor dst, unsigned scale) {
- // On a 64-bit machine, _64 is about 10% faster than _32, but ~40% slower on a 32-bit machine.
- if (sizeof(void*) == 4) {
- return SkFastFourByteInterp256_32(src, dst, scale);
- } else {
- return SkFastFourByteInterp256_64(src, dst, scale);
- }
-}
-
-/**
- * Nearly the same as SkFourByteInterp, but faster and a touch more accurate, due to better
- * srcWeight scaling to [0, 256].
- */
-static inline SkPMColor SkFastFourByteInterp(SkPMColor src,
- SkPMColor dst,
- U8CPU srcWeight) {
- SkASSERT(srcWeight <= 255);
- // scale = srcWeight + (srcWeight >> 7) is more accurate than
- // scale = srcWeight + 1, but 7% slower
- return SkFastFourByteInterp256(src, dst, srcWeight + (srcWeight >> 7));
-}
-
-/**
- * Interpolates between colors src and dst using [0,256] scale.
- */
-static inline SkPMColor SkPMLerp(SkPMColor src, SkPMColor dst, unsigned scale) {
- return SkFastFourByteInterp256(src, dst, scale);
-}
-
-static inline SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa) {
- SkASSERT((unsigned)aa <= 255);
-
- unsigned src_scale = SkAlpha255To256(aa);
- unsigned dst_scale = SkAlphaMulInv256(SkGetPackedA32(src), src_scale);
-
- const uint32_t mask = 0xFF00FF;
-
- uint32_t src_rb = (src & mask) * src_scale;
- uint32_t src_ag = ((src >> 8) & mask) * src_scale;
-
- uint32_t dst_rb = (dst & mask) * dst_scale;
- uint32_t dst_ag = ((dst >> 8) & mask) * dst_scale;
-
- return (((src_rb + dst_rb) >> 8) & mask) | ((src_ag + dst_ag) & ~mask);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////
-// Convert a 32bit pixel to a 16bit pixel (no dither)
-
-#define SkR32ToR16_MACRO(r) ((unsigned)(r) >> (SK_R32_BITS - SK_R16_BITS))
-#define SkG32ToG16_MACRO(g) ((unsigned)(g) >> (SK_G32_BITS - SK_G16_BITS))
-#define SkB32ToB16_MACRO(b) ((unsigned)(b) >> (SK_B32_BITS - SK_B16_BITS))
-
-#ifdef SK_DEBUG
- static inline unsigned SkR32ToR16(unsigned r) {
- SkR32Assert(r);
- return SkR32ToR16_MACRO(r);
- }
- static inline unsigned SkG32ToG16(unsigned g) {
- SkG32Assert(g);
- return SkG32ToG16_MACRO(g);
- }
- static inline unsigned SkB32ToB16(unsigned b) {
- SkB32Assert(b);
- return SkB32ToB16_MACRO(b);
- }
-#else
- #define SkR32ToR16(r) SkR32ToR16_MACRO(r)
- #define SkG32ToG16(g) SkG32ToG16_MACRO(g)
- #define SkB32ToB16(b) SkB32ToB16_MACRO(b)
-#endif
-
-static inline U16CPU SkPixel32ToPixel16(SkPMColor c) {
- unsigned r = ((c >> (SK_R32_SHIFT + (8 - SK_R16_BITS))) & SK_R16_MASK) << SK_R16_SHIFT;
- unsigned g = ((c >> (SK_G32_SHIFT + (8 - SK_G16_BITS))) & SK_G16_MASK) << SK_G16_SHIFT;
- unsigned b = ((c >> (SK_B32_SHIFT + (8 - SK_B16_BITS))) & SK_B16_MASK) << SK_B16_SHIFT;
- return r | g | b;
-}
-
-static inline U16CPU SkPack888ToRGB16(U8CPU r, U8CPU g, U8CPU b) {
- return (SkR32ToR16(r) << SK_R16_SHIFT) |
- (SkG32ToG16(g) << SK_G16_SHIFT) |
- (SkB32ToB16(b) << SK_B16_SHIFT);
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
-/* SrcOver the 32bit src color with the 16bit dst, returning a 16bit value
- (with dirt in the high 16bits, so caller beware).
-*/
-static inline U16CPU SkSrcOver32To16(SkPMColor src, uint16_t dst) {
- unsigned sr = SkGetPackedR32(src);
- unsigned sg = SkGetPackedG32(src);
- unsigned sb = SkGetPackedB32(src);
-
- unsigned dr = SkGetPackedR16(dst);
- unsigned dg = SkGetPackedG16(dst);
- unsigned db = SkGetPackedB16(dst);
-
- unsigned isa = 255 - SkGetPackedA32(src);
-
- dr = (sr + SkMul16ShiftRound(dr, isa, SK_R16_BITS)) >> (8 - SK_R16_BITS);
- dg = (sg + SkMul16ShiftRound(dg, isa, SK_G16_BITS)) >> (8 - SK_G16_BITS);
- db = (sb + SkMul16ShiftRound(db, isa, SK_B16_BITS)) >> (8 - SK_B16_BITS);
-
- return SkPackRGB16(dr, dg, db);
-}
-
-static inline SkColor SkPixel16ToColor(U16CPU src) {
- SkASSERT(src == SkToU16(src));
-
- unsigned r = SkPacked16ToR32(src);
- unsigned g = SkPacked16ToG32(src);
- unsigned b = SkPacked16ToB32(src);
-
- SkASSERT((r >> (8 - SK_R16_BITS)) == SkGetPackedR16(src));
- SkASSERT((g >> (8 - SK_G16_BITS)) == SkGetPackedG16(src));
- SkASSERT((b >> (8 - SK_B16_BITS)) == SkGetPackedB16(src));
-
- return SkColorSetRGB(r, g, b);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-typedef uint16_t SkPMColor16;
-
-// Put in OpenGL order (r g b a)
-#define SK_A4444_SHIFT 0
-#define SK_R4444_SHIFT 12
-#define SK_G4444_SHIFT 8
-#define SK_B4444_SHIFT 4
-
-static inline U8CPU SkReplicateNibble(unsigned nib) {
- SkASSERT(nib <= 0xF);
- return (nib << 4) | nib;
-}
-
-#define SkGetPackedA4444(c) (((unsigned)(c) >> SK_A4444_SHIFT) & 0xF)
-#define SkGetPackedR4444(c) (((unsigned)(c) >> SK_R4444_SHIFT) & 0xF)
-#define SkGetPackedG4444(c) (((unsigned)(c) >> SK_G4444_SHIFT) & 0xF)
-#define SkGetPackedB4444(c) (((unsigned)(c) >> SK_B4444_SHIFT) & 0xF)
-
-#define SkPacked4444ToA32(c) SkReplicateNibble(SkGetPackedA4444(c))
-
-static inline SkPMColor SkPixel4444ToPixel32(U16CPU c) {
- uint32_t d = (SkGetPackedA4444(c) << SK_A32_SHIFT) |
- (SkGetPackedR4444(c) << SK_R32_SHIFT) |
- (SkGetPackedG4444(c) << SK_G32_SHIFT) |
- (SkGetPackedB4444(c) << SK_B32_SHIFT);
- return d | (d << 4);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-static inline int SkUpscale31To32(int value) {
- SkASSERT((unsigned)value <= 31);
- return value + (value >> 4);
-}
-
-static inline int SkBlend32(int src, int dst, int scale) {
- SkASSERT((unsigned)src <= 0xFF);
- SkASSERT((unsigned)dst <= 0xFF);
- SkASSERT((unsigned)scale <= 32);
- return dst + ((src - dst) * scale >> 5);
-}
-
-static inline SkPMColor SkBlendLCD16(int srcA, int srcR, int srcG, int srcB,
- SkPMColor dst, uint16_t mask) {
- if (mask == 0) {
- return dst;
- }
-
- /* We want all of these in 5bits, hence the shifts in case one of them
- * (green) is 6bits.
- */
- int maskR = SkGetPackedR16(mask) >> (SK_R16_BITS - 5);
- int maskG = SkGetPackedG16(mask) >> (SK_G16_BITS - 5);
- int maskB = SkGetPackedB16(mask) >> (SK_B16_BITS - 5);
-
- // Now upscale them to 0..32, so we can use blend32
- maskR = SkUpscale31To32(maskR);
- maskG = SkUpscale31To32(maskG);
- maskB = SkUpscale31To32(maskB);
-
- // srcA has been upscaled to 256 before passed into this function
- maskR = maskR * srcA >> 8;
- maskG = maskG * srcA >> 8;
- maskB = maskB * srcA >> 8;
-
- int dstR = SkGetPackedR32(dst);
- int dstG = SkGetPackedG32(dst);
- int dstB = SkGetPackedB32(dst);
-
- // LCD blitting is only supported if the dst is known/required
- // to be opaque
- return SkPackARGB32(0xFF,
- SkBlend32(srcR, dstR, maskR),
- SkBlend32(srcG, dstG, maskG),
- SkBlend32(srcB, dstB, maskB));
-}
-
-static inline SkPMColor SkBlendLCD16Opaque(int srcR, int srcG, int srcB,
- SkPMColor dst, uint16_t mask,
- SkPMColor opaqueDst) {
- if (mask == 0) {
- return dst;
- }
-
- if (0xFFFF == mask) {
- return opaqueDst;
- }
-
- /* We want all of these in 5bits, hence the shifts in case one of them
- * (green) is 6bits.
- */
- int maskR = SkGetPackedR16(mask) >> (SK_R16_BITS - 5);
- int maskG = SkGetPackedG16(mask) >> (SK_G16_BITS - 5);
- int maskB = SkGetPackedB16(mask) >> (SK_B16_BITS - 5);
-
- // Now upscale them to 0..32, so we can use blend32
- maskR = SkUpscale31To32(maskR);
- maskG = SkUpscale31To32(maskG);
- maskB = SkUpscale31To32(maskB);
-
- int dstR = SkGetPackedR32(dst);
- int dstG = SkGetPackedG32(dst);
- int dstB = SkGetPackedB32(dst);
-
- // LCD blitting is only supported if the dst is known/required
- // to be opaque
- return SkPackARGB32(0xFF,
- SkBlend32(srcR, dstR, maskR),
- SkBlend32(srcG, dstG, maskG),
- SkBlend32(srcB, dstB, maskB));
-}
-
-static inline void SkBlitLCD16Row(SkPMColor dst[], const uint16_t mask[],
- SkColor src, int width, SkPMColor) {
- int srcA = SkColorGetA(src);
- int srcR = SkColorGetR(src);
- int srcG = SkColorGetG(src);
- int srcB = SkColorGetB(src);
-
- srcA = SkAlpha255To256(srcA);
-
- for (int i = 0; i < width; i++) {
- dst[i] = SkBlendLCD16(srcA, srcR, srcG, srcB, dst[i], mask[i]);
- }
-}
-
-static inline void SkBlitLCD16OpaqueRow(SkPMColor dst[], const uint16_t mask[],
- SkColor src, int width,
- SkPMColor opaqueDst) {
- int srcR = SkColorGetR(src);
- int srcG = SkColorGetG(src);
- int srcB = SkColorGetB(src);
-
- for (int i = 0; i < width; i++) {
- dst[i] = SkBlendLCD16Opaque(srcR, srcG, srcB, dst[i], mask[i],
- opaqueDst);
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////
-
-static inline Sk4f swizzle_rb(const Sk4f& x) {
- return SkNx_shuffle<2, 1, 0, 3>(x);
-}
-
-static inline Sk4f swizzle_rb_if_bgra(const Sk4f& x) {
-#ifdef SK_PMCOLOR_IS_BGRA
- return swizzle_rb(x);
-#else
- return x;
-#endif
-}
-
-static inline Sk4f Sk4f_fromL32(uint32_t px) {
- return SkNx_cast<float>(Sk4b::Load(&px)) * (1 / 255.0f);
-}
-
-static inline uint32_t Sk4f_toL32(const Sk4f& px) {
- Sk4f v = px;
-
-#if !defined(SKNX_NO_SIMD) && SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
- // SkNx_cast<uint8_t, int32_t>() pins, and we don't anticipate giant floats
-#elif !defined(SKNX_NO_SIMD) && defined(SK_ARM_HAS_NEON)
- // SkNx_cast<uint8_t, int32_t>() pins, and so does Sk4f_round().
-#else
- // No guarantee of a pin.
- v = Sk4f::Max(0, Sk4f::Min(v, 1));
-#endif
-
- uint32_t l32;
- SkNx_cast<uint8_t>(Sk4f_round(v * 255.0f)).store(&l32);
- return l32;
-}
-
-using SkPMColor4f = SkRGBA4f<kPremul_SkAlphaType>;
-
-constexpr SkPMColor4f SK_PMColor4fTRANSPARENT = { 0, 0, 0, 0 };
-constexpr SkPMColor4f SK_PMColor4fWHITE = { 1, 1, 1, 1 };
-constexpr SkPMColor4f SK_PMColor4fILLEGAL = { SK_FloatNegativeInfinity,
- SK_FloatNegativeInfinity,
- SK_FloatNegativeInfinity,
- SK_FloatNegativeInfinity };
-
-#endif
diff --git a/src/core/SkGpuBlurUtils.cpp b/src/core/SkGpuBlurUtils.cpp
index b97e628..f9aee1c 100644
--- a/src/core/SkGpuBlurUtils.cpp
+++ b/src/core/SkGpuBlurUtils.cpp
@@ -220,11 +220,12 @@
contentRect->fBottom = dstRect.fBottom;
}
if (!topRect.isEmpty()) {
- dstRenderTargetContext->clear(&topRect, 0, GrRenderTargetContext::CanClearFullscreen::kNo);
+ dstRenderTargetContext->clear(&topRect, SK_PMColor4fTRANSPARENT,
+ GrRenderTargetContext::CanClearFullscreen::kNo);
}
if (!bottomRect.isEmpty()) {
- dstRenderTargetContext->clear(&bottomRect, 0,
+ dstRenderTargetContext->clear(&bottomRect, SK_PMColor4fTRANSPARENT,
GrRenderTargetContext::CanClearFullscreen::kNo);
}
@@ -338,7 +339,7 @@
// X convolution from reading garbage.
SkIRect clearRect = SkIRect::MakeXYWH(contentRect->fRight, contentRect->fTop,
radiusX, contentRect->height());
- dstRenderTargetContext->priv().absClear(&clearRect, 0x0);
+ dstRenderTargetContext->priv().absClear(&clearRect, SK_PMColor4fTRANSPARENT);
}
} else {
if (scaleFactorY > 1) {
@@ -346,7 +347,7 @@
// convolution from reading garbage.
SkIRect clearRect = SkIRect::MakeXYWH(contentRect->fLeft, contentRect->fBottom,
contentRect->width(), radiusY);
- dstRenderTargetContext->priv().absClear(&clearRect, 0x0);
+ dstRenderTargetContext->priv().absClear(&clearRect, SK_PMColor4fTRANSPARENT);
}
}
@@ -368,9 +369,9 @@
// TODO: it seems like we should actually be clamping here rather than darkening
// the bottom right edges.
SkIRect clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom, srcRect.width() + 1, 1);
- srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
+ srcRenderTargetContext->priv().absClear(&clearRect, SK_PMColor4fTRANSPARENT);
clearRect = SkIRect::MakeXYWH(srcRect.fRight, srcRect.fTop, 1, srcRect.height());
- srcRenderTargetContext->priv().absClear(&clearRect, 0x0);
+ srcRenderTargetContext->priv().absClear(&clearRect, SK_PMColor4fTRANSPARENT);
sk_sp<GrTextureProxy> srcProxy = srcRenderTargetContext->asTextureProxyRef();
if (!srcProxy) {
@@ -502,7 +503,7 @@
// convolution from reading garbage.
SkIRect clearRect = SkIRect::MakeXYWH(srcRect.fLeft, srcRect.fBottom,
srcRect.width(), radiusY);
- dstRenderTargetContext->priv().absClear(&clearRect, 0x0);
+ dstRenderTargetContext->priv().absClear(&clearRect, SK_PMColor4fTRANSPARENT);
}
srcProxy = dstRenderTargetContext->asTextureProxyRef();
diff --git a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
index 589c105..8cc485f 100644
--- a/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
+++ b/src/effects/imagefilters/SkAlphaThresholdFilter.cpp
@@ -117,7 +117,8 @@
GrPaint paint;
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
SkRegion::Iterator iter(fRegion);
- rtContext->clear(nullptr, 0x0, GrRenderTargetContext::CanClearFullscreen::kYes);
+ rtContext->clear(nullptr, SK_PMColor4fTRANSPARENT,
+ GrRenderTargetContext::CanClearFullscreen::kYes);
GrFixedClip clip(SkIRect::MakeWH(bounds.width(), bounds.height()));
while (!iter.done()) {
diff --git a/src/effects/imagefilters/SkMorphologyImageFilter.cpp b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
index 9c27040..ae07ffb 100644
--- a/src/effects/imagefilters/SkMorphologyImageFilter.cpp
+++ b/src/effects/imagefilters/SkMorphologyImageFilter.cpp
@@ -488,8 +488,8 @@
radius.fWidth, morphType, GrMorphologyEffect::Direction::kX);
SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
dstRect.width(), radius.fHeight);
- GrColor clearColor =
- GrMorphologyEffect::Type::kErode == morphType ? SK_ColorWHITE : SK_ColorTRANSPARENT;
+ SkPMColor4f clearColor = GrMorphologyEffect::Type::kErode == morphType
+ ? SK_PMColor4fWHITE : SK_PMColor4fTRANSPARENT;
dstRTContext->clear(&clearRect, clearColor, GrRenderTargetContext::CanClearFullscreen::kNo);
srcTexture = dstRTContext->asTextureProxyRef();
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 3535df9..b4b93f4 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -183,7 +183,7 @@
return nullptr;
}
- rtContext->priv().absClear(nullptr, 0x0);
+ rtContext->priv().absClear(nullptr, SK_PMColor4fTRANSPARENT);
GrPaint maskPaint;
maskPaint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
diff --git a/src/gpu/GrGpuCommandBuffer.cpp b/src/gpu/GrGpuCommandBuffer.cpp
index 421d057..8b5b128 100644
--- a/src/gpu/GrGpuCommandBuffer.cpp
+++ b/src/gpu/GrGpuCommandBuffer.cpp
@@ -16,7 +16,7 @@
#include "GrRenderTarget.h"
#include "SkRect.h"
-void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, GrColor color) {
+void GrGpuRTCommandBuffer::clear(const GrFixedClip& clip, const SkPMColor4f& color) {
SkASSERT(fRenderTarget);
this->onClear(clip, color);
diff --git a/src/gpu/GrGpuCommandBuffer.h b/src/gpu/GrGpuCommandBuffer.h
index 888d459..ca03378 100644
--- a/src/gpu/GrGpuCommandBuffer.h
+++ b/src/gpu/GrGpuCommandBuffer.h
@@ -8,7 +8,6 @@
#ifndef GrGpuCommandBuffer_DEFINED
#define GrGpuCommandBuffer_DEFINED
-#include "GrColor.h"
#include "GrPipeline.h"
#include "SkDrawable.h"
#include "ops/GrDrawOp.h"
@@ -73,9 +72,9 @@
class GrGpuRTCommandBuffer : public GrGpuCommandBuffer {
public:
struct LoadAndStoreInfo {
- GrLoadOp fLoadOp;
- GrStoreOp fStoreOp;
- GrColor fClearColor;
+ GrLoadOp fLoadOp;
+ GrStoreOp fStoreOp;
+ SkPMColor4f fClearColor;
};
// Load-time clears of the stencil buffer are always to 0 so we don't store
@@ -109,7 +108,7 @@
/**
* Clear the owned render target. Ignores the draw state and clip.
*/
- void clear(const GrFixedClip&, GrColor);
+ void clear(const GrFixedClip&, const SkPMColor4f&);
void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
@@ -155,7 +154,7 @@
const SkRect& bounds) = 0;
// overridden by backend-specific derived class to perform the clear.
- virtual void onClear(const GrFixedClip&, GrColor) = 0;
+ virtual void onClear(const GrFixedClip&, const SkPMColor4f&) = 0;
virtual void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) = 0;
diff --git a/src/gpu/GrOpList.cpp b/src/gpu/GrOpList.cpp
index 97214bd..dd889e8 100644
--- a/src/gpu/GrOpList.cpp
+++ b/src/gpu/GrOpList.cpp
@@ -213,7 +213,7 @@
: -1);
SkDebugf("ColorLoadOp: %s %x StencilLoadOp: %s\n",
op_to_name(fColorLoadOp),
- GrLoadOp::kClear == fColorLoadOp ? fLoadClearColor : 0x0,
+ GrLoadOp::kClear == fColorLoadOp ? fLoadClearColor.toBytes_RGBA() : 0x0,
op_to_name(fStencilLoadOp));
if (printDependencies) {
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index 32b7016..ee09a26 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -57,20 +57,20 @@
params));
}
-bool GrPaint::isConstantBlendedColor(GrColor* constantColor) const {
+bool GrPaint::isConstantBlendedColor(SkPMColor4f* constantColor) const {
// This used to do a more sophisticated analysis but now it just explicitly looks for common
// cases.
static const GrXPFactory* kSrc = GrPorterDuffXPFactory::Get(SkBlendMode::kSrc);
static const GrXPFactory* kClear = GrPorterDuffXPFactory::Get(SkBlendMode::kClear);
if (kClear == fXPFactory) {
- *constantColor = GrColor_TRANSPARENT_BLACK;
+ *constantColor = SK_PMColor4fTRANSPARENT;
return true;
}
if (this->numColorFragmentProcessors()) {
return false;
}
if (kSrc == fXPFactory || (!fXPFactory && fColor.isOpaque())) {
- *constantColor = fColor.toBytes_RGBA();
+ *constantColor = fColor;
return true;
}
return false;
diff --git a/src/gpu/GrPaint.h b/src/gpu/GrPaint.h
index 7f5b035..f6173b7 100644
--- a/src/gpu/GrPaint.h
+++ b/src/gpu/GrPaint.h
@@ -112,7 +112,7 @@
* coverage and color, so the actual values written to pixels with partial coverage may still
* not seem constant, even if this function returns true.
*/
- bool isConstantBlendedColor(GrColor* constantColor) const;
+ bool isConstantBlendedColor(SkPMColor4f* constantColor) const;
/**
* A trivial paint is one that uses src-over and has no fragment processors.
diff --git a/src/gpu/GrReducedClip.cpp b/src/gpu/GrReducedClip.cpp
index 4cf3477..97af1de 100644
--- a/src/gpu/GrReducedClip.cpp
+++ b/src/gpu/GrReducedClip.cpp
@@ -747,7 +747,8 @@
// The scratch texture that we are drawing into can be substantially larger than the mask. Only
// clear the part that we care about.
- GrColor initialCoverage = InitialState::kAllIn == this->initialState() ? -1 : 0;
+ SkPMColor4f initialCoverage =
+ InitialState::kAllIn == this->initialState() ? SK_PMColor4fWHITE : SK_PMColor4fTRANSPARENT;
rtc->priv().clear(clip, initialCoverage, GrRenderTargetContext::CanClearFullscreen::kYes);
// Set the matrix so that rendered clip elements are transformed to mask space from clip space.
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 3989374..fc446bf 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -256,7 +256,7 @@
}
void GrRenderTargetContext::clear(const SkIRect* rect,
- const GrColor color,
+ const SkPMColor4f& color,
CanClearFullscreen canClearFullscreen) {
ASSERT_SINGLE_OWNER
RETURN_IF_ABANDONED
@@ -268,7 +268,7 @@
canClearFullscreen);
}
-void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const GrColor color) {
+void GrRenderTargetContextPriv::absClear(const SkIRect* clearRect, const SkPMColor4f& color) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV
SkDEBUGCODE(fRenderTargetContext->validate();)
@@ -298,7 +298,7 @@
// It could be done but will take more finagling.
if (clearRect && fRenderTargetContext->caps()->performPartialClearsAsDraws()) {
GrPaint paint;
- paint.setColor4f(SkPMColor4f::FromBytes_RGBA(color));
+ paint.setColor4f(color);
SkRect scissor = SkRect::Make(rtRect);
std::unique_ptr<GrDrawOp> op(GrRectOpFactory::MakeNonAAFill(fRenderTargetContext->fContext,
std::move(paint), SkMatrix::I(),
@@ -319,7 +319,7 @@
}
void GrRenderTargetContextPriv::clear(const GrFixedClip& clip,
- const GrColor color,
+ const SkPMColor4f& color,
CanClearFullscreen canClearFullscreen) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV
@@ -332,7 +332,7 @@
}
void GrRenderTargetContext::internalClear(const GrFixedClip& clip,
- const GrColor color,
+ const SkPMColor4f& color,
CanClearFullscreen canClearFullscreen) {
bool isFull = false;
if (!clip.hasWindowRectangles()) {
@@ -347,7 +347,7 @@
} else {
if (this->caps()->performPartialClearsAsDraws()) {
GrPaint paint;
- paint.setColor4f(SkPMColor4f::FromBytes_RGBA(color));
+ paint.setColor4f(color);
SkRect scissor = SkRect::Make(clip.scissorRect());
std::unique_ptr<GrDrawOp> op(GrRectOpFactory::MakeNonAAFill(fContext, std::move(paint),
SkMatrix::I(), scissor,
@@ -392,7 +392,7 @@
// Check if the paint is a constant color, which is the first criterion to being able to turn
// the drawPaint() into a clear(). More expensive geometry checks can happen after that.
- GrColor clearColor;
+ SkPMColor4f clearColor;
if (paint.isConstantBlendedColor(&clearColor)) {
// Regardless of the actual clip geometry, if it completely covers the device bounds it can
// be turned into a fullscreen clear.
@@ -568,7 +568,7 @@
rect_contains_inclusive(rect, quad.point(2)) &&
rect_contains_inclusive(rect, quad.point(3))) {
// Will it blend?
- GrColor clearColor;
+ SkPMColor4f clearColor;
if (paint.isConstantBlendedColor(&clearColor)) {
this->clear(nullptr, clearColor,
GrRenderTargetContext::CanClearFullscreen::kYes);
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index 1200e6f..941c954 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -79,7 +79,7 @@
* @param CanClearFullscreen allows partial clears to be converted to fullscreen clears on
* tiling platforms where that is an optimization.
*/
- void clear(const SkIRect* rect, GrColor color, CanClearFullscreen);
+ void clear(const SkIRect* rect, const SkPMColor4f& color, CanClearFullscreen);
/**
* Draw everywhere (respecting the clip) with the paint.
@@ -441,7 +441,7 @@
std::unique_ptr<GrFragmentProcessor>,
sk_sp<GrTextureProxy>);
- void internalClear(const GrFixedClip&, const GrColor, CanClearFullscreen);
+ void internalClear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
// Only consumes the GrPaint if successful.
bool drawFilledDRRect(const GrClip& clip,
diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h
index 2a29282..c06c8ca 100644
--- a/src/gpu/GrRenderTargetContextPriv.h
+++ b/src/gpu/GrRenderTargetContextPriv.h
@@ -45,7 +45,7 @@
using CanClearFullscreen = GrRenderTargetContext::CanClearFullscreen;
- void clear(const GrFixedClip&, const GrColor, CanClearFullscreen);
+ void clear(const GrFixedClip&, const SkPMColor4f&, CanClearFullscreen);
void clearStencilClip(const GrFixedClip&, bool insideStencilMask);
@@ -60,7 +60,7 @@
* @param rect if (!null) the rect to clear, otherwise it is a full screen clear
* @param color the color to clear to
*/
- void absClear(const SkIRect* rect, const GrColor color);
+ void absClear(const SkIRect* rect, const SkPMColor4f& color);
void stencilRect(const GrHardClip&,
const GrUserStencilSettings* ss,
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index 2b2eece..df5233d 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -120,7 +120,7 @@
GrSurfaceOrigin origin,
const SkRect& bounds,
GrLoadOp colorLoadOp,
- GrColor loadClearColor,
+ const SkPMColor4f& loadClearColor,
GrLoadOp stencilLoadOp) {
const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo {
colorLoadOp,
@@ -216,7 +216,7 @@
}
}
-void GrRenderTargetOpList::fullClear(GrContext* context, GrColor color) {
+void GrRenderTargetOpList::fullClear(GrContext* context, const SkPMColor4f& color) {
// This is conservative. If the opList is marked as needing a stencil buffer then there
// may be a prior op that writes to the stencil buffer. Although the clear will ignore the
diff --git a/src/gpu/GrRenderTargetOpList.h b/src/gpu/GrRenderTargetOpList.h
index ad629e6..27922a8 100644
--- a/src/gpu/GrRenderTargetOpList.h
+++ b/src/gpu/GrRenderTargetOpList.h
@@ -89,7 +89,7 @@
void discard();
/** Clears the entire render target */
- void fullClear(GrContext*, GrColor color);
+ void fullClear(GrContext*, const SkPMColor4f& color);
/**
* Copies a pixel rectangle from one surface to another. This call may finalize
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index f0aafc1..daa86fc 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -242,7 +242,8 @@
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "clearAll", fContext.get());
SkIRect rect = SkIRect::MakeWH(this->width(), this->height());
- fRenderTargetContext->clear(&rect, 0x0, GrRenderTargetContext::CanClearFullscreen::kYes);
+ fRenderTargetContext->clear(&rect, SK_PMColor4fTRANSPARENT,
+ GrRenderTargetContext::CanClearFullscreen::kYes);
}
void SkGpuDevice::replaceRenderTargetContext(bool shouldRetainContent) {
diff --git a/src/gpu/ccpr/GrCCAtlas.cpp b/src/gpu/ccpr/GrCCAtlas.cpp
index a566707..0d1f9d9 100644
--- a/src/gpu/ccpr/GrCCAtlas.cpp
+++ b/src/gpu/ccpr/GrCCAtlas.cpp
@@ -202,7 +202,8 @@
}
SkIRect clearRect = SkIRect::MakeSize(fDrawBounds);
- rtc->clear(&clearRect, 0, GrRenderTargetContext::CanClearFullscreen::kYes);
+ rtc->clear(&clearRect, SK_PMColor4fTRANSPARENT,
+ GrRenderTargetContext::CanClearFullscreen::kYes);
return rtc;
}
diff --git a/src/gpu/effects/GrRRectBlurEffect.h b/src/gpu/effects/GrRRectBlurEffect.h
index 3093b31..e760f60 100644
--- a/src/gpu/effects/GrRRectBlurEffect.h
+++ b/src/gpu/effects/GrRRectBlurEffect.h
@@ -62,7 +62,8 @@
GrPaint paint;
- rtc->clear(nullptr, 0x0, GrRenderTargetContext::CanClearFullscreen::kYes);
+ rtc->clear(nullptr, SK_PMColor4fTRANSPARENT,
+ GrRenderTargetContext::CanClearFullscreen::kYes);
rtc->drawRRect(GrNoClip(), std::move(paint), GrAA::kYes, SkMatrix::I(), rrectToDraw,
GrStyle::SimpleFill());
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 214cdd6..902509d 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2000,23 +2000,15 @@
}
}
-void GrGLGpu::clear(const GrFixedClip& clip, GrColor color,
+void GrGLGpu::clear(const GrFixedClip& clip, const SkPMColor4f& color,
GrRenderTarget* target, GrSurfaceOrigin origin) {
// parent class should never let us get here with no RT
SkASSERT(target);
this->handleDirtyContext();
- GrGLfloat r, g, b, a;
- static const GrGLfloat scale255 = 1.f / 255.f;
- a = GrColorUnpackA(color) * scale255;
- GrGLfloat scaleRGB = scale255;
- r = GrColorUnpackR(color) * scaleRGB;
- g = GrColorUnpackG(color) * scaleRGB;
- b = GrColorUnpackB(color) * scaleRGB;
-
if (this->glCaps().useDrawToClearColor()) {
- this->clearColorAsDraw(clip, r, g, b, a, target, origin);
+ this->clearColorAsDraw(clip, color, target, origin);
return;
}
@@ -2033,6 +2025,8 @@
GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE));
fHWWriteToColor = kYes_TriState;
+ GrGLfloat r = color.fR, g = color.fG, b = color.fB, a = color.fA;
+
if (this->glCaps().clearToBoundaryValuesIsBroken() &&
(1 == r || 0 == r) && (1 == g || 0 == g) && (1 == b || 0 == b) && (1 == a || 0 == a)) {
static const GrGLfloat safeAlpha1 = nextafter(1.f, 2.f);
@@ -3647,8 +3641,8 @@
return true;
}
-void GrGLGpu::clearColorAsDraw(const GrFixedClip& clip, GrGLfloat r, GrGLfloat g, GrGLfloat b,
- GrGLfloat a, GrRenderTarget* dst, GrSurfaceOrigin origin) {
+void GrGLGpu::clearColorAsDraw(const GrFixedClip& clip, const SkPMColor4f& color,
+ GrRenderTarget* dst, GrSurfaceOrigin origin) {
if (!fClearColorProgram.fProgram) {
if (!this->createClearColorProgram()) {
SkDebugf("Failed to create clear color program.\n");
@@ -3674,7 +3668,7 @@
this->flushScissor(clip.scissorState(), glrt->getViewport(), origin);
this->flushWindowRectangles(clip.windowRectsState(), glrt, origin);
- GL_CALL(Uniform4f(fClearColorProgram.fColorUniform, r, g, b, a));
+ GL_CALL(Uniform4f(fClearColorProgram.fColorUniform, color.fR, color.fG, color.fB, color.fA));
GrXferProcessor::BlendInfo blendInfo;
blendInfo.reset();
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 1fa18c5..8812a02 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -108,9 +108,9 @@
// The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clear call for the corresponding passthrough function
// on GrGLGpuRTCommandBuffer.
- void clear(const GrFixedClip&, GrColor, GrRenderTarget*, GrSurfaceOrigin);
- void clearColorAsDraw(const GrFixedClip&, GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a,
- GrRenderTarget*, GrSurfaceOrigin);
+ void clear(const GrFixedClip&, const SkPMColor4f&, GrRenderTarget*, GrSurfaceOrigin);
+ void clearColorAsDraw(const GrFixedClip&, const SkPMColor4f& color, GrRenderTarget*,
+ GrSurfaceOrigin);
// The GrGLGpuRTCommandBuffer does not buffer up draws before submitting them to the gpu.
// Thus this is the implementation of the clearStencil call for the corresponding passthrough
diff --git a/src/gpu/gl/GrGLGpuCommandBuffer.h b/src/gpu/gl/GrGLGpuCommandBuffer.h
index 63aacf3..e8c9bbd 100644
--- a/src/gpu/gl/GrGLGpuCommandBuffer.h
+++ b/src/gpu/gl/GrGLGpuCommandBuffer.h
@@ -89,7 +89,7 @@
fGpu->draw(primProc, pipeline, fixedDynamicState, dynamicStateArrays, mesh, meshCount);
}
- void onClear(const GrFixedClip& clip, GrColor color) override {
+ void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override {
fGpu->clear(clip, color, fRenderTarget, fOrigin);
}
diff --git a/src/gpu/mock/GrMockGpuCommandBuffer.h b/src/gpu/mock/GrMockGpuCommandBuffer.h
index cad5836..a14fb64 100644
--- a/src/gpu/mock/GrMockGpuCommandBuffer.h
+++ b/src/gpu/mock/GrMockGpuCommandBuffer.h
@@ -51,7 +51,7 @@
const GrMesh[], int meshCount, const SkRect& bounds) override {
++fNumDraws;
}
- void onClear(const GrFixedClip&, GrColor) override {}
+ void onClear(const GrFixedClip&, const SkPMColor4f&) override {}
void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override {}
GrMockGpu* fGpu;
diff --git a/src/gpu/mtl/GrMtlGpuCommandBuffer.h b/src/gpu/mtl/GrMtlGpuCommandBuffer.h
index 9e1ce45..1505789 100644
--- a/src/gpu/mtl/GrMtlGpuCommandBuffer.h
+++ b/src/gpu/mtl/GrMtlGpuCommandBuffer.h
@@ -84,7 +84,7 @@
int meshCount,
const SkRect& bounds) override;
- void onClear(const GrFixedClip& clip, GrColor color) override;
+ void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override;
void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override;
diff --git a/src/gpu/mtl/GrMtlGpuCommandBuffer.mm b/src/gpu/mtl/GrMtlGpuCommandBuffer.mm
index b982577..48258cc 100644
--- a/src/gpu/mtl/GrMtlGpuCommandBuffer.mm
+++ b/src/gpu/mtl/GrMtlGpuCommandBuffer.mm
@@ -181,14 +181,12 @@
fCommandBufferInfo.fBounds.join(bounds);
}
-void GrMtlGpuRTCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
+void GrMtlGpuRTCommandBuffer::onClear(const GrFixedClip& clip, const SkPMColor4f& color) {
// if we end up here from absClear, the clear bounds may be bigger than the RT proxy bounds -
// but in that case, scissor should be enabled, so this check should still succeed
SkASSERT(!clip.scissorEnabled() || clip.scissorRect().contains(fBounds));
- float clear[4];
- GrColorToRGBAFloat(color, clear);
- fRenderPassDesc.colorAttachments[0].clearColor = MTLClearColorMake(clear[0], clear[1], clear[2],
- clear[3]);
+ fRenderPassDesc.colorAttachments[0].clearColor = MTLClearColorMake(color.fR, color.fG, color.fB,
+ color.fA);
fRenderPassDesc.colorAttachments[0].loadAction = MTLLoadActionClear;
this->internalBegin();
this->internalEnd();
@@ -242,8 +240,7 @@
static_cast<GrMtlRenderTarget*>(fRenderTarget)->mtlRenderTexture();
renderPassDesc.colorAttachments[0].slice = 0;
renderPassDesc.colorAttachments[0].level = 0;
- float clearColor[4];
- GrColorToRGBAFloat(fColorLoadAndStoreInfo.fClearColor, clearColor);
+ const SkPMColor4f& clearColor = fColorLoadAndStoreInfo.fClearColor;
renderPassDesc.colorAttachments[0].clearColor =
MTLClearColorMake(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
renderPassDesc.colorAttachments[0].loadAction =
diff --git a/src/gpu/ops/GrClearOp.cpp b/src/gpu/ops/GrClearOp.cpp
index 612ff20..ece91ad 100644
--- a/src/gpu/ops/GrClearOp.cpp
+++ b/src/gpu/ops/GrClearOp.cpp
@@ -14,7 +14,7 @@
std::unique_ptr<GrClearOp> GrClearOp::Make(GrContext* context,
const GrFixedClip& clip,
- GrColor color,
+ const SkPMColor4f& color,
GrSurfaceProxy* dstProxy) {
const SkIRect rect = SkIRect::MakeWH(dstProxy->width(), dstProxy->height());
if (clip.scissorEnabled() && !SkIRect::Intersects(clip.scissorRect(), rect)) {
@@ -28,7 +28,7 @@
std::unique_ptr<GrClearOp> GrClearOp::Make(GrContext* context,
const SkIRect& rect,
- GrColor color,
+ const SkPMColor4f& color,
bool fullScreen) {
SkASSERT(fullScreen || !rect.isEmpty());
@@ -37,7 +37,7 @@
return pool->allocate<GrClearOp>(rect, color, fullScreen);
}
-GrClearOp::GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy)
+GrClearOp::GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy)
: INHERITED(ClassID())
, fClip(clip)
, fColor(color) {
diff --git a/src/gpu/ops/GrClearOp.h b/src/gpu/ops/GrClearOp.h
index 7e19d61..c123e58 100644
--- a/src/gpu/ops/GrClearOp.h
+++ b/src/gpu/ops/GrClearOp.h
@@ -19,12 +19,12 @@
static std::unique_ptr<GrClearOp> Make(GrContext* context,
const GrFixedClip& clip,
- GrColor color,
+ const SkPMColor4f& color,
GrSurfaceProxy* dstProxy);
static std::unique_ptr<GrClearOp> Make(GrContext* context,
const SkIRect& rect,
- GrColor color,
+ const SkPMColor4f& color,
bool fullScreen);
const char* name() const override { return "Clear"; }
@@ -39,19 +39,19 @@
} else {
string.append("disabled");
}
- string.appendf("], Color: 0x%08x\n", fColor);
+ string.appendf("], Color: 0x%08x\n", fColor.toBytes_RGBA());
return string;
}
- GrColor color() const { return fColor; }
- void setColor(GrColor color) { fColor = color; }
+ const SkPMColor4f& color() const { return fColor; }
+ void setColor(const SkPMColor4f& color) { fColor = color; }
private:
friend class GrOpMemoryPool; // for ctors
- GrClearOp(const GrFixedClip& clip, GrColor color, GrSurfaceProxy* proxy);
+ GrClearOp(const GrFixedClip& clip, const SkPMColor4f& color, GrSurfaceProxy* proxy);
- GrClearOp(const SkIRect& rect, GrColor color, bool fullScreen)
+ GrClearOp(const SkIRect& rect, const SkPMColor4f& color, bool fullScreen)
: INHERITED(ClassID())
, fClip(GrFixedClip(rect))
, fColor(color) {
@@ -92,7 +92,7 @@
void onExecute(GrOpFlushState* state) override;
GrFixedClip fClip;
- GrColor fColor;
+ SkPMColor4f fColor;
typedef GrOp INHERITED;
};
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index fce6235..9ffd8f8 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -243,7 +243,7 @@
this->INHERITED::set(rt, origin);
- GrColorToRGBAFloat(colorInfo.fClearColor, fClearColor);
+ fClearColor = colorInfo.fClearColor;
get_vk_load_store_ops(colorInfo.fLoadOp, colorInfo.fStoreOp,
&fVkColorLoadOp, &fVkColorStoreOp);
@@ -371,7 +371,7 @@
}
}
-void GrVkGpuRTCommandBuffer::onClear(const GrFixedClip& clip, GrColor color) {
+void GrVkGpuRTCommandBuffer::onClear(const GrFixedClip& clip, const SkPMColor4f& color) {
GrVkRenderTarget* vkRT = static_cast<GrVkRenderTarget*>(fRenderTarget);
// parent class should never let us get here with no RT
@@ -379,8 +379,7 @@
CommandBufferInfo& cbInfo = fCommandBufferInfos[fCurrentCmdInfo];
- VkClearColorValue vkColor;
- GrColorToRGBAFloat(color, vkColor.float32);
+ VkClearColorValue vkColor = {{color.fR, color.fG, color.fB, color.fA}};
if (cbInfo.fIsEmpty && !clip.scissorEnabled()) {
// Change the render pass to do a clear load
@@ -406,7 +405,7 @@
SkASSERT(cbInfo.fRenderPass->isCompatible(*oldRP));
oldRP->unref(fGpu);
- GrColorToRGBAFloat(color, cbInfo.fColorClearValue.color.float32);
+ cbInfo.fColorClearValue.color = {{color.fR, color.fG, color.fB, color.fA}};
cbInfo.fLoadStoreState = LoadStoreState::kStartsWithClear;
// If we are going to clear the whole render target then the results of any copies we did
// immediately before to the target won't matter, so just drop them.
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.h b/src/gpu/vk/GrVkGpuCommandBuffer.h
index b40cff3..151d962 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.h
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.h
@@ -134,7 +134,7 @@
const GrBuffer* instanceBuffer, int instanceCount,
int baseInstance, GrPrimitiveRestart) final;
- void onClear(const GrFixedClip&, GrColor color) override;
+ void onClear(const GrFixedClip&, const SkPMColor4f& color) override;
void onClearStencilClip(const GrFixedClip&, bool insideStencilMask) override;
@@ -201,7 +201,7 @@
VkAttachmentStoreOp fVkColorStoreOp;
VkAttachmentLoadOp fVkStencilLoadOp;
VkAttachmentStoreOp fVkStencilStoreOp;
- float fClearColor[4];
+ SkPMColor4f fClearColor;
GrVkPipelineState* fLastPipelineState;
typedef GrGpuRTCommandBuffer INHERITED;