SkPaintPriv.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkPaintPriv_DEFINED
  8. #define SkPaintPriv_DEFINED
  9. #include "include/core/SkPaint.h"
  10. class SkFont;
  11. class SkReadBuffer;
  12. class SkWriteBuffer;
  13. enum SkReadPaintResult {
  14. kFailed_ReadPaint,
  15. kSuccess_JustPaint,
  16. kSuccess_PaintAndFont,
  17. };
  18. class SkPaintPriv {
  19. public:
  20. enum ShaderOverrideOpacity {
  21. kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
  22. kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
  23. kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
  24. };
  25. /**
  26. * Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels.
  27. *
  28. * Note: returns conservative true, meaning it may return false even though the paint might
  29. * in fact overwrite its pixels.
  30. */
  31. static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity);
  32. static bool ShouldDither(const SkPaint&, SkColorType);
  33. /*
  34. * The luminance color is used to determine which Gamma Canonical color to map to. This is
  35. * really only used by backends which want to cache glyph masks, and need some way to know if
  36. * they need to generate new masks based off a given color.
  37. */
  38. static SkColor ComputeLuminanceColor(const SkPaint&);
  39. /** Serializes SkPaint into a buffer. A companion unflatten() call
  40. can reconstitute the paint at a later time.
  41. @param buffer SkWriteBuffer receiving the flattened SkPaint data
  42. */
  43. static void Flatten(const SkPaint& paint, SkWriteBuffer& buffer);
  44. /** Populates SkPaint, typically from a serialized stream, created by calling
  45. flatten() at an earlier time.
  46. SkReadBuffer class is not public, so unflatten() cannot be meaningfully called
  47. by the client.
  48. Older formats also stored font info in the serialized data. On success, this
  49. returns if it deserialized just a paint, or both a font and paint. The font
  50. param is optional.
  51. @param buffer serialized data describing SkPaint content
  52. @return false if the buffer contains invalid data
  53. */
  54. static SkReadPaintResult Unflatten(SkPaint* paint, SkReadBuffer& buffer, SkFont* font);
  55. private:
  56. static SkReadPaintResult Unflatten_PreV68(SkPaint* paint, SkReadBuffer& buffer, SkFont*);
  57. };
  58. #endif