GrContext_Base.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2019 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/private/GrContext_Base.h"
  8. #include "src/gpu/GrBaseContextPriv.h"
  9. #include "src/gpu/GrCaps.h"
  10. #include "src/gpu/GrSkSLFPFactoryCache.h"
  11. static int32_t next_id() {
  12. static std::atomic<int32_t> nextID{1};
  13. int32_t id;
  14. do {
  15. id = nextID++;
  16. } while (id == SK_InvalidGenID);
  17. return id;
  18. }
  19. GrContext_Base::GrContext_Base(GrBackendApi backend,
  20. const GrContextOptions& options,
  21. uint32_t contextID)
  22. : fBackend(backend)
  23. , fOptions(options)
  24. , fContextID(SK_InvalidGenID == contextID ? next_id() : contextID) {
  25. }
  26. GrContext_Base::~GrContext_Base() { }
  27. bool GrContext_Base::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
  28. SkASSERT(caps && FPFactoryCache);
  29. fCaps = caps;
  30. fFPFactoryCache = FPFactoryCache;
  31. return true;
  32. }
  33. const GrCaps* GrContext_Base::caps() const { return fCaps.get(); }
  34. sk_sp<const GrCaps> GrContext_Base::refCaps() const { return fCaps; }
  35. sk_sp<GrSkSLFPFactoryCache> GrContext_Base::fpFactoryCache() { return fFPFactoryCache; }
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////
  37. sk_sp<const GrCaps> GrBaseContextPriv::refCaps() const {
  38. return fContext->refCaps();
  39. }
  40. sk_sp<GrSkSLFPFactoryCache> GrBaseContextPriv::fpFactoryCache() {
  41. return fContext->fpFactoryCache();
  42. }