GrOnFlushResourceProvider.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright 2017 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 "src/gpu/GrOnFlushResourceProvider.h"
  8. #include "include/private/GrRecordingContext.h"
  9. #include "src/gpu/GrContextPriv.h"
  10. #include "src/gpu/GrDrawingManager.h"
  11. #include "src/gpu/GrProxyProvider.h"
  12. #include "src/gpu/GrRecordingContextPriv.h"
  13. #include "src/gpu/GrRenderTargetContext.h"
  14. #include "src/gpu/GrSurfaceProxy.h"
  15. sk_sp<GrRenderTargetContext> GrOnFlushResourceProvider::makeRenderTargetContext(
  16. sk_sp<GrSurfaceProxy> proxy,
  17. GrColorType colorType,
  18. sk_sp<SkColorSpace> colorSpace,
  19. const SkSurfaceProps* props) {
  20. // Since this is at flush time and these won't be allocated for us by the GrResourceAllocator
  21. // we have to manually ensure it is allocated here. The proxy had best have been created
  22. // with the kNoPendingIO flag!
  23. if (!this->instatiateProxy(proxy.get())) {
  24. return nullptr;
  25. }
  26. sk_sp<GrRenderTargetContext> renderTargetContext(fDrawingMgr->makeRenderTargetContext(
  27. std::move(proxy), colorType, std::move(colorSpace), props, false));
  28. if (!renderTargetContext) {
  29. return nullptr;
  30. }
  31. renderTargetContext->discard();
  32. return renderTargetContext;
  33. }
  34. bool GrOnFlushResourceProvider::assignUniqueKeyToProxy(const GrUniqueKey& key,
  35. GrTextureProxy* proxy) {
  36. auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
  37. return proxyProvider->assignUniqueKeyToProxy(key, proxy);
  38. }
  39. void GrOnFlushResourceProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
  40. auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
  41. proxyProvider->removeUniqueKeyFromProxy(proxy);
  42. }
  43. void GrOnFlushResourceProvider::processInvalidUniqueKey(const GrUniqueKey& key) {
  44. auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
  45. proxyProvider->processInvalidUniqueKey(key, nullptr,
  46. GrProxyProvider::InvalidateGPUResource::kYes);
  47. }
  48. sk_sp<GrTextureProxy> GrOnFlushResourceProvider::findOrCreateProxyByUniqueKey(
  49. const GrUniqueKey& key, GrSurfaceOrigin origin) {
  50. auto proxyProvider = fDrawingMgr->getContext()->priv().proxyProvider();
  51. return proxyProvider->findOrCreateProxyByUniqueKey(key, origin);
  52. }
  53. bool GrOnFlushResourceProvider::instatiateProxy(GrSurfaceProxy* proxy) {
  54. SkASSERT(proxy->priv().ignoredByResourceAllocator());
  55. // TODO: this class should probably just get a GrDirectContext
  56. auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
  57. if (!direct) {
  58. return false;
  59. }
  60. auto resourceProvider = direct->priv().resourceProvider();
  61. if (GrSurfaceProxy::LazyState::kNot != proxy->lazyInstantiationState()) {
  62. // DDL TODO: Decide if we ever plan to have these proxies use the GrDeinstantiateTracker
  63. // to support unistantiating them at the end of a flush.
  64. return proxy->priv().doLazyInstantiation(resourceProvider);
  65. }
  66. return proxy->instantiate(resourceProvider);
  67. }
  68. sk_sp<GrGpuBuffer> GrOnFlushResourceProvider::makeBuffer(GrGpuBufferType intendedType, size_t size,
  69. const void* data) {
  70. // TODO: this class should probably just get a GrDirectContext
  71. auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
  72. if (!direct) {
  73. return nullptr;
  74. }
  75. auto resourceProvider = direct->priv().resourceProvider();
  76. return sk_sp<GrGpuBuffer>(
  77. resourceProvider->createBuffer(size, intendedType, kDynamic_GrAccessPattern, data));
  78. }
  79. sk_sp<const GrGpuBuffer> GrOnFlushResourceProvider::findOrMakeStaticBuffer(
  80. GrGpuBufferType intendedType, size_t size, const void* data, const GrUniqueKey& key) {
  81. // TODO: class should probably just get a GrDirectContext
  82. auto direct = fDrawingMgr->getContext()->priv().asDirectContext();
  83. if (!direct) {
  84. return nullptr;
  85. }
  86. auto resourceProvider = direct->priv().resourceProvider();
  87. sk_sp<const GrGpuBuffer> buffer =
  88. resourceProvider->findOrMakeStaticBuffer(intendedType, size, data, key);
  89. // Static buffers should never have pending IO.
  90. SkASSERT(!buffer || !buffer->resourcePriv().hasPendingIO_debugOnly());
  91. return buffer;
  92. }
  93. uint32_t GrOnFlushResourceProvider::contextID() const {
  94. return fDrawingMgr->getContext()->priv().contextID();
  95. }
  96. const GrCaps* GrOnFlushResourceProvider::caps() const {
  97. return fDrawingMgr->getContext()->priv().caps();
  98. }