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