Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: cc/resource_provider.cc

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

Powered by Google App Engine
This is Rietveld 408576698