| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resource_provider.h" | 5 #include "cc/resource_provider.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include "base/debug/alias.h" | 9 #include "base/debug/alias.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 static bool isTextureFormatSupportedForStorage(GLenum format) | 45 static bool isTextureFormatSupportedForStorage(GLenum format) |
| 46 { | 46 { |
| 47 return (format == GL_RGBA || format == GL_BGRA_EXT); | 47 return (format == GL_RGBA || format == GL_BGRA_EXT); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ResourceProvider::Resource::Resource() | 50 ResourceProvider::Resource::Resource() |
| 51 : glId(0) | 51 : glId(0) |
| 52 , glPixelBufferId(0) | 52 , glPixelBufferId(0) |
| 53 , glUploadQueryId(0) |
| 53 , pixels(0) | 54 , pixels(0) |
| 54 , pixelBuffer(0) | 55 , pixelBuffer(0) |
| 55 , pool(0) | 56 , pool(0) |
| 56 , lockForReadCount(0) | 57 , lockForReadCount(0) |
| 57 , lockedForWrite(false) | 58 , lockedForWrite(false) |
| 58 , external(false) | 59 , external(false) |
| 59 , exported(false) | 60 , exported(false) |
| 60 , markedForDeletion(false) | 61 , markedForDeletion(false) |
| 62 , pendingSetPixels(false) |
| 61 , size() | 63 , size() |
| 62 , format(0) | 64 , format(0) |
| 63 , filter(0) | 65 , filter(0) |
| 64 , type(static_cast<ResourceType>(0)) | 66 , type(static_cast<ResourceType>(0)) |
| 65 { | 67 { |
| 66 } | 68 } |
| 67 | 69 |
| 68 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si
ze& size, GLenum format, GLenum filter) | 70 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si
ze& size, GLenum format, GLenum filter) |
| 69 : glId(textureId) | 71 : glId(textureId) |
| 70 , glPixelBufferId(0) | 72 , glPixelBufferId(0) |
| 73 , glUploadQueryId(0) |
| 71 , pixels(0) | 74 , pixels(0) |
| 72 , pixelBuffer(0) | 75 , pixelBuffer(0) |
| 73 , pool(pool) | 76 , pool(pool) |
| 74 , lockForReadCount(0) | 77 , lockForReadCount(0) |
| 75 , lockedForWrite(false) | 78 , lockedForWrite(false) |
| 76 , external(false) | 79 , external(false) |
| 77 , exported(false) | 80 , exported(false) |
| 78 , markedForDeletion(false) | 81 , markedForDeletion(false) |
| 82 , pendingSetPixels(false) |
| 79 , size(size) | 83 , size(size) |
| 80 , format(format) | 84 , format(format) |
| 81 , filter(filter) | 85 , filter(filter) |
| 82 , type(GLTexture) | 86 , type(GLTexture) |
| 83 { | 87 { |
| 84 } | 88 } |
| 85 | 89 |
| 86 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size&
size, GLenum format, GLenum filter) | 90 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size&
size, GLenum format, GLenum filter) |
| 87 : glId(0) | 91 : glId(0) |
| 88 , glPixelBufferId(0) | 92 , glPixelBufferId(0) |
| 93 , glUploadQueryId(0) |
| 89 , pixels(pixels) | 94 , pixels(pixels) |
| 90 , pixelBuffer(0) | 95 , pixelBuffer(0) |
| 91 , pool(pool) | 96 , pool(pool) |
| 92 , lockForReadCount(0) | 97 , lockForReadCount(0) |
| 93 , lockedForWrite(false) | 98 , lockedForWrite(false) |
| 94 , external(false) | 99 , external(false) |
| 95 , exported(false) | 100 , exported(false) |
| 96 , markedForDeletion(false) | 101 , markedForDeletion(false) |
| 102 , pendingSetPixels(false) |
| 97 , size(size) | 103 , size(size) |
| 98 , format(format) | 104 , format(format) |
| 99 , filter(filter) | 105 , filter(filter) |
| 100 , type(Bitmap) | 106 , type(Bitmap) |
| 101 { | 107 { |
| 102 } | 108 } |
| 103 | 109 |
| 104 ResourceProvider::Child::Child() | 110 ResourceProvider::Child::Child() |
| 105 { | 111 { |
| 106 } | 112 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 240 } |
| 235 | 241 |
| 236 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 242 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
| 237 { | 243 { |
| 238 Resource* resource = &it->second; | 244 Resource* resource = &it->second; |
| 239 if (resource->glId && !resource->external) { | 245 if (resource->glId && !resource->external) { |
| 240 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); | 246 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 241 DCHECK(context3d); | 247 DCHECK(context3d); |
| 242 GLC(context3d, context3d->deleteTexture(resource->glId)); | 248 GLC(context3d, context3d->deleteTexture(resource->glId)); |
| 243 } | 249 } |
| 250 if (resource->glUploadQueryId) { |
| 251 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 252 DCHECK(context3d); |
| 253 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); |
| 254 } |
| 244 if (resource->glPixelBufferId) { | 255 if (resource->glPixelBufferId) { |
| 245 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); | 256 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 246 DCHECK(context3d); | 257 DCHECK(context3d); |
| 247 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 258 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
| 248 } | 259 } |
| 249 if (resource->pixels) | 260 if (resource->pixels) |
| 250 delete[] resource->pixels; | 261 delete[] resource->pixels; |
| 251 if (resource->pixelBuffer) | 262 if (resource->pixelBuffer) |
| 252 delete[] resource->pixelBuffer; | 263 delete[] resource->pixelBuffer; |
| 253 | 264 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 DCHECK(!resource->lockedForWrite); | 872 DCHECK(!resource->lockedForWrite); |
| 862 | 873 |
| 863 GLC(context3d, context3d->bindTexture(target, resource->glId)); | 874 GLC(context3d, context3d->bindTexture(target, resource->glId)); |
| 864 if (filter != resource->filter) { | 875 if (filter != resource->filter) { |
| 865 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f
ilter)); | 876 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MIN_FILTER, f
ilter)); |
| 866 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f
ilter)); | 877 GLC(context3d, context3d->texParameteri(target, GL_TEXTURE_MAG_FILTER, f
ilter)); |
| 867 resource->filter = filter; | 878 resource->filter = filter; |
| 868 } | 879 } |
| 869 } | 880 } |
| 870 | 881 |
| 882 void ResourceProvider::beginSetPixels(ResourceId id) |
| 883 { |
| 884 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 885 ResourceMap::iterator it = m_resources.find(id); |
| 886 CHECK(it != m_resources.end()); |
| 887 Resource* resource = &it->second; |
| 888 DCHECK(!resource->pendingSetPixels); |
| 889 |
| 890 lockForWrite(id); |
| 891 |
| 892 if (resource->glId) { |
| 893 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 894 DCHECK(context3d); |
| 895 DCHECK(resource->glPixelBufferId); |
| 896 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
| 897 context3d->bindBuffer( |
| 898 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
| 899 resource->glPixelBufferId); |
| 900 if (!resource->glUploadQueryId) |
| 901 resource->glUploadQueryId = context3d->createQueryEXT(); |
| 902 context3d->beginQueryEXT( |
| 903 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
| 904 resource->glUploadQueryId); |
| 905 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
| 906 0, /* level */ |
| 907 0, /* x */ |
| 908 0, /* y */ |
| 909 resource->size.width(), |
| 910 resource->size.height(), |
| 911 resource->format, |
| 912 GL_UNSIGNED_BYTE, |
| 913 NULL); |
| 914 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
| 915 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
| 916 } |
| 917 |
| 918 if (resource->pixels) |
| 919 setPixelsFromBuffer(id); |
| 920 |
| 921 resource->pendingSetPixels = true; |
| 922 } |
| 923 |
| 924 bool ResourceProvider::didSetPixelsComplete(ResourceId id) { |
| 925 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 926 ResourceMap::iterator it = m_resources.find(id); |
| 927 CHECK(it != m_resources.end()); |
| 928 Resource* resource = &it->second; |
| 929 DCHECK(resource->lockedForWrite); |
| 930 DCHECK(resource->pendingSetPixels); |
| 931 |
| 932 if (resource->glId) { |
| 933 WebGraphicsContext3D* context3d = m_outputSurface->context3D(); |
| 934 DCHECK(context3d); |
| 935 DCHECK(resource->glUploadQueryId); |
| 936 unsigned complete = 1; |
| 937 context3d->getQueryObjectuivEXT( |
| 938 resource->glUploadQueryId, |
| 939 GL_QUERY_RESULT_AVAILABLE_EXT, |
| 940 &complete); |
| 941 if (!complete) |
| 942 return false; |
| 943 } |
| 944 |
| 945 resource->pendingSetPixels = false; |
| 946 unlockForWrite(id); |
| 947 |
| 948 return true; |
| 949 } |
| 950 |
| 871 } // namespace cc | 951 } // namespace cc |
| OLD | NEW |