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

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: Track uninitialized textures. Fix 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return createGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, h int); 169 return createGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, h int);
167 case Bitmap: 170 case Bitmap:
168 DCHECK(format == GL_RGBA); 171 DCHECK(format == GL_RGBA);
169 return createBitmap(size); 172 return createBitmap(size);
170 } 173 }
171 174
172 LOG(FATAL) << "Invalid default resource type."; 175 LOG(FATAL) << "Invalid default resource type.";
173 return 0; 176 return 0;
174 } 177 }
175 178
179 ResourceProvider::ResourceId ResourceProvider::createAllocatedResource(const gfx ::Size& size, GLenum format, TextureUsageHint hint)
180 {
181 ResourceProvider::ResourceId id = createResource(size, format, hint);
182 if (id)
183 lazyAllocate(id);
184 return id;
185 }
186
187 ResourceProvider::ResourceId ResourceProvider::createAllocatedManagedResource(co nst gfx::Size& size, GLenum format, TextureUsageHint hint)
188 {
189 ResourceProvider::ResourceId id = createManagedResource(size, format, hint);
190 if (id)
191 lazyAllocate(id);
192 return id;
193 }
194
195
176 ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size& size, GLenum format, GLenum texturePool, TextureUsageHint hint) 196 ResourceProvider::ResourceId ResourceProvider::createGLTexture(const gfx::Size& size, GLenum format, GLenum texturePool, TextureUsageHint hint)
177 { 197 {
178 DCHECK_LE(size.width(), m_maxTextureSize); 198 DCHECK_LE(size.width(), m_maxTextureSize);
179 DCHECK_LE(size.height(), m_maxTextureSize); 199 DCHECK_LE(size.height(), m_maxTextureSize);
180 200
181 DCHECK(m_threadChecker.CalledOnValidThread()); 201 DCHECK(m_threadChecker.CalledOnValidThread());
182 unsigned textureId = 0; 202 unsigned textureId = 0;
183 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 203 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
184 DCHECK(context3d); 204 DCHECK(context3d);
185 GLC(context3d, textureId = context3d->createTexture()); 205 GLC(context3d, textureId = context3d->createTexture());
186 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 206 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
207
208 // Set texture properties. Allocation is delayed until needed.
187 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 209 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)); 210 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)); 211 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)); 212 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)); 213 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROM IUM, texturePool));
192
193 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 214 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
194 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 215 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 216
201 ResourceId id = m_nextId++; 217 ResourceId id = m_nextId++;
202 Resource resource(textureId, size, format, GL_LINEAR); 218 Resource resource(textureId, size, format, GL_LINEAR);
219 resource.allocated = false;
203 m_resources[id] = resource; 220 m_resources[id] = resource;
204 return id; 221 return id;
205 } 222 }
206 223
207 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e) 224 ResourceProvider::ResourceId ResourceProvider::createBitmap(const gfx::Size& siz e)
208 { 225 {
209 DCHECK(m_threadChecker.CalledOnValidThread()); 226 DCHECK(m_threadChecker.CalledOnValidThread());
210 227
211 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 228 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
212 229
213 ResourceId id = m_nextId++; 230 ResourceId id = m_nextId++;
214 Resource resource(pixels, size, GL_RGBA, GL_LINEAR); 231 Resource resource(pixels, size, GL_RGBA, GL_LINEAR);
232 resource.allocated = true;
215 m_resources[id] = resource; 233 m_resources[id] = resource;
216 return id; 234 return id;
217 } 235 }
218 236
219 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 237 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
220 { 238 {
221 DCHECK(m_threadChecker.CalledOnValidThread()); 239 DCHECK(m_threadChecker.CalledOnValidThread());
222 240
223 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 241 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
224 DCHECK(context3d); 242 DCHECK(context3d);
225 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 243 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
226 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 244 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)); 245 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)); 246 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)); 247 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
230 248
231 ResourceId id = m_nextId++; 249 ResourceId id = m_nextId++;
232 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR); 250 Resource resource(textureId, gfx::Size(), 0, GL_LINEAR);
233 resource.external = true; 251 resource.external = true;
252 resource.allocated = true;
234 m_resources[id] = resource; 253 m_resources[id] = resource;
235 return id; 254 return id;
236 } 255 }
237 256
238 void ResourceProvider::deleteResource(ResourceId id) 257 void ResourceProvider::deleteResource(ResourceId id)
239 { 258 {
240 DCHECK(m_threadChecker.CalledOnValidThread()); 259 DCHECK(m_threadChecker.CalledOnValidThread());
241 ResourceMap::iterator it = m_resources.find(id); 260 ResourceMap::iterator it = m_resources.find(id);
242 CHECK(it != m_resources.end()); 261 CHECK(it != m_resources.end());
243 Resource* resource = &it->second; 262 Resource* resource = &it->second;
244 DCHECK(!resource->lockedForWrite);
245 DCHECK(!resource->lockForReadCount); 263 DCHECK(!resource->lockForReadCount);
246 DCHECK(!resource->markedForDeletion); 264 DCHECK(!resource->markedForDeletion);
265 DCHECK(resource->pendingSetPixels || !resource->lockedForWrite);
247 266
248 if (resource->exported) { 267 if (resource->exported) {
249 resource->markedForDeletion = true; 268 resource->markedForDeletion = true;
250 return; 269 return;
251 } else 270 } else
252 deleteResourceInternal(it); 271 deleteResourceInternal(it);
253 } 272 }
254 273
255 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) 274 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it)
256 { 275 {
(...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) 308 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset)
290 { 309 {
291 DCHECK(m_threadChecker.CalledOnValidThread()); 310 DCHECK(m_threadChecker.CalledOnValidThread());
292 ResourceMap::iterator it = m_resources.find(id); 311 ResourceMap::iterator it = m_resources.find(id);
293 CHECK(it != m_resources.end()); 312 CHECK(it != m_resources.end());
294 Resource* resource = &it->second; 313 Resource* resource = &it->second;
295 DCHECK(!resource->lockedForWrite); 314 DCHECK(!resource->lockedForWrite);
296 DCHECK(!resource->lockForReadCount); 315 DCHECK(!resource->lockForReadCount);
297 DCHECK(!resource->external); 316 DCHECK(!resource->external);
298 DCHECK(!resource->exported); 317 DCHECK(!resource->exported);
318 lazyAllocate(resource);
299 319
300 if (resource->glId) { 320 if (resource->glId) {
321 DCHECK(!resource->pendingSetPixels);
301 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 322 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
302 DCHECK(context3d); 323 DCHECK(context3d);
303 DCHECK(m_textureUploader.get()); 324 DCHECK(m_textureUploader.get());
304 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 325 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
305 m_textureUploader->upload(image, 326 m_textureUploader->upload(image,
306 imageRect, 327 imageRect,
307 sourceRect, 328 sourceRect,
308 destOffset, 329 destOffset,
309 resource->format, 330 resource->format,
310 resource->size); 331 resource->size);
311 } 332 }
312 333
313 if (resource->pixels) { 334 if (resource->pixels) {
335 DCHECK(resource->allocated);
314 DCHECK(resource->format == GL_RGBA); 336 DCHECK(resource->format == GL_RGBA);
315 SkBitmap srcFull; 337 SkBitmap srcFull;
316 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height()); 338 srcFull.setConfig(SkBitmap::kARGB_8888_Config, imageRect.width(), imageR ect.height());
317 srcFull.setPixels(const_cast<uint8_t*>(image)); 339 srcFull.setPixels(const_cast<uint8_t*>(image));
318 SkBitmap srcSubset; 340 SkBitmap srcSubset;
319 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height()); 341 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(), sourceRect.width(), sourceRect.height());
320 skSourceRect.offset(-imageRect.x(), -imageRect.y()); 342 skSourceRect.offset(-imageRect.x(), -imageRect.y());
321 srcFull.extractSubset(&srcSubset, skSourceRect); 343 srcFull.extractSubset(&srcSubset, skSourceRect);
322 344
323 ScopedWriteLockSoftware lock(this, id); 345 ScopedWriteLockSoftware lock(this, id);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 400 }
379 401
380 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) 402 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id)
381 { 403 {
382 DCHECK(m_threadChecker.CalledOnValidThread()); 404 DCHECK(m_threadChecker.CalledOnValidThread());
383 ResourceMap::iterator it = m_resources.find(id); 405 ResourceMap::iterator it = m_resources.find(id);
384 CHECK(it != m_resources.end()); 406 CHECK(it != m_resources.end());
385 Resource* resource = &it->second; 407 Resource* resource = &it->second;
386 DCHECK(!resource->lockedForWrite); 408 DCHECK(!resource->lockedForWrite);
387 DCHECK(!resource->exported); 409 DCHECK(!resource->exported);
410 DCHECK(resource->allocated); // Texture uninitialized! setPixels or lockForW rite first.
piman 2012/12/18 22:41:38 nit: 2 spaces before comments
388 resource->lockForReadCount++; 411 resource->lockForReadCount++;
389 return resource; 412 return resource;
390 } 413 }
391 414
392 void ResourceProvider::unlockForRead(ResourceId id) 415 void ResourceProvider::unlockForRead(ResourceId id)
393 { 416 {
394 DCHECK(m_threadChecker.CalledOnValidThread()); 417 DCHECK(m_threadChecker.CalledOnValidThread());
395 ResourceMap::iterator it = m_resources.find(id); 418 ResourceMap::iterator it = m_resources.find(id);
396 CHECK(it != m_resources.end()); 419 CHECK(it != m_resources.end());
397 Resource* resource = &it->second; 420 Resource* resource = &it->second;
398 DCHECK(resource->lockForReadCount > 0); 421 DCHECK(resource->lockForReadCount > 0);
399 DCHECK(!resource->exported); 422 DCHECK(!resource->exported);
400 resource->lockForReadCount--; 423 resource->lockForReadCount--;
401 } 424 }
402 425
403 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) 426 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id)
404 { 427 {
405 DCHECK(m_threadChecker.CalledOnValidThread()); 428 DCHECK(m_threadChecker.CalledOnValidThread());
406 ResourceMap::iterator it = m_resources.find(id); 429 ResourceMap::iterator it = m_resources.find(id);
407 CHECK(it != m_resources.end()); 430 CHECK(it != m_resources.end());
408 Resource* resource = &it->second; 431 Resource* resource = &it->second;
409 DCHECK(!resource->lockedForWrite); 432 DCHECK(!resource->lockedForWrite);
410 DCHECK(!resource->lockForReadCount); 433 DCHECK(!resource->lockForReadCount);
411 DCHECK(!resource->exported); 434 DCHECK(!resource->exported);
412 DCHECK(!resource->external); 435 DCHECK(!resource->external);
436 lazyAllocate(resource);
437
413 resource->lockedForWrite = true; 438 resource->lockedForWrite = true;
414 return resource; 439 return resource;
415 } 440 }
416 441
417 void ResourceProvider::unlockForWrite(ResourceId id) 442 void ResourceProvider::unlockForWrite(ResourceId id)
418 { 443 {
419 DCHECK(m_threadChecker.CalledOnValidThread()); 444 DCHECK(m_threadChecker.CalledOnValidThread());
420 ResourceMap::iterator it = m_resources.find(id); 445 ResourceMap::iterator it = m_resources.find(id);
421 CHECK(it != m_resources.end()); 446 CHECK(it != m_resources.end());
422 Resource* resource = &it->second; 447 Resource* resource = &it->second;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 } 664 }
640 Child& childInfo = m_children.find(child)->second; 665 Child& childInfo = m_children.find(child)->second;
641 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 666 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
642 unsigned textureId; 667 unsigned textureId;
643 GLC(context3d, textureId = context3d->createTexture()); 668 GLC(context3d, textureId = context3d->createTexture());
644 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 669 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
645 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 670 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
646 ResourceId id = m_nextId++; 671 ResourceId id = m_nextId++;
647 Resource resource(textureId, it->size, it->format, it->filter); 672 Resource resource(textureId, it->size, it->format, it->filter);
648 resource.mailbox.setName(it->mailbox.name); 673 resource.mailbox.setName(it->mailbox.name);
674 // Don't allocate a texture for a child.
675 resource.allocated = true;
649 m_resources[id] = resource; 676 m_resources[id] = resource;
650 childInfo.parentToChildMap[id] = it->id; 677 childInfo.parentToChildMap[id] = it->id;
651 childInfo.childToParentMap[it->id] = id; 678 childInfo.childToParentMap[it->id] = id;
652 } 679 }
653 } 680 }
654 681
655 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 682 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
656 { 683 {
657 DCHECK(m_threadChecker.CalledOnValidThread()); 684 DCHECK(m_threadChecker.CalledOnValidThread());
658 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 685 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
(...skipping 20 matching lines...) Expand all
679 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 706 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
680 { 707 {
681 DCHECK(m_threadChecker.CalledOnValidThread()); 708 DCHECK(m_threadChecker.CalledOnValidThread());
682 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 709 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
683 ResourceMap::iterator it = m_resources.find(id); 710 ResourceMap::iterator it = m_resources.find(id);
684 CHECK(it != m_resources.end()); 711 CHECK(it != m_resources.end());
685 Resource* source = &it->second; 712 Resource* source = &it->second;
686 DCHECK(!source->lockedForWrite); 713 DCHECK(!source->lockedForWrite);
687 DCHECK(!source->lockForReadCount); 714 DCHECK(!source->lockForReadCount);
688 DCHECK(!source->external); 715 DCHECK(!source->external);
716 DCHECK(source->allocated);
689 if (source->exported) 717 if (source->exported)
690 return false; 718 return false;
691 resource->id = id; 719 resource->id = id;
692 resource->format = source->format; 720 resource->format = source->format;
693 resource->filter = source->filter; 721 resource->filter = source->filter;
694 resource->size = source->size; 722 resource->size = source->size;
695 723
696 if (source->mailbox.isZero()) { 724 if (source->mailbox.isZero()) {
697 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM]; 725 GLbyte name[GL_MAILBOX_SIZE_CHROMIUM];
698 GLC(context3d, context3d->genMailboxCHROMIUM(name)); 726 GLC(context3d, context3d->genMailboxCHROMIUM(name));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 void ResourceProvider::setPixelsFromBuffer(ResourceId id) 854 void ResourceProvider::setPixelsFromBuffer(ResourceId id)
827 { 855 {
828 DCHECK(m_threadChecker.CalledOnValidThread()); 856 DCHECK(m_threadChecker.CalledOnValidThread());
829 ResourceMap::iterator it = m_resources.find(id); 857 ResourceMap::iterator it = m_resources.find(id);
830 CHECK(it != m_resources.end()); 858 CHECK(it != m_resources.end());
831 Resource* resource = &it->second; 859 Resource* resource = &it->second;
832 DCHECK(!resource->lockedForWrite); 860 DCHECK(!resource->lockedForWrite);
833 DCHECK(!resource->lockForReadCount); 861 DCHECK(!resource->lockForReadCount);
834 DCHECK(!resource->external); 862 DCHECK(!resource->external);
835 DCHECK(!resource->exported); 863 DCHECK(!resource->exported);
864 lazyAllocate(resource);
836 865
837 if (resource->glId) { 866 if (resource->glId) {
838 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 867 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
839 DCHECK(context3d); 868 DCHECK(context3d);
840 DCHECK(resource->glPixelBufferId); 869 DCHECK(resource->glPixelBufferId);
841 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 870 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
842 context3d->bindBuffer( 871 context3d->bindBuffer(
843 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 872 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
844 resource->glPixelBufferId); 873 resource->glPixelBufferId);
845 context3d->texSubImage2D(GL_TEXTURE_2D, 874 context3d->texSubImage2D(GL_TEXTURE_2D,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 } 917 }
889 918
890 void ResourceProvider::beginSetPixels(ResourceId id) 919 void ResourceProvider::beginSetPixels(ResourceId id)
891 { 920 {
892 DCHECK(m_threadChecker.CalledOnValidThread()); 921 DCHECK(m_threadChecker.CalledOnValidThread());
893 ResourceMap::iterator it = m_resources.find(id); 922 ResourceMap::iterator it = m_resources.find(id);
894 CHECK(it != m_resources.end()); 923 CHECK(it != m_resources.end());
895 Resource* resource = &it->second; 924 Resource* resource = &it->second;
896 DCHECK(!resource->pendingSetPixels); 925 DCHECK(!resource->pendingSetPixels);
897 926
927 resource->allocated = true;
898 lockForWrite(id); 928 lockForWrite(id);
899 929
900 if (resource->glId) { 930 if (resource->glId) {
901 WebGraphicsContext3D* context3d = m_outputSurface->Context3D(); 931 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
902 DCHECK(context3d); 932 DCHECK(context3d);
903 DCHECK(resource->glPixelBufferId); 933 DCHECK(resource->glPixelBufferId);
904 context3d->bindTexture(GL_TEXTURE_2D, resource->glId); 934 context3d->bindTexture(GL_TEXTURE_2D, resource->glId);
905 context3d->bindBuffer( 935 context3d->bindBuffer(
906 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 936 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
907 resource->glPixelBufferId); 937 resource->glPixelBufferId);
908 if (!resource->glUploadQueryId) 938 if (!resource->glUploadQueryId)
909 resource->glUploadQueryId = context3d->createQueryEXT(); 939 resource->glUploadQueryId = context3d->createQueryEXT();
910 context3d->beginQueryEXT( 940 context3d->beginQueryEXT(
911 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, 941 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM,
912 resource->glUploadQueryId); 942 resource->glUploadQueryId);
913 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 943 if (!resource->allocated) {
914 0, /* level */ 944 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
915 0, /* x */ 945 0, /* level */
916 0, /* y */ 946 resource->format,
917 resource->size.width(), 947 resource->size.width(),
918 resource->size.height(), 948 resource->size.height(),
919 resource->format, 949 0, /* border */
920 GL_UNSIGNED_BYTE, 950 resource->format,
921 NULL); 951 GL_UNSIGNED_BYTE,
952 NULL);
953 } else {
954 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
955 0, /* level */
956 0, /* x */
957 0, /* y */
958 resource->size.width(),
959 resource->size.height(),
960 resource->format,
961 GL_UNSIGNED_BYTE,
962 NULL);
963 }
922 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); 964 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM);
923 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 965 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
924 } 966 }
925 967
926 if (resource->pixels) 968 if (resource->pixels)
927 setPixelsFromBuffer(id); 969 setPixelsFromBuffer(id);
928 970
929 resource->pendingSetPixels = true; 971 resource->pendingSetPixels = true;
930 } 972 }
931 973
(...skipping 17 matching lines...) Expand all
949 if (!complete) 991 if (!complete)
950 return false; 992 return false;
951 } 993 }
952 994
953 resource->pendingSetPixels = false; 995 resource->pendingSetPixels = false;
954 unlockForWrite(id); 996 unlockForWrite(id);
955 997
956 return true; 998 return true;
957 } 999 }
958 1000
1001 void ResourceProvider::lazyAllocate(ResourceId id) {
1002 ResourceMap::iterator it = m_resources.find(id);
1003 CHECK(it != m_resources.end());
1004 Resource* resource = &it->second;
1005 lazyAllocate(resource);
1006 }
1007
1008 void ResourceProvider::lazyAllocate(Resource* resource) {
1009 DCHECK(resource);
1010 DCHECK(resource->glId || resource->allocated);
1011
1012 if (resource->allocated || !resource->glId)
1013 return;
1014
1015 resource->allocated = true;
1016 WebGraphicsContext3D* context3d = m_outputSurface->Context3D();
1017 gfx::Size& size = resource->size;
1018 GLenum format = resource->format;
1019 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
1020 GLenum storageFormat = textureToStorageFormat(format);
1021 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
1022 } else
1023 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
1024 }
1025
1026
959 } // namespace cc 1027 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698