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 29 matching lines...) Expand all Loading... | |
40 } | 40 } |
41 | 41 |
42 return storageFormat; | 42 return storageFormat; |
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 static void texImage2D(WebGraphicsContext3D* context3d, | |
51 const gfx::Size& size, | |
52 GLenum format, | |
53 bool useTextureStorageExt) | |
54 { | |
55 if (useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | |
56 GLenum storageFormat = textureToStorageFormat(format); | |
57 context3d->texStorage2DEXT( | |
58 GL_TEXTURE_2D, 1, storageFormat, size.width(), size.height()); | |
59 } else { | |
60 context3d->texImage2D(GL_TEXTURE_2D, | |
61 0, | |
62 format, | |
63 size.width(), | |
64 size.height(), | |
65 0, | |
66 format, | |
67 GL_UNSIGNED_BYTE, | |
68 0); | |
69 } | |
70 } | |
71 | |
50 ResourceProvider::Resource::Resource() | 72 ResourceProvider::Resource::Resource() |
51 : glId(0) | 73 : glId(0) |
52 , glPixelBufferId(0) | 74 , glPixelBufferId(0) |
75 , glUploadQueryId(0) | |
53 , pixels(0) | 76 , pixels(0) |
54 , pixelBuffer(0) | 77 , pixelBuffer(0) |
55 , pool(0) | 78 , pool(0) |
56 , lockForReadCount(0) | 79 , lockForReadCount(0) |
57 , lockedForWrite(false) | 80 , lockedForWrite(false) |
58 , external(false) | 81 , external(false) |
59 , exported(false) | 82 , exported(false) |
60 , markedForDeletion(false) | 83 , markedForDeletion(false) |
61 , size() | 84 , size() |
62 , format(0) | 85 , format(0) |
63 , type(static_cast<ResourceType>(0)) | 86 , type(static_cast<ResourceType>(0)) |
64 { | 87 { |
65 } | 88 } |
66 | 89 |
67 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format) | 90 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const gfx::Si ze& size, GLenum format) |
68 : glId(textureId) | 91 : glId(textureId) |
69 , glPixelBufferId(0) | 92 , glPixelBufferId(0) |
93 , glUploadQueryId(0) | |
70 , pixels(0) | 94 , pixels(0) |
71 , pixelBuffer(0) | 95 , pixelBuffer(0) |
72 , pool(pool) | 96 , pool(pool) |
73 , lockForReadCount(0) | 97 , lockForReadCount(0) |
74 , lockedForWrite(false) | 98 , lockedForWrite(false) |
75 , external(false) | 99 , external(false) |
76 , exported(false) | 100 , exported(false) |
77 , markedForDeletion(false) | 101 , markedForDeletion(false) |
78 , size(size) | 102 , size(size) |
79 , format(format) | 103 , format(format) |
80 , type(GLTexture) | 104 , type(GLTexture) |
81 { | 105 { |
82 } | 106 } |
83 | 107 |
84 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format) | 108 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format) |
85 : glId(0) | 109 : glId(0) |
86 , glPixelBufferId(0) | 110 , glPixelBufferId(0) |
111 , glUploadQueryId(0) | |
87 , pixels(pixels) | 112 , pixels(pixels) |
88 , pixelBuffer(0) | 113 , pixelBuffer(0) |
89 , pool(pool) | 114 , pool(pool) |
90 , lockForReadCount(0) | 115 , lockForReadCount(0) |
91 , lockedForWrite(false) | 116 , lockedForWrite(false) |
92 , external(false) | 117 , external(false) |
93 , exported(false) | 118 , exported(false) |
94 , markedForDeletion(false) | 119 , markedForDeletion(false) |
95 , size(size) | 120 , size(size) |
96 , format(format) | 121 , format(format) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 DCHECK(context3d); | 185 DCHECK(context3d); |
161 GLC(context3d, textureId = context3d->createTexture()); | 186 GLC(context3d, textureId = context3d->createTexture()); |
162 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 187 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
163 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); | 188 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); |
164 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); | 189 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); |
165 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); | 190 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); |
166 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); | 191 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); |
167 | 192 |
168 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 193 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
170 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 195 |
171 GLenum storageFormat = textureToStorageFormat(format); | 196 texImage2D(context3d, size, format, m_useTextureStorageExt); |
172 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); | |
173 } else | |
174 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | |
175 | 197 |
176 ResourceId id = m_nextId++; | 198 ResourceId id = m_nextId++; |
177 Resource resource(textureId, pool, size, format); | 199 Resource resource(textureId, pool, size, format); |
178 m_resources[id] = resource; | 200 m_resources[id] = resource; |
179 return id; | 201 return id; |
180 } | 202 } |
181 | 203 |
182 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) | 204 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) |
183 { | 205 { |
184 DCHECK(m_threadChecker.CalledOnValidThread()); | 206 DCHECK(m_threadChecker.CalledOnValidThread()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 } | 250 } |
229 | 251 |
230 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 252 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
231 { | 253 { |
232 Resource* resource = &it->second; | 254 Resource* resource = &it->second; |
233 if (resource->glId && !resource->external) { | 255 if (resource->glId && !resource->external) { |
234 WebGraphicsContext3D* context3d = m_context->context3D(); | 256 WebGraphicsContext3D* context3d = m_context->context3D(); |
235 DCHECK(context3d); | 257 DCHECK(context3d); |
236 GLC(context3d, context3d->deleteTexture(resource->glId)); | 258 GLC(context3d, context3d->deleteTexture(resource->glId)); |
237 } | 259 } |
260 if (resource->glUploadQueryId) { | |
261 WebGraphicsContext3D* context3d = m_context->context3D(); | |
262 DCHECK(context3d); | |
263 GLC(context3d, context3d->deleteQueryEXT(resource->glUploadQueryId)); | |
264 } | |
238 if (resource->glPixelBufferId) { | 265 if (resource->glPixelBufferId) { |
239 WebGraphicsContext3D* context3d = m_context->context3D(); | 266 WebGraphicsContext3D* context3d = m_context->context3D(); |
240 DCHECK(context3d); | 267 DCHECK(context3d); |
241 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); | 268 GLC(context3d, context3d->deleteBuffer(resource->glPixelBufferId)); |
242 } | 269 } |
243 if (resource->pixels) | 270 if (resource->pixels) |
244 delete[] resource->pixels; | 271 delete[] resource->pixels; |
245 if (resource->pixelBuffer) | 272 if (resource->pixelBuffer) |
246 delete[] resource->pixelBuffer; | 273 delete[] resource->pixelBuffer; |
247 | 274 |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 resource->size.width(), | 852 resource->size.width(), |
826 resource->size.height()); | 853 resource->size.height()); |
827 src.setPixels(resource->pixelBuffer); | 854 src.setPixels(resource->pixelBuffer); |
828 | 855 |
829 ScopedWriteLockSoftware lock(this, id); | 856 ScopedWriteLockSoftware lock(this, id); |
830 SkCanvas* dest = lock.skCanvas(); | 857 SkCanvas* dest = lock.skCanvas(); |
831 dest->writePixels(src, 0, 0); | 858 dest->writePixels(src, 0, 0); |
832 } | 859 } |
833 } | 860 } |
834 | 861 |
862 void ResourceProvider::beginSetPixels(ResourceId id) | |
863 { | |
864 DCHECK(m_threadChecker.CalledOnValidThread()); | |
865 ResourceMap::iterator it = m_resources.find(id); | |
866 CHECK(it != m_resources.end()); | |
867 Resource* resource = &it->second; | |
868 DCHECK(!resource->lockedForWrite); | |
869 DCHECK(!resource->lockForReadCount); | |
870 DCHECK(!resource->external); | |
871 DCHECK(!resource->exported); | |
872 | |
873 if (resource->glId) { | |
874 WebGraphicsContext3D* context3d = m_context->context3D(); | |
875 DCHECK(context3d); | |
876 DCHECK(resource->glPixelBufferId); | |
877 lockForWrite(id); | |
piman
2012/11/27 00:40:01
We should do this for both software and GL. All it
reveman
2012/11/27 03:22:48
Done.
| |
878 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | |
879 context3d->bindBuffer( | |
880 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | |
881 resource->glPixelBufferId); | |
882 if (!resource->glUploadQueryId) | |
883 resource->glUploadQueryId = context3d->createQueryEXT(); | |
884 context3d->beginQueryEXT( | |
885 GL_ASYNC_TEXTURES_UPLOADED_CHROMIUM, resource->glUploadQueryId); | |
886 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | |
887 0, /* level */ | |
888 0, /* x */ | |
889 0, /* y */ | |
890 resource->size.width(), | |
891 resource->size.height(), | |
892 resource->format, | |
893 GL_UNSIGNED_BYTE, | |
894 NULL); | |
895 context3d->endQueryEXT(GL_ASYNC_TEXTURES_UPLOADED_CHROMIUM); | |
896 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
897 } | |
898 | |
899 if (resource->pixels) | |
900 setPixelsFromBuffer(id); | |
901 } | |
902 | |
903 bool ResourceProvider::didSetPixelsComplete(ResourceId id) { | |
904 DCHECK(m_threadChecker.CalledOnValidThread()); | |
905 ResourceMap::iterator it = m_resources.find(id); | |
906 CHECK(it != m_resources.end()); | |
907 Resource* resource = &it->second; | |
908 | |
909 if (resource->glId) { | |
910 WebGraphicsContext3D* context3d = m_context->context3D(); | |
911 DCHECK(context3d); | |
912 DCHECK(resource->glUploadQueryId); | |
913 DCHECK(resource->lockedForWrite); | |
914 unsigned complete = 1; | |
915 context3d->getQueryObjectuivEXT( | |
916 resource->glUploadQueryId, | |
917 GL_QUERY_RESULT_AVAILABLE_EXT, | |
918 &complete); | |
919 if (!complete) | |
920 return false; | |
921 | |
922 unlockForWrite(id); | |
piman
2012/11/27 00:40:01
It would be useful I think to add some state on th
reveman
2012/11/27 03:22:48
Done.
| |
923 } | |
924 | |
925 return true; | |
926 } | |
927 | |
928 void ResourceProvider::abortSetPixels(ResourceId id) { | |
929 DCHECK(m_threadChecker.CalledOnValidThread()); | |
930 ResourceMap::iterator it = m_resources.find(id); | |
931 CHECK(it != m_resources.end()); | |
932 Resource* resource = &it->second; | |
933 | |
934 if (resource->glId) { | |
935 WebGraphicsContext3D* context3d = m_context->context3D(); | |
936 DCHECK(context3d); | |
937 DCHECK(resource->glUploadQueryId); | |
938 DCHECK(resource->lockedForWrite); | |
939 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | |
940 texImage2D(context3d, | |
941 resource->size, | |
942 resource->format, | |
943 m_useTextureStorageExt); | |
944 | |
945 unlockForWrite(id); | |
946 } | |
947 } | |
948 | |
835 } // namespace cc | 949 } // namespace cc |
OLD | NEW |