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

Side by Side Diff: cc/resource_provider.cc

Issue 11369071: A speculative Revert for r165872 - Remove static thread pointers from CC, attempt 2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « cc/resource_provider.h ('k') | cc/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/resource_provider.h" 7 #include "cc/resource_provider.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
11 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
12 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/string_split.h" 14 #include "base/string_split.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "cc/gl_renderer.h" // For the GLC() macro. 16 #include "cc/gl_renderer.h" // For the GLC() macro.
17 #include "cc/proxy.h"
17 #include "cc/texture_uploader.h" 18 #include "cc/texture_uploader.h"
18 #include "cc/transferable_resource.h" 19 #include "cc/transferable_resource.h"
19 #include "third_party/khronos/GLES2/gl2.h" 20 #include "third_party/khronos/GLES2/gl2.h"
20 #include "third_party/khronos/GLES2/gl2ext.h" 21 #include "third_party/khronos/GLES2/gl2ext.h"
21 #include "ui/gfx/rect.h" 22 #include "ui/gfx/rect.h"
22 #include "ui/gfx/vector2d.h" 23 #include "ui/gfx/vector2d.h"
23 24
24 #include <public/WebGraphicsContext3D.h> 25 #include <public/WebGraphicsContext3D.h>
25 26
26 using WebKit::WebGraphicsContext3D; 27 using WebKit::WebGraphicsContext3D;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 { 124 {
124 WebGraphicsContext3D* context3d = m_context->context3D(); 125 WebGraphicsContext3D* context3d = m_context->context3D();
125 if (!context3d || !context3d->makeContextCurrent()) 126 if (!context3d || !context3d->makeContextCurrent())
126 return; 127 return;
127 m_textureUploader.reset(); 128 m_textureUploader.reset();
128 m_textureCopier.reset(); 129 m_textureCopier.reset();
129 } 130 }
130 131
131 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() 132 WebGraphicsContext3D* ResourceProvider::graphicsContext3D()
132 { 133 {
133 DCHECK(m_threadChecker.CalledOnValidThread()); 134 DCHECK(Proxy::isImplThread());
134 return m_context->context3D(); 135 return m_context->context3D();
135 } 136 }
136 137
137 bool ResourceProvider::inUseByConsumer(ResourceId id) 138 bool ResourceProvider::inUseByConsumer(ResourceId id)
138 { 139 {
139 DCHECK(m_threadChecker.CalledOnValidThread()); 140 DCHECK(Proxy::isImplThread());
140 ResourceMap::iterator it = m_resources.find(id); 141 ResourceMap::iterator it = m_resources.find(id);
141 CHECK(it != m_resources.end()); 142 CHECK(it != m_resources.end());
142 Resource* resource = &it->second; 143 Resource* resource = &it->second;
143 return !!resource->lockForReadCount || resource->exported; 144 return !!resource->lockForReadCount || resource->exported;
144 } 145 }
145 146
146 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf x::Size& size, GLenum format, TextureUsageHint hint) 147 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf x::Size& size, GLenum format, TextureUsageHint hint)
147 { 148 {
148 switch (m_defaultResourceType) { 149 switch (m_defaultResourceType) {
149 case GLTexture: 150 case GLTexture:
150 return createGLTexture(pool, size, format, hint); 151 return createGLTexture(pool, size, format, hint);
151 case Bitmap: 152 case Bitmap:
152 DCHECK(format == GL_RGBA); 153 DCHECK(format == GL_RGBA);
153 return createBitmap(pool, size); 154 return createBitmap(pool, size);
154 } 155 }
155 156
156 CRASH(); 157 CRASH();
157 return 0; 158 return 0;
158 } 159 }
159 160
160 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g fx::Size& size, GLenum format, TextureUsageHint hint) 161 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g fx::Size& size, GLenum format, TextureUsageHint hint)
161 { 162 {
162 DCHECK(m_threadChecker.CalledOnValidThread()); 163 DCHECK(Proxy::isImplThread());
163 unsigned textureId = 0; 164 unsigned textureId = 0;
164 WebGraphicsContext3D* context3d = m_context->context3D(); 165 WebGraphicsContext3D* context3d = m_context->context3D();
165 DCHECK(context3d); 166 DCHECK(context3d);
166 GLC(context3d, textureId = context3d->createTexture()); 167 GLC(context3d, textureId = context3d->createTexture());
167 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); 168 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId));
168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR)); 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER , GL_LINEAR));
169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR)); 170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER , GL_LINEAR));
170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE)); 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL _CLAMP_TO_EDGE));
171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE)); 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL _CLAMP_TO_EDGE));
172 173
173 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer)
174 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_ ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE));
175 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) {
176 GLenum storageFormat = textureToStorageFormat(format); 177 GLenum storageFormat = textureToStorageFormat(format);
177 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height())); 178 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma t, size.width(), size.height()));
178 } else 179 } else
179 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); 180 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0));
180 ResourceId id = m_nextId++; 181 ResourceId id = m_nextId++;
181 Resource resource(textureId, pool, size, format); 182 Resource resource(textureId, pool, size, format);
182 m_resources[id] = resource; 183 m_resources[id] = resource;
183 return id; 184 return id;
184 } 185 }
185 186
186 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size) 187 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx: :Size& size)
187 { 188 {
188 DCHECK(m_threadChecker.CalledOnValidThread()); 189 DCHECK(Proxy::isImplThread());
189 190
190 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; 191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4];
191 192
192 ResourceId id = m_nextId++; 193 ResourceId id = m_nextId++;
193 Resource resource(pixels, pool, size, GL_RGBA); 194 Resource resource(pixels, pool, size, GL_RGBA);
194 m_resources[id] = resource; 195 m_resources[id] = resource;
195 return id; 196 return id;
196 } 197 }
197 198
198 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId) 199 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture (unsigned textureId)
199 { 200 {
200 DCHECK(m_threadChecker.CalledOnValidThread()); 201 DCHECK(Proxy::isImplThread());
201 DCHECK(m_context->context3D()); 202 DCHECK(m_context->context3D());
202 ResourceId id = m_nextId++; 203 ResourceId id = m_nextId++;
203 Resource resource(textureId, 0, gfx::Size(), 0); 204 Resource resource(textureId, 0, gfx::Size(), 0);
204 resource.external = true; 205 resource.external = true;
205 m_resources[id] = resource; 206 m_resources[id] = resource;
206 return id; 207 return id;
207 } 208 }
208 209
209 void ResourceProvider::deleteResource(ResourceId id) 210 void ResourceProvider::deleteResource(ResourceId id)
210 { 211 {
211 DCHECK(m_threadChecker.CalledOnValidThread()); 212 DCHECK(Proxy::isImplThread());
212 ResourceMap::iterator it = m_resources.find(id); 213 ResourceMap::iterator it = m_resources.find(id);
213 CHECK(it != m_resources.end()); 214 CHECK(it != m_resources.end());
214 Resource* resource = &it->second; 215 Resource* resource = &it->second;
215 DCHECK(!resource->lockedForWrite); 216 DCHECK(!resource->lockedForWrite);
216 DCHECK(!resource->lockForReadCount); 217 DCHECK(!resource->lockForReadCount);
217 DCHECK(!resource->markedForDeletion); 218 DCHECK(!resource->markedForDeletion);
218 219
219 if (resource->exported) { 220 if (resource->exported) {
220 resource->markedForDeletion = true; 221 resource->markedForDeletion = true;
221 return; 222 return;
(...skipping 11 matching lines...) Expand all
233 } 234 }
234 if (resource->pixels) 235 if (resource->pixels)
235 delete[] resource->pixels; 236 delete[] resource->pixels;
236 237
237 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] = (*it).first | g_debugZone; 238 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] = (*it).first | g_debugZone;
238 m_resources.erase(it); 239 m_resources.erase(it);
239 } 240 }
240 241
241 void ResourceProvider::deleteOwnedResources(int pool) 242 void ResourceProvider::deleteOwnedResources(int pool)
242 { 243 {
243 DCHECK(m_threadChecker.CalledOnValidThread()); 244 DCHECK(Proxy::isImplThread());
244 ResourceIdArray toDelete; 245 ResourceIdArray toDelete;
245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end() ; ++it) { 246 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end() ; ++it) {
246 if (it->second.pool == pool && !it->second.external && !it->second.marke dForDeletion) 247 if (it->second.pool == pool && !it->second.external && !it->second.marke dForDeletion)
247 toDelete.push_back(it->first); 248 toDelete.push_back(it->first);
248 } 249 }
249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it) 250 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end(); ++it)
250 deleteResource(*it); 251 deleteResource(*it);
251 } 252 }
252 253
253 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) 254 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id)
254 { 255 {
255 ResourceMap::iterator it = m_resources.find(id); 256 ResourceMap::iterator it = m_resources.find(id);
256 CHECK(it != m_resources.end()); 257 CHECK(it != m_resources.end());
257 Resource* resource = &it->second; 258 Resource* resource = &it->second;
258 return resource->type; 259 return resource->type;
259 } 260 }
260 261
261 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) 262 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx: :Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset)
262 { 263 {
263 DCHECK(m_threadChecker.CalledOnValidThread()); 264 DCHECK(Proxy::isImplThread());
264 ResourceMap::iterator it = m_resources.find(id); 265 ResourceMap::iterator it = m_resources.find(id);
265 CHECK(it != m_resources.end()); 266 CHECK(it != m_resources.end());
266 Resource* resource = &it->second; 267 Resource* resource = &it->second;
267 DCHECK(!resource->lockedForWrite); 268 DCHECK(!resource->lockedForWrite);
268 DCHECK(!resource->lockForReadCount); 269 DCHECK(!resource->lockForReadCount);
269 DCHECK(!resource->external); 270 DCHECK(!resource->external);
270 DCHECK(!resource->exported); 271 DCHECK(!resource->exported);
271 272
272 if (resource->glId) { 273 if (resource->glId) {
273 WebGraphicsContext3D* context3d = m_context->context3D(); 274 WebGraphicsContext3D* context3d = m_context->context3D();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 void ResourceProvider::flushUploads() 325 void ResourceProvider::flushUploads()
325 { 326 {
326 if (!m_textureUploader) 327 if (!m_textureUploader)
327 return; 328 return;
328 329
329 m_textureUploader->flush(); 330 m_textureUploader->flush();
330 } 331 }
331 332
332 void ResourceProvider::flush() 333 void ResourceProvider::flush()
333 { 334 {
334 DCHECK(m_threadChecker.CalledOnValidThread()); 335 DCHECK(Proxy::isImplThread());
335 WebGraphicsContext3D* context3d = m_context->context3D(); 336 WebGraphicsContext3D* context3d = m_context->context3D();
336 if (context3d) 337 if (context3d)
337 context3d->flush(); 338 context3d->flush();
338 } 339 }
339 340
340 bool ResourceProvider::shallowFlushIfSupported() 341 bool ResourceProvider::shallowFlushIfSupported()
341 { 342 {
342 DCHECK(m_threadChecker.CalledOnValidThread()); 343 DCHECK(Proxy::isImplThread());
343 WebGraphicsContext3D* context3d = m_context->context3D(); 344 WebGraphicsContext3D* context3d = m_context->context3D();
344 if (!context3d || !m_useShallowFlush) 345 if (!context3d || !m_useShallowFlush)
345 return false; 346 return false;
346 347
347 context3d->shallowFlushCHROMIUM(); 348 context3d->shallowFlushCHROMIUM();
348 return true; 349 return true;
349 } 350 }
350 351
351 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) 352 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id)
352 { 353 {
353 DCHECK(m_threadChecker.CalledOnValidThread()); 354 DCHECK(Proxy::isImplThread());
354 ResourceMap::iterator it = m_resources.find(id); 355 ResourceMap::iterator it = m_resources.find(id);
355 356
356 if (it == m_resources.end()) { 357 if (it == m_resources.end()) {
357 int resourceCount = m_resources.size(); 358 int resourceCount = m_resources.size();
358 int64 resDestroyedCount = g_debugResDestroyedCount; 359 int64 resDestroyedCount = g_debugResDestroyedCount;
359 ResourceId resDestroyed[g_debugMaxResourcesTracked]; 360 ResourceId resDestroyed[g_debugMaxResourcesTracked];
360 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) 361 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i)
361 resDestroyed[i] = g_debugResDestroyed[i]; 362 resDestroyed[i] = g_debugResDestroyed[i];
362 ResourceId resToDestroy = id; 363 ResourceId resToDestroy = id;
363 364
364 base::debug::Alias(&resourceCount); 365 base::debug::Alias(&resourceCount);
365 base::debug::Alias(&resDestroyedCount); 366 base::debug::Alias(&resDestroyedCount);
366 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) 367 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i)
367 base::debug::Alias(&resDestroyed[i]); 368 base::debug::Alias(&resDestroyed[i]);
368 base::debug::Alias(&resToDestroy); 369 base::debug::Alias(&resToDestroy);
369 CHECK(it != m_resources.end()); 370 CHECK(it != m_resources.end());
370 } 371 }
371 372
372 Resource* resource = &it->second; 373 Resource* resource = &it->second;
373 DCHECK(!resource->lockedForWrite); 374 DCHECK(!resource->lockedForWrite);
374 DCHECK(!resource->exported); 375 DCHECK(!resource->exported);
375 resource->lockForReadCount++; 376 resource->lockForReadCount++;
376 return resource; 377 return resource;
377 } 378 }
378 379
379 void ResourceProvider::unlockForRead(ResourceId id) 380 void ResourceProvider::unlockForRead(ResourceId id)
380 { 381 {
381 DCHECK(m_threadChecker.CalledOnValidThread()); 382 DCHECK(Proxy::isImplThread());
382 ResourceMap::iterator it = m_resources.find(id); 383 ResourceMap::iterator it = m_resources.find(id);
383 CHECK(it != m_resources.end()); 384 CHECK(it != m_resources.end());
384 Resource* resource = &it->second; 385 Resource* resource = &it->second;
385 DCHECK(resource->lockForReadCount > 0); 386 DCHECK(resource->lockForReadCount > 0);
386 DCHECK(!resource->exported); 387 DCHECK(!resource->exported);
387 resource->lockForReadCount--; 388 resource->lockForReadCount--;
388 } 389 }
389 390
390 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) 391 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id)
391 { 392 {
392 DCHECK(m_threadChecker.CalledOnValidThread()); 393 DCHECK(Proxy::isImplThread());
393 ResourceMap::iterator it = m_resources.find(id); 394 ResourceMap::iterator it = m_resources.find(id);
394 CHECK(it != m_resources.end()); 395 CHECK(it != m_resources.end());
395 Resource* resource = &it->second; 396 Resource* resource = &it->second;
396 DCHECK(!resource->lockedForWrite); 397 DCHECK(!resource->lockedForWrite);
397 DCHECK(!resource->lockForReadCount); 398 DCHECK(!resource->lockForReadCount);
398 DCHECK(!resource->exported); 399 DCHECK(!resource->exported);
399 DCHECK(!resource->external); 400 DCHECK(!resource->external);
400 resource->lockedForWrite = true; 401 resource->lockedForWrite = true;
401 return resource; 402 return resource;
402 } 403 }
403 404
404 void ResourceProvider::unlockForWrite(ResourceId id) 405 void ResourceProvider::unlockForWrite(ResourceId id)
405 { 406 {
406 DCHECK(m_threadChecker.CalledOnValidThread()); 407 DCHECK(Proxy::isImplThread());
407 ResourceMap::iterator it = m_resources.find(id); 408 ResourceMap::iterator it = m_resources.find(id);
408 CHECK(it != m_resources.end()); 409 CHECK(it != m_resources.end());
409 Resource* resource = &it->second; 410 Resource* resource = &it->second;
410 DCHECK(resource->lockedForWrite); 411 DCHECK(resource->lockedForWrite);
411 DCHECK(!resource->exported); 412 DCHECK(!resource->exported);
412 DCHECK(!resource->external); 413 DCHECK(!resource->external);
413 resource->lockedForWrite = false; 414 resource->lockedForWrite = false;
414 } 415 }
415 416
416 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP rovider, ResourceProvider::ResourceId resourceId) 417 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP rovider, ResourceProvider::ResourceId resourceId)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 , m_defaultResourceType(GLTexture) 480 , m_defaultResourceType(GLTexture)
480 , m_useTextureStorageExt(false) 481 , m_useTextureStorageExt(false)
481 , m_useTextureUsageHint(false) 482 , m_useTextureUsageHint(false)
482 , m_useShallowFlush(false) 483 , m_useShallowFlush(false)
483 , m_maxTextureSize(0) 484 , m_maxTextureSize(0)
484 { 485 {
485 } 486 }
486 487
487 bool ResourceProvider::initialize() 488 bool ResourceProvider::initialize()
488 { 489 {
489 DCHECK(m_threadChecker.CalledOnValidThread()); 490 DCHECK(Proxy::isImplThread());
490 WebGraphicsContext3D* context3d = m_context->context3D(); 491 WebGraphicsContext3D* context3d = m_context->context3D();
491 if (!context3d) { 492 if (!context3d) {
492 m_maxTextureSize = INT_MAX / 2; 493 m_maxTextureSize = INT_MAX / 2;
493 return true; 494 return true;
494 } 495 }
495 if (!context3d->makeContextCurrent()) 496 if (!context3d->makeContextCurrent())
496 return false; 497 return false;
497 498
498 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO NS)); 499 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO NS));
499 std::vector<std::string> extensions; 500 std::vector<std::string> extensions;
(...skipping 15 matching lines...) Expand all
515 516
516 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform ); 517 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform );
517 518
518 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall owFlush); 519 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall owFlush);
519 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize )); 520 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize ));
520 return true; 521 return true;
521 } 522 }
522 523
523 int ResourceProvider::createChild(int pool) 524 int ResourceProvider::createChild(int pool)
524 { 525 {
525 DCHECK(m_threadChecker.CalledOnValidThread()); 526 DCHECK(Proxy::isImplThread());
526 Child childInfo; 527 Child childInfo;
527 childInfo.pool = pool; 528 childInfo.pool = pool;
528 int child = m_nextChild++; 529 int child = m_nextChild++;
529 m_children[child] = childInfo; 530 m_children[child] = childInfo;
530 return child; 531 return child;
531 } 532 }
532 533
533 void ResourceProvider::destroyChild(int child) 534 void ResourceProvider::destroyChild(int child)
534 { 535 {
535 DCHECK(m_threadChecker.CalledOnValidThread()); 536 DCHECK(Proxy::isImplThread());
536 ChildMap::iterator it = m_children.find(child); 537 ChildMap::iterator it = m_children.find(child);
537 DCHECK(it != m_children.end()); 538 DCHECK(it != m_children.end());
538 deleteOwnedResources(it->second.pool); 539 deleteOwnedResources(it->second.pool);
539 m_children.erase(it); 540 m_children.erase(it);
540 trimMailboxDeque(); 541 trimMailboxDeque();
541 } 542 }
542 543
543 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const 544 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int child) const
544 { 545 {
545 DCHECK(m_threadChecker.CalledOnValidThread()); 546 DCHECK(Proxy::isImplThread());
546 ChildMap::const_iterator it = m_children.find(child); 547 ChildMap::const_iterator it = m_children.find(child);
547 DCHECK(it != m_children.end()); 548 DCHECK(it != m_children.end());
548 return it->second.childToParentMap; 549 return it->second.childToParentMap;
549 } 550 }
550 551
551 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceList* list) 552 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra nsferableResourceList* list)
552 { 553 {
553 DCHECK(m_threadChecker.CalledOnValidThread()); 554 DCHECK(Proxy::isImplThread());
554 list->sync_point = 0; 555 list->sync_point = 0;
555 list->resources.clear(); 556 list->resources.clear();
556 WebGraphicsContext3D* context3d = m_context->context3D(); 557 WebGraphicsContext3D* context3d = m_context->context3D();
557 if (!context3d || !context3d->makeContextCurrent()) { 558 if (!context3d || !context3d->makeContextCurrent()) {
558 // FIXME: Implement this path for software compositing. 559 // FIXME: Implement this path for software compositing.
559 return; 560 return;
560 } 561 }
561 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 562 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
562 TransferableResource resource; 563 TransferableResource resource;
563 if (transferResource(context3d, *it, &resource)) { 564 if (transferResource(context3d, *it, &resource)) {
564 m_resources.find(*it)->second.exported = true; 565 m_resources.find(*it)->second.exported = true;
565 list->resources.push_back(resource); 566 list->resources.push_back(resource);
566 } 567 }
567 } 568 }
568 if (list->resources.size()) 569 if (list->resources.size())
569 list->sync_point = context3d->insertSyncPoint(); 570 list->sync_point = context3d->insertSyncPoint();
570 } 571 }
571 572
572 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceList* list) 573 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso urces, TransferableResourceList* list)
573 { 574 {
574 DCHECK(m_threadChecker.CalledOnValidThread()); 575 DCHECK(Proxy::isImplThread());
575 list->sync_point = 0; 576 list->sync_point = 0;
576 list->resources.clear(); 577 list->resources.clear();
577 WebGraphicsContext3D* context3d = m_context->context3D(); 578 WebGraphicsContext3D* context3d = m_context->context3D();
578 if (!context3d || !context3d->makeContextCurrent()) { 579 if (!context3d || !context3d->makeContextCurrent()) {
579 // FIXME: Implement this path for software compositing. 580 // FIXME: Implement this path for software compositing.
580 return; 581 return;
581 } 582 }
582 Child& childInfo = m_children.find(child)->second; 583 Child& childInfo = m_children.find(child)->second;
583 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) { 584 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources .end(); ++it) {
584 TransferableResource resource; 585 TransferableResource resource;
585 if (!transferResource(context3d, *it, &resource)) 586 if (!transferResource(context3d, *it, &resource))
586 NOTREACHED(); 587 NOTREACHED();
587 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end()); 588 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa p.end());
588 resource.id = childInfo.parentToChildMap[*it]; 589 resource.id = childInfo.parentToChildMap[*it];
589 childInfo.parentToChildMap.erase(*it); 590 childInfo.parentToChildMap.erase(*it);
590 childInfo.childToParentMap.erase(resource.id); 591 childInfo.childToParentMap.erase(resource.id);
591 list->resources.push_back(resource); 592 list->resources.push_back(resource);
592 deleteResource(*it); 593 deleteResource(*it);
593 } 594 }
594 if (list->resources.size()) 595 if (list->resources.size())
595 list->sync_point = context3d->insertSyncPoint(); 596 list->sync_point = context3d->insertSyncPoint();
596 } 597 }
597 598
598 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis t& resources) 599 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis t& resources)
599 { 600 {
600 DCHECK(m_threadChecker.CalledOnValidThread()); 601 DCHECK(Proxy::isImplThread());
601 WebGraphicsContext3D* context3d = m_context->context3D(); 602 WebGraphicsContext3D* context3d = m_context->context3D();
602 if (!context3d || !context3d->makeContextCurrent()) { 603 if (!context3d || !context3d->makeContextCurrent()) {
603 // FIXME: Implement this path for software compositing. 604 // FIXME: Implement this path for software compositing.
604 return; 605 return;
605 } 606 }
606 if (resources.sync_point) { 607 if (resources.sync_point) {
607 // NOTE: If the parent is a browser and the child a renderer, the parent 608 // NOTE: If the parent is a browser and the child a renderer, the parent
608 // is not supposed to have its context wait, because that could induce 609 // is not supposed to have its context wait, because that could induce
609 // deadlocks and/or security issues. The caller is responsible for 610 // deadlocks and/or security issues. The caller is responsible for
610 // waiting asynchronously, and resetting sync_point before calling this. 611 // waiting asynchronously, and resetting sync_point before calling this.
(...skipping 11 matching lines...) Expand all
622 Resource resource(textureId, childInfo.pool, it->size, it->format); 623 Resource resource(textureId, childInfo.pool, it->size, it->format);
623 m_resources[id] = resource; 624 m_resources[id] = resource;
624 m_mailboxes.push_back(it->mailbox); 625 m_mailboxes.push_back(it->mailbox);
625 childInfo.parentToChildMap[id] = it->id; 626 childInfo.parentToChildMap[id] = it->id;
626 childInfo.childToParentMap[it->id] = id; 627 childInfo.childToParentMap[it->id] = id;
627 } 628 }
628 } 629 }
629 630
630 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es) 631 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc es)
631 { 632 {
632 DCHECK(m_threadChecker.CalledOnValidThread()); 633 DCHECK(Proxy::isImplThread());
633 WebGraphicsContext3D* context3d = m_context->context3D(); 634 WebGraphicsContext3D* context3d = m_context->context3D();
634 if (!context3d || !context3d->makeContextCurrent()) { 635 if (!context3d || !context3d->makeContextCurrent()) {
635 // FIXME: Implement this path for software compositing. 636 // FIXME: Implement this path for software compositing.
636 return; 637 return;
637 } 638 }
638 if (resources.sync_point) 639 if (resources.sync_point)
639 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); 640 GLC(context3d, context3d->waitSyncPoint(resources.sync_point));
640 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) { 641 for (TransferableResourceArray::const_iterator it = resources.resources.begi n(); it != resources.resources.end(); ++it) {
641 ResourceMap::iterator mapIterator = m_resources.find(it->id); 642 ResourceMap::iterator mapIterator = m_resources.find(it->id);
642 DCHECK(mapIterator != m_resources.end()); 643 DCHECK(mapIterator != m_resources.end());
643 Resource* resource = &mapIterator->second; 644 Resource* resource = &mapIterator->second;
644 DCHECK(resource->exported); 645 DCHECK(resource->exported);
645 resource->exported = false; 646 resource->exported = false;
646 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); 647 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId));
647 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name)); 648 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail box.name));
648 m_mailboxes.push_back(it->mailbox); 649 m_mailboxes.push_back(it->mailbox);
649 if (resource->markedForDeletion) 650 if (resource->markedForDeletion)
650 deleteResourceInternal(mapIterator); 651 deleteResourceInternal(mapIterator);
651 } 652 }
652 } 653 }
653 654
654 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource) 655 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI d id, TransferableResource* resource)
655 { 656 {
656 DCHECK(m_threadChecker.CalledOnValidThread()); 657 DCHECK(Proxy::isImplThread());
657 ResourceMap::const_iterator it = m_resources.find(id); 658 ResourceMap::const_iterator it = m_resources.find(id);
658 CHECK(it != m_resources.end()); 659 CHECK(it != m_resources.end());
659 const Resource* source = &it->second; 660 const Resource* source = &it->second;
660 DCHECK(!source->lockedForWrite); 661 DCHECK(!source->lockedForWrite);
661 DCHECK(!source->lockForReadCount); 662 DCHECK(!source->lockForReadCount);
662 DCHECK(!source->external); 663 DCHECK(!source->external);
663 if (source->exported) 664 if (source->exported)
664 return false; 665 return false;
665 resource->id = id; 666 resource->id = id;
666 resource->format = source->format; 667 resource->format = source->format;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 g_debugZone = zone; 708 g_debugZone = zone;
708 } 709 }
709 710
710 void ResourceProvider::debugNotifyLeaveZone() 711 void ResourceProvider::debugNotifyLeaveZone()
711 { 712 {
712 g_debugZone = 0; 713 g_debugZone = 0;
713 } 714 }
714 715
715 716
716 } 717 }
OLDNEW
« no previous file with comments | « cc/resource_provider.h ('k') | cc/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698