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 #include "GrGLGpu.h" | 8 #include "GrGLGpu.h" |
9 #include "GrGLBuffer.h" | 9 #include "GrGLBuffer.h" |
10 #include "GrGLGLSL.h" | 10 #include "GrGLGLSL.h" |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 } | 888 } |
889 | 889 |
890 if (success) { | 890 if (success) { |
891 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); | 891 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
892 this->didWriteToSurface(surface, &rect); | 892 this->didWriteToSurface(surface, &rect); |
893 } | 893 } |
894 | 894 |
895 return success; | 895 return success; |
896 } | 896 } |
897 | 897 |
898 bool GrGLGpu::onTransferPixels(GrTexture* texture, | 898 bool GrGLGpu::onTransferPixels(GrSurface* surface, |
899 int left, int top, int width, int height, | 899 int left, int top, int width, int height, |
900 GrPixelConfig config, GrBuffer* transferBuffer, | 900 GrPixelConfig config, GrBuffer* transferBuffer, |
901 size_t offset, size_t rowBytes) { | 901 size_t offset, size_t rowBytes) { |
902 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); | 902 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); |
903 | 903 |
904 if (!check_write_and_transfer_input(glTex, texture, config)) { | 904 if (!check_write_and_transfer_input(glTex, surface, config)) { |
905 return false; | 905 return false; |
906 } | 906 } |
907 | 907 |
908 // For the moment, can't transfer compressed data | 908 // For the moment, can't transfer compressed data |
909 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 909 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
910 return false; | 910 return false; |
911 } | 911 } |
912 | 912 |
913 this->setScratchTextureUnit(); | 913 this->setScratchTextureUnit(); |
914 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 914 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
915 | 915 |
916 SkASSERT(!transferBuffer->isMapped()); | 916 SkASSERT(!transferBuffer->isMapped()); |
917 SkASSERT(!transferBuffer->isCPUBacked()); | 917 SkASSERT(!transferBuffer->isCPUBacked()); |
918 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); | 918 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); |
919 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer); | 919 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer); |
920 | 920 |
921 bool success = false; | 921 bool success = false; |
922 GrMipLevel mipLevel; | 922 GrMipLevel mipLevel; |
923 mipLevel.fPixels = (void*)offset; | 923 mipLevel.fPixels = transferBuffer; |
924 mipLevel.fRowBytes = rowBytes; | 924 mipLevel.fRowBytes = rowBytes; |
925 SkSTArray<1, GrMipLevel> texels; | 925 SkSTArray<1, GrMipLevel> texels; |
926 texels.push_back(mipLevel); | 926 texels.push_back(mipLevel); |
927 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo
adType, | 927 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo
adType, |
928 left, top, width, height, config, texels); | 928 left, top, width, height, config, texels); |
929 | |
930 if (success) { | 929 if (success) { |
931 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); | 930 SkIRect rect = SkIRect::MakeXYWH(left, top, width, height); |
932 this->didWriteToSurface(texture, &rect); | 931 this->didWriteToSurface(surface, &rect); |
933 return true; | 932 return true; |
934 } | 933 } |
935 | 934 |
936 return false; | 935 return false; |
937 } | 936 } |
938 | 937 |
939 // For GL_[UN]PACK_ALIGNMENT. | 938 // For GL_[UN]PACK_ALIGNMENT. |
940 static inline GrGLint config_alignment(GrPixelConfig config) { | 939 static inline GrGLint config_alignment(GrPixelConfig config) { |
941 SkASSERT(!GrPixelConfigIsCompressed(config)); | 940 SkASSERT(!GrPixelConfigIsCompressed(config)); |
942 switch (config) { | 941 switch (config) { |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1190 GrGLenum target, | 1189 GrGLenum target, |
1191 UploadType uploadType, | 1190 UploadType uploadType, |
1192 int left, int top, int width, int height, | 1191 int left, int top, int width, int height, |
1193 GrPixelConfig dataConfig, | 1192 GrPixelConfig dataConfig, |
1194 const SkTArray<GrMipLevel>& texels) { | 1193 const SkTArray<GrMipLevel>& texels) { |
1195 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 1194 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
1196 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 1195 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
1197 | 1196 |
1198 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); | 1197 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); |
1199 | 1198 |
1200 // unbind any previous transfer buffer if not transferring | |
1201 auto& xferBufferState = fHWBufferState[kXferCpuToGpu_GrBufferType]; | |
1202 if (kTransfer_UploadType != uploadType && | |
1203 SK_InvalidUniqueID != xferBufferState.fBoundBufferUniqueID) { | |
1204 GL_CALL(BindBuffer(xferBufferState.fGLTarget, 0)); | |
1205 xferBufferState.invalidate(); | |
1206 } | |
1207 | |
1208 // texels is const. | 1199 // texels is const. |
1209 // But we may need to flip the texture vertically to prepare it. | 1200 // But we may need to flip the texture vertically to prepare it. |
1210 // Rather than flip in place and alter the incoming data, | 1201 // Rather than flip in place and alter the incoming data, |
1211 // we allocate a new buffer to flip into. | 1202 // we allocate a new buffer to flip into. |
1212 // This means we need to make a non-const shallow copy of texels. | 1203 // This means we need to make a non-const shallow copy of texels. |
1213 SkTArray<GrMipLevel> texelsShallowCopy(texels); | 1204 SkTArray<GrMipLevel> texelsShallowCopy(texels); |
1214 | 1205 |
1215 for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >=
0; | 1206 for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >=
0; |
1216 currentMipLevel--) { | 1207 currentMipLevel--) { |
1217 SkASSERT(texelsShallowCopy[currentMipLevel].fPixels || kTransfer_UploadT
ype == uploadType); | 1208 SkASSERT(texelsShallowCopy[currentMipLevel].fPixels || kTransfer_UploadT
ype == uploadType); |
(...skipping 3070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4288 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4279 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4289 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4280 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4290 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4281 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4291 copyParams->fWidth = texture->width(); | 4282 copyParams->fWidth = texture->width(); |
4292 copyParams->fHeight = texture->height(); | 4283 copyParams->fHeight = texture->height(); |
4293 return true; | 4284 return true; |
4294 } | 4285 } |
4295 } | 4286 } |
4296 return false; | 4287 return false; |
4297 } | 4288 } |
OLD | NEW |