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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 , glPixelBufferId(0) | 52 , glPixelBufferId(0) |
53 , glUploadQueryId(0) | 53 , glUploadQueryId(0) |
54 , pixels(0) | 54 , pixels(0) |
55 , pixelBuffer(0) | 55 , pixelBuffer(0) |
56 , lockForReadCount(0) | 56 , lockForReadCount(0) |
57 , lockedForWrite(false) | 57 , lockedForWrite(false) |
58 , external(false) | 58 , external(false) |
59 , exported(false) | 59 , exported(false) |
60 , markedForDeletion(false) | 60 , markedForDeletion(false) |
61 , pendingSetPixels(false) | 61 , pendingSetPixels(false) |
62 , allocated(false) | |
63 , size() | 62 , size() |
64 , format(0) | 63 , format(0) |
65 , filter(0) | 64 , filter(0) |
66 , type(static_cast<ResourceType>(0)) | 65 , type(static_cast<ResourceType>(0)) |
67 { | 66 { |
68 } | 67 } |
69 | 68 |
70 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size,
GLenum format, GLenum filter) | 69 ResourceProvider::Resource::Resource(unsigned textureId, const gfx::Size& size,
GLenum format, GLenum filter) |
71 : glId(textureId) | 70 : glId(textureId) |
72 , glPixelBufferId(0) | 71 , glPixelBufferId(0) |
73 , glUploadQueryId(0) | 72 , glUploadQueryId(0) |
74 , pixels(0) | 73 , pixels(0) |
75 , pixelBuffer(0) | 74 , pixelBuffer(0) |
76 , lockForReadCount(0) | 75 , lockForReadCount(0) |
77 , lockedForWrite(false) | 76 , lockedForWrite(false) |
78 , external(false) | 77 , external(false) |
79 , exported(false) | 78 , exported(false) |
80 , markedForDeletion(false) | 79 , markedForDeletion(false) |
81 , pendingSetPixels(false) | 80 , pendingSetPixels(false) |
82 , allocated(false) | |
83 , size(size) | 81 , size(size) |
84 , format(format) | 82 , format(format) |
85 , filter(filter) | 83 , filter(filter) |
86 , type(GLTexture) | 84 , type(GLTexture) |
87 { | 85 { |
88 } | 86 } |
89 | 87 |
90 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe
num format, GLenum filter) | 88 ResourceProvider::Resource::Resource(uint8_t* pixels, const gfx::Size& size, GLe
num format, GLenum filter) |
91 : glId(0) | 89 : glId(0) |
92 , glPixelBufferId(0) | 90 , glPixelBufferId(0) |
93 , glUploadQueryId(0) | 91 , glUploadQueryId(0) |
94 , pixels(pixels) | 92 , pixels(pixels) |
95 , pixelBuffer(0) | 93 , pixelBuffer(0) |
96 , lockForReadCount(0) | 94 , lockForReadCount(0) |
97 , lockedForWrite(false) | 95 , lockedForWrite(false) |
98 , external(false) | 96 , external(false) |
99 , exported(false) | 97 , exported(false) |
100 , markedForDeletion(false) | 98 , markedForDeletion(false) |
101 , pendingSetPixels(false) | 99 , pendingSetPixels(false) |
102 , allocated(false) | |
103 , size(size) | 100 , size(size) |
104 , format(format) | 101 , format(format) |
105 , filter(filter) | 102 , filter(filter) |
106 , type(Bitmap) | 103 , type(Bitmap) |
107 { | 104 { |
108 } | 105 } |
109 | 106 |
110 ResourceProvider::Child::Child() | 107 ResourceProvider::Child::Child() |
111 { | 108 { |
112 } | 109 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 { | 176 { |
180 DCHECK_LE(size.width(), m_maxTextureSize); | 177 DCHECK_LE(size.width(), m_maxTextureSize); |
181 DCHECK_LE(size.height(), m_maxTextureSize); | 178 DCHECK_LE(size.height(), m_maxTextureSize); |
182 | 179 |
183 DCHECK(m_threadChecker.CalledOnValidThread()); | 180 DCHECK(m_threadChecker.CalledOnValidThread()); |
184 unsigned textureId = 0; | 181 unsigned textureId = 0; |
185 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 182 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
186 DCHECK(context3d); | 183 DCHECK(context3d); |
187 GLC(context3d, textureId = context3d->createTexture()); | 184 GLC(context3d, textureId = context3d->createTexture()); |
188 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 185 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
189 | |
190 // Set texture properties. Allocation is delayed until needed. | |
191 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 186 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
192 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 187 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
193 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 188 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 189 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
195 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM
IUM, texturePool)); | 190 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM
IUM, texturePool)); |
| 191 |
196 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 192 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
197 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 193 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 194 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
| 195 GLenum storageFormat = textureToStorageFormat(format); |
| 196 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
| 197 } else |
| 198 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
198 | 199 |
199 ResourceId id = m_nextId++; | 200 ResourceId id = m_nextId++; |
200 Resource resource(textureId, size, format, GL_LINEAR); | 201 Resource resource(textureId, size, format, GL_LINEAR); |
201 resource.allocated = false; | |
202 m_resources[id] = resource; | 202 m_resources[id] = resource; |
203 return id; | 203 return id; |
204 } | 204 } |
205 | 205 |
206 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz
e) | 206 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz
e) |
207 { | 207 { |
208 DCHECK(m_threadChecker.CalledOnValidThread()); | 208 DCHECK(m_threadChecker.CalledOnValidThread()); |
209 | 209 |
210 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 210 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
211 | 211 |
212 ResourceId id = m_nextId++; | 212 ResourceId id = m_nextId++; |
213 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); | 213 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); |
214 resource.allocated = true; | |
215 m_resources[id] = resource; | 214 m_resources[id] = resource; |
216 return id; | 215 return id; |
217 } | 216 } |
218 | 217 |
219 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 218 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
220 { | 219 { |
221 DCHECK(m_threadChecker.CalledOnValidThread()); | 220 DCHECK(m_threadChecker.CalledOnValidThread()); |
222 | 221 |
223 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 222 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
224 DCHECK(context3d); | 223 DCHECK(context3d); |
225 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 224 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
226 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 225 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 226 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 227 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
229 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 228 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
230 | 229 |
231 ResourceId id = m_nextId++; | 230 ResourceId id = m_nextId++; |
232 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); | 231 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); |
233 resource.external = true; | 232 resource.external = true; |
234 resource.allocated = true; | |
235 m_resources[id] = resource; | 233 m_resources[id] = resource; |
236 return id; | 234 return id; |
237 } | 235 } |
238 | 236 |
239 void ResourceProvider::deleteResource(ResourceId id) | 237 void ResourceProvider::deleteResource(ResourceId id) |
240 { | 238 { |
241 DCHECK(m_threadChecker.CalledOnValidThread()); | 239 DCHECK(m_threadChecker.CalledOnValidThread()); |
242 ResourceMap::iterator it = m_resources.find(id); | 240 ResourceMap::iterator it = m_resources.find(id); |
243 CHECK(it != m_resources.end()); | 241 CHECK(it != m_resources.end()); |
244 Resource* resource = &it->second; | 242 Resource* resource = &it->second; |
| 243 DCHECK(!resource->lockedForWrite); |
245 DCHECK(!resource->lockForReadCount); | 244 DCHECK(!resource->lockForReadCount); |
246 DCHECK(!resource->markedForDeletion); | 245 DCHECK(!resource->markedForDeletion); |
247 DCHECK(resource->pendingSetPixels || !resource->lockedForWrite); | |
248 | 246 |
249 if (resource->exported) { | 247 if (resource->exported) { |
250 resource->markedForDeletion = true; | 248 resource->markedForDeletion = true; |
251 return; | 249 return; |
252 } else | 250 } else |
253 deleteResourceInternal(it); | 251 deleteResourceInternal(it); |
254 } | 252 } |
255 | 253 |
256 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 254 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
257 { | 255 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) | 288 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) |
291 { | 289 { |
292 DCHECK(m_threadChecker.CalledOnValidThread()); | 290 DCHECK(m_threadChecker.CalledOnValidThread()); |
293 ResourceMap::iterator it = m_resources.find(id); | 291 ResourceMap::iterator it = m_resources.find(id); |
294 CHECK(it != m_resources.end()); | 292 CHECK(it != m_resources.end()); |
295 Resource* resource = &it->second; | 293 Resource* resource = &it->second; |
296 DCHECK(!resource->lockedForWrite); | 294 DCHECK(!resource->lockedForWrite); |
297 DCHECK(!resource->lockForReadCount); | 295 DCHECK(!resource->lockForReadCount); |
298 DCHECK(!resource->external); | 296 DCHECK(!resource->external); |
299 DCHECK(!resource->exported); | 297 DCHECK(!resource->exported); |
300 lazyAllocate(resource); | |
301 | 298 |
302 if (resource->glId) { | 299 if (resource->glId) { |
303 DCHECK(!resource->pendingSetPixels); | |
304 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 300 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
305 DCHECK(context3d); | 301 DCHECK(context3d); |
306 DCHECK(m_textureUploader.get()); | 302 DCHECK(m_textureUploader.get()); |
307 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 303 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
308 m_textureUploader->upload(image, | 304 m_textureUploader->upload(image, |
309 imageRect, | 305 imageRect, |
310 sourceRect, | 306 sourceRect, |
311 destOffset, | 307 destOffset, |
312 resource->format, | 308 resource->format, |
313 resource->size); | 309 resource->size); |
314 } | 310 } |
315 | 311 |
316 if (resource->pixels) { | 312 if (resource->pixels) { |
317 DCHECK(resource->allocated); | |
318 DCHECK(resource->format == GL_RGBA); | 313 DCHECK(resource->format == GL_RGBA); |
319 SkBitmap srcFull; | 314 SkBitmap srcFull; |
320 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); | 315 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR
ect.height()); |
321 srcFull.setPixels(const_cast<uint8_t*>(image)); | 316 srcFull.setPixels(const_cast<uint8_t*>(image)); |
322 SkBitmap srcSubset; | 317 SkBitmap srcSubset; |
323 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 318 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
324 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 319 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
325 srcFull.extractSubset(&srcSubset, skSourceRect); | 320 srcFull.extractSubset(&srcSubset, skSourceRect); |
326 | 321 |
327 ScopedWriteLockSoftware lock(this, id); | 322 ScopedWriteLockSoftware lock(this, id); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 } | 377 } |
383 | 378 |
384 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 379 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
385 { | 380 { |
386 DCHECK(m_threadChecker.CalledOnValidThread()); | 381 DCHECK(m_threadChecker.CalledOnValidThread()); |
387 ResourceMap::iterator it = m_resources.find(id); | 382 ResourceMap::iterator it = m_resources.find(id); |
388 CHECK(it != m_resources.end()); | 383 CHECK(it != m_resources.end()); |
389 Resource* resource = &it->second; | 384 Resource* resource = &it->second; |
390 DCHECK(!resource->lockedForWrite); | 385 DCHECK(!resource->lockedForWrite); |
391 DCHECK(!resource->exported); | 386 DCHECK(!resource->exported); |
392 DCHECK(resource->allocated); // Uninitialized! Call setPixels or lockForWrit
e first. | |
393 | |
394 resource->lockForReadCount++; | 387 resource->lockForReadCount++; |
395 return resource; | 388 return resource; |
396 } | 389 } |
397 | 390 |
398 void ResourceProvider::unlockForRead(ResourceId id) | 391 void ResourceProvider::unlockForRead(ResourceId id) |
399 { | 392 { |
400 DCHECK(m_threadChecker.CalledOnValidThread()); | 393 DCHECK(m_threadChecker.CalledOnValidThread()); |
401 ResourceMap::iterator it = m_resources.find(id); | 394 ResourceMap::iterator it = m_resources.find(id); |
402 CHECK(it != m_resources.end()); | 395 CHECK(it != m_resources.end()); |
403 Resource* resource = &it->second; | 396 Resource* resource = &it->second; |
404 DCHECK(resource->lockForReadCount > 0); | 397 DCHECK(resource->lockForReadCount > 0); |
405 DCHECK(!resource->exported); | 398 DCHECK(!resource->exported); |
406 resource->lockForReadCount--; | 399 resource->lockForReadCount--; |
407 } | 400 } |
408 | 401 |
409 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) | 402 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
410 { | 403 { |
411 DCHECK(m_threadChecker.CalledOnValidThread()); | 404 DCHECK(m_threadChecker.CalledOnValidThread()); |
412 ResourceMap::iterator it = m_resources.find(id); | 405 ResourceMap::iterator it = m_resources.find(id); |
413 CHECK(it != m_resources.end()); | 406 CHECK(it != m_resources.end()); |
414 Resource* resource = &it->second; | 407 Resource* resource = &it->second; |
415 DCHECK(!resource->lockedForWrite); | 408 DCHECK(!resource->lockedForWrite); |
416 DCHECK(!resource->lockForReadCount); | 409 DCHECK(!resource->lockForReadCount); |
417 DCHECK(!resource->exported); | 410 DCHECK(!resource->exported); |
418 DCHECK(!resource->external); | 411 DCHECK(!resource->external); |
419 lazyAllocate(resource); | |
420 | |
421 resource->lockedForWrite = true; | 412 resource->lockedForWrite = true; |
422 return resource; | 413 return resource; |
423 } | 414 } |
424 | 415 |
425 void ResourceProvider::unlockForWrite(ResourceId id) | 416 void ResourceProvider::unlockForWrite(ResourceId id) |
426 { | 417 { |
427 DCHECK(m_threadChecker.CalledOnValidThread()); | 418 DCHECK(m_threadChecker.CalledOnValidThread()); |
428 ResourceMap::iterator it = m_resources.find(id); | 419 ResourceMap::iterator it = m_resources.find(id); |
429 CHECK(it != m_resources.end()); | 420 CHECK(it != m_resources.end()); |
430 Resource* resource = &it->second; | 421 Resource* resource = &it->second; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 } | 638 } |
648 Child& childInfo = m_children.find(child)->second; | 639 Child& childInfo = m_children.find(child)->second; |
649 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 640 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
650 unsigned textureId; | 641 unsigned textureId; |
651 GLC(context3d, textureId = context3d->createTexture()); | 642 GLC(context3d, textureId = context3d->createTexture()); |
652 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 643 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
653 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 644 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
654 ResourceId id = m_nextId++; | 645 ResourceId id = m_nextId++; |
655 Resource resource(textureId, it->size, it->format, it->filter); | 646 Resource resource(textureId, it->size, it->format, it->filter); |
656 resource.mailbox.setName(it->mailbox.name); | 647 resource.mailbox.setName(it->mailbox.name); |
657 // Don't allocate a texture for a child. | |
658 resource.allocated = true; | |
659 m_resources[id] = resource; | 648 m_resources[id] = resource; |
660 childInfo.parentToChildMap[id] = it->id; | 649 childInfo.parentToChildMap[id] = it->id; |
661 childInfo.childToParentMap[it->id] = id; | 650 childInfo.childToParentMap[it->id] = id; |
662 } | 651 } |
663 } | 652 } |
664 | 653 |
665 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 654 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
666 { | 655 { |
667 DCHECK(m_threadChecker.CalledOnValidThread()); | 656 DCHECK(m_threadChecker.CalledOnValidThread()); |
668 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 657 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
(...skipping 20 matching lines...) Expand all Loading... |
689 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 678 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
690 { | 679 { |
691 DCHECK(m_threadChecker.CalledOnValidThread()); | 680 DCHECK(m_threadChecker.CalledOnValidThread()); |
692 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 681 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
693 ResourceMap::iterator it = m_resources.find(id); | 682 ResourceMap::iterator it = m_resources.find(id); |
694 CHECK(it != m_resources.end()); | 683 CHECK(it != m_resources.end()); |
695 Resource* source = &it->second; | 684 Resource* source = &it->second; |
696 DCHECK(!source->lockedForWrite); | 685 DCHECK(!source->lockedForWrite); |
697 DCHECK(!source->lockForReadCount); | 686 DCHECK(!source->lockForReadCount); |
698 DCHECK(!source->external); | 687 DCHECK(!source->external); |
699 DCHECK(source->allocated); | |
700 if (source->exported) | 688 if (source->exported) |
701 return false; | 689 return false; |
702 resource->id = id; | 690 resource->id = id; |
703 resource->format = source->format; | 691 resource->format = source->format; |
704 resource->filter = source->filter; | 692 resource->filter = source->filter; |
705 resource->size = source->size; | 693 resource->size = source->size; |
706 | 694 |
707 if (source->mailbox.isZero()) { | 695 if (source->mailbox.isZero()) { |
708 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; | 696 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; |
709 GLC(context3d, context3d->genMailboxCHROMIUM(name)); | 697 GLC(context3d, context3d->genMailboxCHROMIUM(name)); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 void ResourceProvider::setPixelsFromBuffer(ResourceId id) | 825 void ResourceProvider::setPixelsFromBuffer(ResourceId id) |
838 { | 826 { |
839 DCHECK(m_threadChecker.CalledOnValidThread()); | 827 DCHECK(m_threadChecker.CalledOnValidThread()); |
840 ResourceMap::iterator it = m_resources.find(id); | 828 ResourceMap::iterator it = m_resources.find(id); |
841 CHECK(it != m_resources.end()); | 829 CHECK(it != m_resources.end()); |
842 Resource* resource = &it->second; | 830 Resource* resource = &it->second; |
843 DCHECK(!resource->lockedForWrite); | 831 DCHECK(!resource->lockedForWrite); |
844 DCHECK(!resource->lockForReadCount); | 832 DCHECK(!resource->lockForReadCount); |
845 DCHECK(!resource->external); | 833 DCHECK(!resource->external); |
846 DCHECK(!resource->exported); | 834 DCHECK(!resource->exported); |
847 lazyAllocate(resource); | |
848 | 835 |
849 if (resource->glId) { | 836 if (resource->glId) { |
850 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 837 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
851 DCHECK(context3d); | 838 DCHECK(context3d); |
852 DCHECK(resource->glPixelBufferId); | 839 DCHECK(resource->glPixelBufferId); |
853 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 840 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
854 context3d->bindBuffer( | 841 context3d->bindBuffer( |
855 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 842 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
856 resource->glPixelBufferId); | 843 resource->glPixelBufferId); |
857 context3d->texSubImage2D(GL_TEXTURE_2D, | 844 context3d->texSubImage2D(GL_TEXTURE_2D, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
899 } | 886 } |
900 } | 887 } |
901 | 888 |
902 void ResourceProvider::beginSetPixels(ResourceId id) | 889 void ResourceProvider::beginSetPixels(ResourceId id) |
903 { | 890 { |
904 DCHECK(m_threadChecker.CalledOnValidThread()); | 891 DCHECK(m_threadChecker.CalledOnValidThread()); |
905 ResourceMap::iterator it = m_resources.find(id); | 892 ResourceMap::iterator it = m_resources.find(id); |
906 CHECK(it != m_resources.end()); | 893 CHECK(it != m_resources.end()); |
907 Resource* resource = &it->second; | 894 Resource* resource = &it->second; |
908 DCHECK(!resource->pendingSetPixels); | 895 DCHECK(!resource->pendingSetPixels); |
909 DCHECK(resource->glId || resource->allocated); | |
910 | 896 |
911 bool allocate = !resource->allocated; | |
912 resource->allocated = true; | |
913 lockForWrite(id); | 897 lockForWrite(id); |
914 | 898 |
915 if (resource->glId) { | 899 if (resource->glId) { |
916 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | 900 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); |
917 DCHECK(context3d); | 901 DCHECK(context3d); |
918 DCHECK(resource->glPixelBufferId); | 902 DCHECK(resource->glPixelBufferId); |
919 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); | 903 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); |
920 context3d->bindBuffer( | 904 context3d->bindBuffer( |
921 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 905 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
922 resource->glPixelBufferId); | 906 resource->glPixelBufferId); |
923 if (!resource->glUploadQueryId) | 907 if (!resource->glUploadQueryId) |
924 resource->glUploadQueryId = context3d->createQueryEXT(); | 908 resource->glUploadQueryId = context3d->createQueryEXT(); |
925 context3d->beginQueryEXT( | 909 context3d->beginQueryEXT( |
926 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, | 910 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
927 resource->glUploadQueryId); | 911 resource->glUploadQueryId); |
928 if (allocate) { | 912 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, |
929 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 913 0, /* level */ |
930 0, /* level */ | 914 0, /* x */ |
931 resource->format, | 915 0, /* y */ |
932 resource->size.width(), | 916 resource->size.width(), |
933 resource->size.height(), | 917 resource->size.height(), |
934 0, /* border */ | 918 resource->format, |
935 resource->format, | 919 GL_UNSIGNED_BYTE, |
936 GL_UNSIGNED_BYTE, | 920 NULL); |
937 NULL); | |
938 } else { | |
939 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | |
940 0, /* level */ | |
941 0, /* x */ | |
942 0, /* y */ | |
943 resource->size.width(), | |
944 resource->size.height(), | |
945 resource->format, | |
946 GL_UNSIGNED_BYTE, | |
947 NULL); | |
948 } | |
949 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); | 921 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); |
950 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 922 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
951 } | 923 } |
952 | 924 |
953 if (resource->pixels) | 925 if (resource->pixels) |
954 setPixelsFromBuffer(id); | 926 setPixelsFromBuffer(id); |
955 | 927 |
956 resource->pendingSetPixels = true; | 928 resource->pendingSetPixels = true; |
957 } | 929 } |
958 | 930 |
(...skipping 17 matching lines...) Expand all Loading... |
976 if (!complete) | 948 if (!complete) |
977 return false; | 949 return false; |
978 } | 950 } |
979 | 951 |
980 resource->pendingSetPixels = false; | 952 resource->pendingSetPixels = false; |
981 unlockForWrite(id); | 953 unlockForWrite(id); |
982 | 954 |
983 return true; | 955 return true; |
984 } | 956 } |
985 | 957 |
986 void ResourceProvider::allocateForTesting(ResourceId id) { | |
987 ResourceMap::iterator it = m_resources.find(id); | |
988 CHECK(it != m_resources.end()); | |
989 Resource* resource = &it->second; | |
990 lazyAllocate(resource); | |
991 } | |
992 | |
993 void ResourceProvider::lazyAllocate(Resource* resource) { | |
994 DCHECK(resource); | |
995 DCHECK(resource->glId || resource->allocated); | |
996 | |
997 if (resource->allocated || !resource->glId) | |
998 return; | |
999 | |
1000 resource->allocated = true; | |
1001 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); | |
1002 gfx::Size& size = resource->size; | |
1003 GLenum format = resource->format; | |
1004 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | |
1005 GLenum storageFormat = textureToStorageFormat(format); | |
1006 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | |
1007 } else | |
1008 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | |
1009 } | |
1010 | |
1011 | |
1012 } // namespace cc | 958 } // namespace cc |
OLD | NEW |