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 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
texels, | 901 success = this->uploadCompressedTexData(glTex->desc(), glTex->target(),
texels, |
902 kWrite_UploadType, left, top, wi
dth, height); | 902 kWrite_UploadType, left, top, wi
dth, height); |
903 } else { | 903 } else { |
904 success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_Upl
oadType, | 904 success = this->uploadTexData(glTex->desc(), glTex->target(), kWrite_Upl
oadType, |
905 left, top, width, height, config, texels); | 905 left, top, width, height, config, texels); |
906 } | 906 } |
907 | 907 |
908 return success; | 908 return success; |
909 } | 909 } |
910 | 910 |
911 bool GrGLGpu::onTransferPixels(GrSurface* surface, | 911 bool GrGLGpu::onTransferPixels(GrTexture* texture, |
912 int left, int top, int width, int height, | 912 int left, int top, int width, int height, |
913 GrPixelConfig config, GrBuffer* transferBuffer, | 913 GrPixelConfig config, GrBuffer* transferBuffer, |
914 size_t offset, size_t rowBytes) { | 914 size_t offset, size_t rowBytes) { |
915 GrGLTexture* glTex = static_cast<GrGLTexture*>(surface->asTexture()); | 915 GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
916 | 916 |
917 if (!check_write_and_transfer_input(glTex, surface, config)) { | 917 if (!check_write_and_transfer_input(glTex, texture, config)) { |
918 return false; | 918 return false; |
919 } | 919 } |
920 | 920 |
921 // For the moment, can't transfer compressed data | 921 // For the moment, can't transfer compressed data |
922 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { | 922 if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
923 return false; | 923 return false; |
924 } | 924 } |
925 | 925 |
926 this->setScratchTextureUnit(); | 926 this->setScratchTextureUnit(); |
927 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); | 927 GL_CALL(BindTexture(glTex->target(), glTex->textureID())); |
928 | 928 |
929 SkASSERT(!transferBuffer->isMapped()); | 929 SkASSERT(!transferBuffer->isMapped()); |
930 SkASSERT(!transferBuffer->isCPUBacked()); | 930 SkASSERT(!transferBuffer->isCPUBacked()); |
931 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); | 931 const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); |
932 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer); | 932 this->bindBuffer(kXferCpuToGpu_GrBufferType, glBuffer); |
933 | 933 |
934 bool success = false; | 934 bool success = false; |
935 GrMipLevel mipLevel; | 935 GrMipLevel mipLevel; |
936 mipLevel.fPixels = transferBuffer; | 936 mipLevel.fPixels = (void*)offset; |
937 mipLevel.fRowBytes = rowBytes; | 937 mipLevel.fRowBytes = rowBytes; |
938 SkSTArray<1, GrMipLevel> texels; | 938 SkSTArray<1, GrMipLevel> texels; |
939 texels.push_back(mipLevel); | 939 texels.push_back(mipLevel); |
940 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo
adType, | 940 success = this->uploadTexData(glTex->desc(), glTex->target(), kTransfer_Uplo
adType, |
941 left, top, width, height, config, texels); | 941 left, top, width, height, config, texels); |
942 return success; | 942 return success; |
943 } | 943 } |
944 | 944 |
945 // For GL_[UN]PACK_ALIGNMENT. | 945 // For GL_[UN]PACK_ALIGNMENT. |
946 static inline GrGLint config_alignment(GrPixelConfig config) { | 946 static inline GrGLint config_alignment(GrPixelConfig config) { |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 GrGLenum target, | 1198 GrGLenum target, |
1199 UploadType uploadType, | 1199 UploadType uploadType, |
1200 int left, int top, int width, int height, | 1200 int left, int top, int width, int height, |
1201 GrPixelConfig dataConfig, | 1201 GrPixelConfig dataConfig, |
1202 const SkTArray<GrMipLevel>& texels) { | 1202 const SkTArray<GrMipLevel>& texels) { |
1203 // If we're uploading compressed data then we should be using uploadCompress
edTexData | 1203 // If we're uploading compressed data then we should be using uploadCompress
edTexData |
1204 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); | 1204 SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
1205 | 1205 |
1206 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); | 1206 SkASSERT(this->caps()->isConfigTexturable(desc.fConfig)); |
1207 | 1207 |
| 1208 // unbind any previous transfer buffer if not transferring |
| 1209 auto& xferBufferState = fHWBufferState[kXferCpuToGpu_GrBufferType]; |
| 1210 if (kTransfer_UploadType != uploadType && |
| 1211 SK_InvalidUniqueID != xferBufferState.fBoundBufferUniqueID) { |
| 1212 GL_CALL(BindBuffer(xferBufferState.fGLTarget, 0)); |
| 1213 xferBufferState.invalidate(); |
| 1214 } |
| 1215 |
1208 // texels is const. | 1216 // texels is const. |
1209 // But we may need to flip the texture vertically to prepare it. | 1217 // But we may need to flip the texture vertically to prepare it. |
1210 // Rather than flip in place and alter the incoming data, | 1218 // Rather than flip in place and alter the incoming data, |
1211 // we allocate a new buffer to flip into. | 1219 // we allocate a new buffer to flip into. |
1212 // This means we need to make a non-const shallow copy of texels. | 1220 // This means we need to make a non-const shallow copy of texels. |
1213 SkTArray<GrMipLevel> texelsShallowCopy(texels); | 1221 SkTArray<GrMipLevel> texelsShallowCopy(texels); |
1214 | 1222 |
1215 for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >=
0; | 1223 for (int currentMipLevel = texelsShallowCopy.count() - 1; currentMipLevel >=
0; |
1216 currentMipLevel--) { | 1224 currentMipLevel--) { |
1217 SkASSERT(texelsShallowCopy[currentMipLevel].fPixels || kTransfer_UploadT
ype == uploadType); | 1225 SkASSERT(texelsShallowCopy[currentMipLevel].fPixels || kTransfer_UploadT
ype == uploadType); |
(...skipping 3469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4687 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || | 4695 if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() || |
4688 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { | 4696 GR_GL_TEXTURE_RECTANGLE == glTexture->target()) { |
4689 copyParams->fFilter = GrTextureParams::kNone_FilterMode; | 4697 copyParams->fFilter = GrTextureParams::kNone_FilterMode; |
4690 copyParams->fWidth = texture->width(); | 4698 copyParams->fWidth = texture->width(); |
4691 copyParams->fHeight = texture->height(); | 4699 copyParams->fHeight = texture->height(); |
4692 return true; | 4700 return true; |
4693 } | 4701 } |
4694 } | 4702 } |
4695 return false; | 4703 return false; |
4696 } | 4704 } |
| 4705 |
| 4706 GrFence SK_WARN_UNUSED_RESULT GrGLGpu::insertFence() const { |
| 4707 GrGLsync fence; |
| 4708 GL_CALL_RET(fence, FenceSync(GR_GL_SYNC_GPU_COMMANDS_COMPLETE, 0)); |
| 4709 return (GrFence)fence; |
| 4710 } |
| 4711 |
| 4712 bool GrGLGpu::waitFence(GrFence fence) const { |
| 4713 const GrGLuint64 kTimeout = 1000; |
| 4714 GrGLenum result; |
| 4715 GL_CALL_RET(result, ClientWaitSync((GrGLsync)fence, GR_GL_SYNC_FLUSH_COMMAND
S_BIT, kTimeout)); |
| 4716 return (GR_GL_CONDITION_SATISFIED == result); |
| 4717 } |
| 4718 |
| 4719 void GrGLGpu::deleteFence(GrFence fence) const { |
| 4720 GL_CALL(DeleteSync((GrGLsync)fence)); |
| 4721 } |
OLD | NEW |