OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
9 #include "GrGLGpu.h" | 9 #include "GrGLGpu.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 2278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 default: | 2289 default: |
2290 SkFAIL("Unknown resolve type"); | 2290 SkFAIL("Unknown resolve type"); |
2291 } | 2291 } |
2292 | 2292 |
2293 const GrGLIRect& glvp = renderTarget->getViewport(); | 2293 const GrGLIRect& glvp = renderTarget->getViewport(); |
2294 | 2294 |
2295 // the read rect is viewport-relative | 2295 // the read rect is viewport-relative |
2296 GrGLIRect readRect; | 2296 GrGLIRect readRect; |
2297 readRect.setRelativeTo(glvp, left, top, width, height, renderTarget->origin(
)); | 2297 readRect.setRelativeTo(glvp, left, top, width, height, renderTarget->origin(
)); |
2298 | 2298 |
2299 size_t tightRowBytes = GrBytesPerPixel(config) * width; | 2299 size_t bytesPerPixel = GrBytesPerPixel(config); |
| 2300 size_t tightRowBytes = bytesPerPixel * width; |
2300 | 2301 |
2301 size_t readDstRowBytes = tightRowBytes; | 2302 size_t readDstRowBytes = tightRowBytes; |
2302 void* readDst = buffer; | 2303 void* readDst = buffer; |
2303 | 2304 |
2304 // determine if GL can read using the passed rowBytes or if we need | 2305 // determine if GL can read using the passed rowBytes or if we need |
2305 // a scratch buffer. | 2306 // a scratch buffer. |
2306 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; | 2307 SkAutoSMalloc<32 * sizeof(GrColor)> scratch; |
2307 if (rowBytes != tightRowBytes) { | 2308 if (rowBytes != tightRowBytes) { |
2308 if (this->glCaps().packRowLengthSupport()) { | 2309 if (this->glCaps().packRowLengthSupport() && !(rowBytes % bytesPerPixel)
) { |
2309 SkASSERT(!(rowBytes % sizeof(GrColor))); | |
2310 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, | 2310 GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, |
2311 static_cast<GrGLint>(rowBytes / sizeof(GrColor))
)); | 2311 static_cast<GrGLint>(rowBytes / bytesPerPixel)))
; |
2312 readDstRowBytes = rowBytes; | 2312 readDstRowBytes = rowBytes; |
2313 } else { | 2313 } else { |
2314 scratch.reset(tightRowBytes * height); | 2314 scratch.reset(tightRowBytes * height); |
2315 readDst = scratch.get(); | 2315 readDst = scratch.get(); |
2316 } | 2316 } |
2317 } | 2317 } |
2318 if (flipY && this->glCaps().packFlipYSupport()) { | 2318 if (flipY && this->glCaps().packFlipYSupport()) { |
2319 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); | 2319 GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
2320 } | 2320 } |
2321 GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config))); | 2321 GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, config_alignment(config))); |
(...skipping 24 matching lines...) Expand all Loading... |
2346 char* bottom = top + (height - 1) * rowBytes; | 2346 char* bottom = top + (height - 1) * rowBytes; |
2347 for (int y = 0; y < halfY; y++) { | 2347 for (int y = 0; y < halfY; y++) { |
2348 memcpy(tmpRow, top, tightRowBytes); | 2348 memcpy(tmpRow, top, tightRowBytes); |
2349 memcpy(top, bottom, tightRowBytes); | 2349 memcpy(top, bottom, tightRowBytes); |
2350 memcpy(bottom, tmpRow, tightRowBytes); | 2350 memcpy(bottom, tmpRow, tightRowBytes); |
2351 top += rowBytes; | 2351 top += rowBytes; |
2352 bottom -= rowBytes; | 2352 bottom -= rowBytes; |
2353 } | 2353 } |
2354 } | 2354 } |
2355 } else { | 2355 } else { |
2356 SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes); | 2356 SkASSERT(readDst != buffer); |
| 2357 SkASSERT(rowBytes != tightRowBytes); |
2357 // copy from readDst to buffer while flipping y | 2358 // copy from readDst to buffer while flipping y |
2358 // const int halfY = height >> 1; | 2359 // const int halfY = height >> 1; |
2359 const char* src = reinterpret_cast<const char*>(readDst); | 2360 const char* src = reinterpret_cast<const char*>(readDst); |
2360 char* dst = reinterpret_cast<char*>(buffer); | 2361 char* dst = reinterpret_cast<char*>(buffer); |
2361 if (flipY) { | 2362 if (flipY) { |
2362 dst += (height-1) * rowBytes; | 2363 dst += (height-1) * rowBytes; |
2363 } | 2364 } |
2364 for (int y = 0; y < height; y++) { | 2365 for (int y = 0; y < height; y++) { |
2365 memcpy(dst, src, tightRowBytes); | 2366 memcpy(dst, src, tightRowBytes); |
2366 src += readDstRowBytes; | 2367 src += readDstRowBytes; |
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3823 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 3824 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
3824 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 3825 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
3825 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 3826 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
3826 copyParams->fWidth = texture->width(); | 3827 copyParams->fWidth = texture->width(); |
3827 copyParams->fHeight = texture->height(); | 3828 copyParams->fHeight = texture->height(); |
3828 return true; | 3829 return true; |
3829 } | 3830 } |
3830 } | 3831 } |
3831 return false; | 3832 return false; |
3832 } | 3833 } |
OLD | NEW |