GrDDLContext.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright 2018 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/gpu/GrContext.h"
  8. #include "src/gpu/GrCaps.h"
  9. #include "src/gpu/GrContextPriv.h"
  10. #include "src/gpu/GrContextThreadSafeProxyPriv.h"
  11. #include "src/gpu/GrSkSLFPFactoryCache.h"
  12. /**
  13. * The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
  14. * cannot allocate any GPU resources.
  15. */
  16. class SK_API GrDDLContext : public GrContext {
  17. public:
  18. GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
  19. : INHERITED(proxy->backend(), proxy->priv().options(), proxy->priv().contextID()) {
  20. fThreadSafeProxy = std::move(proxy);
  21. }
  22. ~GrDDLContext() override { }
  23. void abandonContext() override {
  24. SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
  25. INHERITED::abandonContext();
  26. }
  27. void releaseResourcesAndAbandonContext() override {
  28. SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
  29. INHERITED::releaseResourcesAndAbandonContext();
  30. }
  31. void freeGpuResources() override {
  32. SkASSERT(0); // freeing resources in a DDL Recorder doesn't make a whole lot of sense
  33. INHERITED::freeGpuResources();
  34. }
  35. protected:
  36. // TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
  37. // GrRecordingContext!
  38. GrContext* asDirectContext() override { return nullptr; }
  39. bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override {
  40. SkASSERT(caps && FPFactoryCache);
  41. SkASSERT(fThreadSafeProxy); // should've been set in the ctor
  42. if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
  43. return false;
  44. }
  45. // DDL contexts/drawing managers always sort the oplists and attempt to reduce opList
  46. // splitting.
  47. this->setupDrawingManager(true, true);
  48. SkASSERT(this->caps());
  49. return true;
  50. }
  51. GrAtlasManager* onGetAtlasManager() override {
  52. SkASSERT(0); // the DDL Recorders should never invoke this
  53. return nullptr;
  54. }
  55. private:
  56. typedef GrContext INHERITED;
  57. };
  58. sk_sp<GrContext> GrContextPriv::MakeDDL(const sk_sp<GrContextThreadSafeProxy>& proxy) {
  59. sk_sp<GrContext> context(new GrDDLContext(proxy));
  60. if (!context->init(proxy->priv().refCaps(), proxy->priv().fpFactoryCache())) {
  61. return nullptr;
  62. }
  63. return context;
  64. }