SkFontConfigInterface.cpp 976 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * Copyright 2016 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. #include "include/core/SkFontMgr.h"
  8. #include "include/core/SkRefCnt.h"
  9. #include "include/ports/SkFontConfigInterface.h"
  10. #include "include/private/SkMutex.h"
  11. static SkMutex& font_config_interface_mutex() {
  12. static SkMutex& mutex = *(new SkMutex);
  13. return mutex;
  14. }
  15. static SkFontConfigInterface* gFontConfigInterface;
  16. sk_sp<SkFontConfigInterface> SkFontConfigInterface::RefGlobal() {
  17. SkAutoMutexExclusive ac(font_config_interface_mutex());
  18. if (gFontConfigInterface) {
  19. return sk_ref_sp(gFontConfigInterface);
  20. }
  21. return sk_ref_sp(SkFontConfigInterface::GetSingletonDirectInterface());
  22. }
  23. void SkFontConfigInterface::SetGlobal(sk_sp<SkFontConfigInterface> fc) {
  24. SkAutoMutexExclusive ac(font_config_interface_mutex());
  25. SkSafeUnref(gFontConfigInterface);
  26. gFontConfigInterface = fc.release();
  27. }