GrGLTextureRenderTarget.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2015 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/SkTraceMemoryDump.h"
  8. #include "include/gpu/GrContext.h"
  9. #include "src/gpu/GrContextPriv.h"
  10. #include "src/gpu/GrTexturePriv.h"
  11. #include "src/gpu/gl/GrGLGpu.h"
  12. #include "src/gpu/gl/GrGLTextureRenderTarget.h"
  13. GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
  14. SkBudgeted budgeted,
  15. const GrSurfaceDesc& desc,
  16. int sampleCount,
  17. const GrGLTexture::IDDesc& texIDDesc,
  18. const GrGLRenderTarget::IDDesc& rtIDDesc,
  19. GrMipMapsStatus mipMapsStatus)
  20. : GrSurface(gpu, desc, GrProtected::kNo)
  21. , GrGLTexture(gpu, desc, texIDDesc, nullptr, mipMapsStatus)
  22. , GrGLRenderTarget(gpu, desc, sampleCount, texIDDesc.fInfo.fFormat, rtIDDesc) {
  23. this->registerWithCache(budgeted);
  24. }
  25. GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
  26. const GrSurfaceDesc& desc,
  27. int sampleCount,
  28. const GrGLTexture::IDDesc& texIDDesc,
  29. sk_sp<GrGLTextureParameters> parameters,
  30. const GrGLRenderTarget::IDDesc& rtIDDesc,
  31. GrWrapCacheable cacheable,
  32. GrMipMapsStatus mipMapsStatus)
  33. : GrSurface(gpu, desc, GrProtected::kNo)
  34. , GrGLTexture(gpu, desc, texIDDesc, std::move(parameters), mipMapsStatus)
  35. , GrGLRenderTarget(gpu, desc, sampleCount, texIDDesc.fInfo.fFormat, rtIDDesc) {
  36. this->registerWithCacheWrapped(cacheable);
  37. }
  38. void GrGLTextureRenderTarget::dumpMemoryStatistics(
  39. SkTraceMemoryDump* traceMemoryDump) const {
  40. #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
  41. // Delegate to the base classes
  42. GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
  43. GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
  44. #else
  45. SkString resourceName = this->getResourceName();
  46. resourceName.append("/texture_renderbuffer");
  47. this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
  48. this->gpuMemorySize());
  49. #endif
  50. }
  51. bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
  52. // The RT FBO of GrGLTextureRenderTarget is never created from a
  53. // wrapped FBO, so we only care about the flag.
  54. return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers();
  55. }
  56. sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
  57. GrGLGpu* gpu, const GrSurfaceDesc& desc, int sampleCount,
  58. const GrGLTexture::IDDesc& texIDDesc, sk_sp<GrGLTextureParameters> parameters,
  59. const GrGLRenderTarget::IDDesc& rtIDDesc, GrWrapCacheable cacheable,
  60. GrMipMapsStatus mipMapsStatus) {
  61. return sk_sp<GrGLTextureRenderTarget>(
  62. new GrGLTextureRenderTarget(gpu, desc, sampleCount, texIDDesc, std::move(parameters),
  63. rtIDDesc, cacheable, mipMapsStatus));
  64. }
  65. size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
  66. return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
  67. this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
  68. }