| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrSurface.h" | 8 #include "GrSurface.h" |
| 9 #include "GrContext.h" | 9 #include "GrContext.h" |
| 10 #include "GrSurfacePriv.h" | 10 #include "GrSurfacePriv.h" |
| 11 | 11 |
| 12 #include "SkBitmap.h" | 12 #include "SkBitmap.h" |
| 13 #include "SkGrPriv.h" | 13 #include "SkGrPriv.h" |
| 14 #include "SkImageEncoder.h" | 14 #include "SkImageEncoder.h" |
| 15 #include <stdio.h> | 15 #include <stdio.h> |
| 16 | 16 |
| 17 size_t GrSurface::WorseCaseSize(const GrSurfaceDesc& desc) { | 17 size_t GrSurface::WorseCaseSize(const GrSurfaceDesc& desc) { |
| 18 size_t size; | 18 size_t size; |
| 19 | 19 |
| 20 bool isRenderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); | 20 bool isRenderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
| 21 if (isRenderTarget) { | 21 if (isRenderTarget) { |
| 22 // We own one color value for texture storing the rendering result, |
| 23 // e.g. the actual fbo texture attachment or the resolve texture. |
| 22 // We own one color value for each MSAA sample. | 24 // We own one color value for each MSAA sample. |
| 23 int colorValuesPerPixel = SkTMax(1, desc.fSampleCnt); | 25 size_t colorValues = 1 + static_cast<size_t>(desc.fSampleCnt); |
| 24 if (desc.fSampleCnt) { | 26 |
| 25 // Worse case, we own the resolve buffer so that is one more sample
per pixel. | |
| 26 colorValuesPerPixel += 1; | |
| 27 } | |
| 28 SkASSERT(kUnknown_GrPixelConfig != desc.fConfig); | 27 SkASSERT(kUnknown_GrPixelConfig != desc.fConfig); |
| 29 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); | 28 SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 30 size_t colorBytes = GrBytesPerPixel(desc.fConfig); | 29 size_t colorBytes = GrBytesPerPixel(desc.fConfig); |
| 31 SkASSERT(colorBytes > 0); | 30 SkASSERT(colorBytes > 0); |
| 32 size = colorValuesPerPixel * desc.fWidth * desc.fHeight * colorBytes; | 31 size_t bytesPerColorValue = desc.fWidth * desc.fHeight * colorBytes; |
| 32 size = colorValues * bytesPerColorValue; |
| 33 // Render target that is a texture might have mipmaps in the |
| 34 // rendering target texture. |
| 35 size += bytesPerColorValue / 3; |
| 33 } else { | 36 } else { |
| 34 if (GrPixelConfigIsCompressed(desc.fConfig)) { | 37 if (GrPixelConfigIsCompressed(desc.fConfig)) { |
| 35 size = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH
eight); | 38 size = GrCompressedFormatDataSize(desc.fConfig, desc.fWidth, desc.fH
eight); |
| 36 } else { | 39 } else { |
| 37 size = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fC
onfig); | 40 size = (size_t) desc.fWidth * desc.fHeight * GrBytesPerPixel(desc.fC
onfig); |
| 38 } | 41 } |
| 39 | 42 |
| 40 size += size/3; // in case we have to mipmap | 43 size += size/3; // in case we have to mipmap |
| 41 } | 44 } |
| 42 | 45 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 206 |
| 204 void GrSurface::onRelease() { | 207 void GrSurface::onRelease() { |
| 205 this->invokeReleaseProc(); | 208 this->invokeReleaseProc(); |
| 206 this->INHERITED::onRelease(); | 209 this->INHERITED::onRelease(); |
| 207 } | 210 } |
| 208 | 211 |
| 209 void GrSurface::onAbandon() { | 212 void GrSurface::onAbandon() { |
| 210 this->invokeReleaseProc(); | 213 this->invokeReleaseProc(); |
| 211 this->INHERITED::onAbandon(); | 214 this->INHERITED::onAbandon(); |
| 212 } | 215 } |
| OLD | NEW |