| 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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 } | 589 } |
| 590 | 590 |
| 591 if (success) { | 591 if (success) { |
| 592 texture->texturePriv().dirtyMipMaps(true); | 592 texture->texturePriv().dirtyMipMaps(true); |
| 593 return true; | 593 return true; |
| 594 } | 594 } |
| 595 | 595 |
| 596 return false; | 596 return false; |
| 597 } | 597 } |
| 598 | 598 |
| 599 static bool adjust_pixel_ops_params(int surfaceWidth, | |
| 600 int surfaceHeight, | |
| 601 size_t bpp, | |
| 602 int* left, int* top, int* width, int* height
, | |
| 603 const void** data, | |
| 604 size_t* rowBytes) { | |
| 605 if (!*rowBytes) { | |
| 606 *rowBytes = *width * bpp; | |
| 607 } | |
| 608 | |
| 609 SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height); | |
| 610 SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight); | |
| 611 | |
| 612 if (!subRect.intersect(bounds)) { | |
| 613 return false; | |
| 614 } | |
| 615 *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + | |
| 616 (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); | |
| 617 | |
| 618 *left = subRect.fLeft; | |
| 619 *top = subRect.fTop; | |
| 620 *width = subRect.width(); | |
| 621 *height = subRect.height(); | |
| 622 return true; | |
| 623 } | |
| 624 | |
| 625 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, | 599 static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
| 626 const GrGLInterface* interface) { | 600 const GrGLInterface* interface) { |
| 627 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { | 601 if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
| 628 return GR_GL_GET_ERROR(interface); | 602 return GR_GL_GET_ERROR(interface); |
| 629 } else { | 603 } else { |
| 630 return CHECK_ALLOC_ERROR(interface); | 604 return CHECK_ALLOC_ERROR(interface); |
| 631 } | 605 } |
| 632 } | 606 } |
| 633 | 607 |
| 634 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, | 608 bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
| 635 bool isNewTexture, | 609 bool isNewTexture, |
| 636 int left, int top, int width, int height, | 610 int left, int top, int width, int height, |
| 637 GrPixelConfig dataConfig, | 611 GrPixelConfig dataConfig, |
| 638 const void* data, | 612 const void* data, |
| 639 size_t rowBytes) { | 613 size_t rowBytes) { |
| 640 SkASSERT(data || isNewTexture); | 614 SkASSERT(data || isNewTexture); |
| 641 | 615 |
| 642 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 616 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
| 643 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 617 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 644 | 618 |
| 645 size_t bpp = GrBytesPerPixel(dataConfig); | 619 size_t bpp = GrBytesPerPixel(dataConfig); |
| 646 if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, | 620 if (!GrSurfacePriv::AdjustWritePixelParams(desc.fWidth, desc.fHeight, bpp, &
left, &top, |
| 647 &width, &height, &data, &rowBytes)) { | 621 &width, &height, &data, &rowBytes
)) { |
| 648 return false; | 622 return false; |
| 649 } | 623 } |
| 650 size_t trimRowBytes = width * bpp; | 624 size_t trimRowBytes = width * bpp; |
| 651 | 625 |
| 652 // in case we need a temporary, trimmed copy of the src pixels | 626 // in case we need a temporary, trimmed copy of the src pixels |
| 653 SkAutoSMalloc<128 * 128> tempStorage; | 627 SkAutoSMalloc<128 * 128> tempStorage; |
| 654 | 628 |
| 655 // We currently lazily create MIPMAPs when the we see a draw with | 629 // We currently lazily create MIPMAPs when the we see a draw with |
| 656 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the | 630 // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that
the |
| 657 // MIP levels are all created when the texture is created. So for now we don
't use | 631 // MIP levels are all created when the texture is created. So for now we don
't use |
| (...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1774 return false; | 1748 return false; |
| 1775 } | 1749 } |
| 1776 | 1750 |
| 1777 GrGLenum format = 0; | 1751 GrGLenum format = 0; |
| 1778 GrGLenum type = 0; | 1752 GrGLenum type = 0; |
| 1779 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); | 1753 bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); |
| 1780 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { | 1754 if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
| 1781 return false; | 1755 return false; |
| 1782 } | 1756 } |
| 1783 size_t bpp = GrBytesPerPixel(config); | 1757 size_t bpp = GrBytesPerPixel(config); |
| 1784 if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, | 1758 if (!GrSurfacePriv::AdjustReadPixelParams(target->width(), target->height(),
bpp, |
| 1785 &left, &top, &width, &height, | 1759 &left, &top, &width, &height, |
| 1786 const_cast<const void**>(&buffer), | 1760 &buffer, |
| 1787 &rowBytes)) { | 1761 &rowBytes)) { |
| 1788 return false; | 1762 return false; |
| 1789 } | 1763 } |
| 1790 | 1764 |
| 1791 // resolve the render target if necessary | 1765 // resolve the render target if necessary |
| 1792 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); | 1766 GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
| 1793 switch (tgt->getResolveType()) { | 1767 switch (tgt->getResolveType()) { |
| 1794 case GrGLRenderTarget::kCantResolve_ResolveType: | 1768 case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1795 return false; | 1769 return false; |
| 1796 case GrGLRenderTarget::kAutoResolves_ResolveType: | 1770 case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1797 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); | 1771 this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkI
Rect::EmptyIRect()); |
| (...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3156 this->setVertexArrayID(gpu, 0); | 3130 this->setVertexArrayID(gpu, 0); |
| 3157 } | 3131 } |
| 3158 int attrCount = gpu->glCaps().maxVertexAttributes(); | 3132 int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3159 if (fDefaultVertexArrayAttribState.count() != attrCount) { | 3133 if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3160 fDefaultVertexArrayAttribState.resize(attrCount); | 3134 fDefaultVertexArrayAttribState.resize(attrCount); |
| 3161 } | 3135 } |
| 3162 attribState = &fDefaultVertexArrayAttribState; | 3136 attribState = &fDefaultVertexArrayAttribState; |
| 3163 } | 3137 } |
| 3164 return attribState; | 3138 return attribState; |
| 3165 } | 3139 } |
| OLD | NEW |