GrSurface.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright 2012 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 "include/gpu/GrRenderTarget.h"
  9. #include "include/gpu/GrSurface.h"
  10. #include "include/gpu/GrTexture.h"
  11. #include "src/gpu/GrOpList.h"
  12. #include "src/gpu/GrResourceProvider.h"
  13. #include "src/gpu/GrSurfacePriv.h"
  14. #include "src/core/SkMathPriv.h"
  15. #include "src/gpu/SkGr.h"
  16. size_t GrSurface::WorstCaseSize(const GrSurfaceDesc& desc, GrRenderable renderable,
  17. int renderTargetSampleCnt, bool binSize) {
  18. size_t size;
  19. int width = binSize ? GrResourceProvider::MakeApprox(desc.fWidth) : desc.fWidth;
  20. int height = binSize ? GrResourceProvider::MakeApprox(desc.fHeight) : desc.fHeight;
  21. if (renderable == GrRenderable::kYes) {
  22. // We own one color value for each MSAA sample.
  23. SkASSERT(renderTargetSampleCnt >= 1);
  24. int colorValuesPerPixel = renderTargetSampleCnt;
  25. if (renderTargetSampleCnt > 1) {
  26. // Worse case, we own the resolve buffer so that is one more sample per pixel.
  27. colorValuesPerPixel += 1;
  28. }
  29. SkASSERT(kUnknown_GrPixelConfig != desc.fConfig);
  30. SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig));
  31. size_t colorBytes = (size_t) width * height * GrBytesPerPixel(desc.fConfig);
  32. // This would be a nice assert to have (i.e., we aren't creating 0 width/height surfaces).
  33. // Unfortunately Chromium seems to want to do this.
  34. //SkASSERT(colorBytes > 0);
  35. size = colorValuesPerPixel * colorBytes;
  36. size += colorBytes/3; // in case we have to mipmap
  37. } else {
  38. SkASSERT(renderTargetSampleCnt == 1);
  39. if (GrPixelConfigIsCompressed(desc.fConfig)) {
  40. size = GrCompressedFormatDataSize(desc.fConfig, width, height);
  41. } else {
  42. size = (size_t)width * height * GrBytesPerPixel(desc.fConfig);
  43. }
  44. size += size/3; // in case we have to mipmap
  45. }
  46. return size;
  47. }
  48. size_t GrSurface::ComputeSize(GrPixelConfig config,
  49. int width,
  50. int height,
  51. int colorSamplesPerPixel,
  52. GrMipMapped mipMapped,
  53. bool binSize) {
  54. size_t colorSize;
  55. width = binSize ? GrResourceProvider::MakeApprox(width) : width;
  56. height = binSize ? GrResourceProvider::MakeApprox(height) : height;
  57. SkASSERT(kUnknown_GrPixelConfig != config);
  58. if (GrPixelConfigIsCompressed(config)) {
  59. colorSize = GrCompressedFormatDataSize(config, width, height);
  60. } else {
  61. colorSize = (size_t)width * height * GrBytesPerPixel(config);
  62. }
  63. SkASSERT(colorSize > 0);
  64. size_t finalSize = colorSamplesPerPixel * colorSize;
  65. if (GrMipMapped::kYes == mipMapped) {
  66. // We don't have to worry about the mipmaps being a different size than
  67. // we'd expect because we never change fDesc.fWidth/fHeight.
  68. finalSize += colorSize/3;
  69. }
  70. return finalSize;
  71. }
  72. //////////////////////////////////////////////////////////////////////////////
  73. bool GrSurface::hasPendingRead() const {
  74. const GrTexture* thisTex = this->asTexture();
  75. if (thisTex && thisTex->internalHasPendingRead()) {
  76. return true;
  77. }
  78. const GrRenderTarget* thisRT = this->asRenderTarget();
  79. if (thisRT && thisRT->internalHasPendingRead()) {
  80. return true;
  81. }
  82. return false;
  83. }
  84. bool GrSurface::hasPendingWrite() const {
  85. const GrTexture* thisTex = this->asTexture();
  86. if (thisTex && thisTex->internalHasPendingWrite()) {
  87. return true;
  88. }
  89. const GrRenderTarget* thisRT = this->asRenderTarget();
  90. if (thisRT && thisRT->internalHasPendingWrite()) {
  91. return true;
  92. }
  93. return false;
  94. }
  95. bool GrSurface::hasPendingIO() const {
  96. const GrTexture* thisTex = this->asTexture();
  97. if (thisTex && thisTex->internalHasPendingIO()) {
  98. return true;
  99. }
  100. const GrRenderTarget* thisRT = this->asRenderTarget();
  101. if (thisRT && thisRT->internalHasPendingIO()) {
  102. return true;
  103. }
  104. return false;
  105. }
  106. void GrSurface::onRelease() {
  107. this->invokeReleaseProc();
  108. this->INHERITED::onRelease();
  109. }
  110. void GrSurface::onAbandon() {
  111. this->invokeReleaseProc();
  112. this->INHERITED::onAbandon();
  113. }