GrTextureContext.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 "src/gpu/GrTextureContext.h"
  8. #include "src/gpu/GrAuditTrail.h"
  9. #include "src/gpu/GrContextPriv.h"
  10. #include "src/gpu/GrDrawingManager.h"
  11. #include "src/gpu/GrTextureOpList.h"
  12. #define ASSERT_SINGLE_OWNER \
  13. SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
  14. #define RETURN_FALSE_IF_ABANDONED if (this->drawingManager()->wasAbandoned()) { return false; }
  15. GrTextureContext::GrTextureContext(GrRecordingContext* context,
  16. sk_sp<GrTextureProxy> textureProxy,
  17. GrColorType colorType,
  18. SkAlphaType alphaType,
  19. sk_sp<SkColorSpace> colorSpace)
  20. : GrSurfaceContext(context, colorType, alphaType, std::move(colorSpace))
  21. , fTextureProxy(std::move(textureProxy))
  22. , fOpList(sk_ref_sp(fTextureProxy->getLastTextureOpList())) {
  23. SkDEBUGCODE(this->validate();)
  24. }
  25. #ifdef SK_DEBUG
  26. void GrTextureContext::validate() const {
  27. SkASSERT(fTextureProxy);
  28. fTextureProxy->validate(fContext);
  29. if (fOpList && !fOpList->isClosed()) {
  30. SkASSERT(fTextureProxy->getLastOpList() == fOpList.get());
  31. }
  32. }
  33. #endif
  34. GrTextureContext::~GrTextureContext() {
  35. ASSERT_SINGLE_OWNER
  36. }
  37. GrRenderTargetProxy* GrTextureContext::asRenderTargetProxy() {
  38. // If the proxy can return an RTProxy it should've been wrapped in a RTContext
  39. SkASSERT(!fTextureProxy->asRenderTargetProxy());
  40. return nullptr;
  41. }
  42. sk_sp<GrRenderTargetProxy> GrTextureContext::asRenderTargetProxyRef() {
  43. // If the proxy can return an RTProxy it should've been wrapped in a RTContext
  44. SkASSERT(!fTextureProxy->asRenderTargetProxy());
  45. return nullptr;
  46. }
  47. GrOpList* GrTextureContext::getOpList() {
  48. ASSERT_SINGLE_OWNER
  49. SkDEBUGCODE(this->validate();)
  50. if (!fOpList || fOpList->isClosed()) {
  51. fOpList = this->drawingManager()->newTextureOpList(fTextureProxy);
  52. }
  53. return fOpList.get();
  54. }