skia_utils_base.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef SKIA_EXT_SKIA_UTILS_BASE_H_
  5. #define SKIA_EXT_SKIA_UTILS_BASE_H_
  6. #include "third_party/skia/include/core/SkColor.h"
  7. #include "third_party/skia/include/core/SkFlattenable.h"
  8. #include "third_party/skia/include/ports/SkFontConfigInterface.h"
  9. namespace base {
  10. class Pickle;
  11. class PickleIterator;
  12. }
  13. class SkBitmap;
  14. class SkFlattenable;
  15. namespace skia {
  16. // Return true if the pickle/iterator contains a string. If so, and if str
  17. // is not null, copy that string into str.
  18. SK_API bool ReadSkString(base::PickleIterator* iter, SkString* str);
  19. // Return true if the pickle/iterator contains a FontIdentity. If so, and if
  20. // identity is not null, copy it into identity.
  21. SK_API bool ReadSkFontIdentity(base::PickleIterator* iter,
  22. SkFontConfigInterface::FontIdentity* identity);
  23. // Return true if the pickle/iterator contains a SkFontStyle. If so, and if
  24. // style is not null, copy it into style.
  25. SK_API bool ReadSkFontStyle(base::PickleIterator* iter, SkFontStyle* style);
  26. // Writes str into the request pickle.
  27. SK_API void WriteSkString(base::Pickle* pickle, const SkString& str);
  28. // Writes identity into the request pickle.
  29. SK_API void WriteSkFontIdentity(
  30. base::Pickle* pickle,
  31. const SkFontConfigInterface::FontIdentity& identity);
  32. // Writes style into the request pickle.
  33. SK_API void WriteSkFontStyle(base::Pickle* pickle, SkFontStyle style);
  34. // Converts an SkBitmap to an Opaque or Premul N32 SkBitmap with stride matching
  35. // the width of each row. If the input is has the right format (N32 Opaque or
  36. // Premul) without stride padding already, this assigns `in` to `out`, sharing
  37. // the backing pixels. `out` may or may not be GPU-backed.
  38. //
  39. // If unsuccessful, returns false, but |out| may be modified.
  40. //
  41. // This should be called as early as possible at IPC endpoints from
  42. // less-privileged contexts (e.g. on a message from the renderer process) if the
  43. // code handling the SkBitmap wants to work with an N32 type, rather than
  44. // delaying this conversion until a later time.
  45. SK_API bool SkBitmapToN32OpaqueOrPremul(const SkBitmap& in, SkBitmap* out);
  46. // Returns hex string representation for the |color| in "#FFFFFF" format.
  47. SK_API std::string SkColorToHexString(SkColor color);
  48. } // namespace skia
  49. #endif // SKIA_EXT_SKIA_UTILS_BASE_H_