OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 wrap_mode(0), | 190 wrap_mode(0), |
191 lost(false), | 191 lost(false), |
192 hint(TextureUsageAny), | 192 hint(TextureUsageAny), |
193 type(static_cast<ResourceType>(0)), | 193 type(static_cast<ResourceType>(0)), |
194 format(RGBA_8888), | 194 format(RGBA_8888), |
195 shared_bitmap(NULL) {} | 195 shared_bitmap(NULL) {} |
196 | 196 |
197 ResourceProvider::Resource::~Resource() {} | 197 ResourceProvider::Resource::~Resource() {} |
198 | 198 |
199 ResourceProvider::Resource::Resource(GLuint texture_id, | 199 ResourceProvider::Resource::Resource(GLuint texture_id, |
200 const gfx::Size& size, | 200 gfx::Size size, |
201 GLenum target, | 201 GLenum target, |
202 GLenum filter, | 202 GLenum filter, |
203 GLenum texture_pool, | 203 GLenum texture_pool, |
204 GLint wrap_mode, | 204 GLint wrap_mode, |
205 TextureUsageHint hint, | 205 TextureUsageHint hint, |
206 ResourceFormat format) | 206 ResourceFormat format) |
207 : child_id(0), | 207 : child_id(0), |
208 gl_id(texture_id), | 208 gl_id(texture_id), |
209 gl_pixel_buffer_id(0), | 209 gl_pixel_buffer_id(0), |
210 gl_upload_query_id(0), | 210 gl_upload_query_id(0), |
(...skipping 22 matching lines...) Expand all Loading... |
233 lost(false), | 233 lost(false), |
234 hint(hint), | 234 hint(hint), |
235 type(GLTexture), | 235 type(GLTexture), |
236 format(format), | 236 format(format), |
237 shared_bitmap(NULL) { | 237 shared_bitmap(NULL) { |
238 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 238 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
239 } | 239 } |
240 | 240 |
241 ResourceProvider::Resource::Resource(uint8_t* pixels, | 241 ResourceProvider::Resource::Resource(uint8_t* pixels, |
242 SharedBitmap* bitmap, | 242 SharedBitmap* bitmap, |
243 const gfx::Size& size, | 243 gfx::Size size, |
244 GLenum filter, | 244 GLenum filter, |
245 GLint wrap_mode) | 245 GLint wrap_mode) |
246 : child_id(0), | 246 : child_id(0), |
247 gl_id(0), | 247 gl_id(0), |
248 gl_pixel_buffer_id(0), | 248 gl_pixel_buffer_id(0), |
249 gl_upload_query_id(0), | 249 gl_upload_query_id(0), |
250 pixels(pixels), | 250 pixels(pixels), |
251 pixel_buffer(NULL), | 251 pixel_buffer(NULL), |
252 lock_for_read_count(0), | 252 lock_for_read_count(0), |
253 imported_count(0), | 253 imported_count(0), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 323 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
324 resource->lost; | 324 resource->lost; |
325 } | 325 } |
326 | 326 |
327 bool ResourceProvider::IsLost(ResourceId id) { | 327 bool ResourceProvider::IsLost(ResourceId id) { |
328 Resource* resource = GetResource(id); | 328 Resource* resource = GetResource(id); |
329 return resource->lost; | 329 return resource->lost; |
330 } | 330 } |
331 | 331 |
332 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 332 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
333 const gfx::Size& size, | 333 gfx::Size size, |
334 GLint wrap_mode, | 334 GLint wrap_mode, |
335 TextureUsageHint hint, | 335 TextureUsageHint hint, |
336 ResourceFormat format) { | 336 ResourceFormat format) { |
337 DCHECK(!size.IsEmpty()); | 337 DCHECK(!size.IsEmpty()); |
338 switch (default_resource_type_) { | 338 switch (default_resource_type_) { |
339 case GLTexture: | 339 case GLTexture: |
340 return CreateGLTexture(size, | 340 return CreateGLTexture(size, |
341 GL_TEXTURE_2D, | 341 GL_TEXTURE_2D, |
342 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 342 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
343 wrap_mode, | 343 wrap_mode, |
344 hint, | 344 hint, |
345 format); | 345 format); |
346 case Bitmap: | 346 case Bitmap: |
347 DCHECK_EQ(RGBA_8888, format); | 347 DCHECK_EQ(RGBA_8888, format); |
348 return CreateBitmap(size, wrap_mode); | 348 return CreateBitmap(size, wrap_mode); |
349 case InvalidType: | 349 case InvalidType: |
350 break; | 350 break; |
351 } | 351 } |
352 | 352 |
353 LOG(FATAL) << "Invalid default resource type."; | 353 LOG(FATAL) << "Invalid default resource type."; |
354 return 0; | 354 return 0; |
355 } | 355 } |
356 | 356 |
357 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 357 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
358 const gfx::Size& size, | 358 gfx::Size size, |
359 GLenum target, | 359 GLenum target, |
360 GLint wrap_mode, | 360 GLint wrap_mode, |
361 TextureUsageHint hint, | 361 TextureUsageHint hint, |
362 ResourceFormat format) { | 362 ResourceFormat format) { |
363 DCHECK(!size.IsEmpty()); | 363 DCHECK(!size.IsEmpty()); |
364 switch (default_resource_type_) { | 364 switch (default_resource_type_) { |
365 case GLTexture: | 365 case GLTexture: |
366 return CreateGLTexture(size, | 366 return CreateGLTexture(size, |
367 target, | 367 target, |
368 GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 368 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
369 wrap_mode, | 369 wrap_mode, |
370 hint, | 370 hint, |
371 format); | 371 format); |
372 case Bitmap: | 372 case Bitmap: |
373 DCHECK_EQ(RGBA_8888, format); | 373 DCHECK_EQ(RGBA_8888, format); |
374 return CreateBitmap(size, wrap_mode); | 374 return CreateBitmap(size, wrap_mode); |
375 case InvalidType: | 375 case InvalidType: |
376 break; | 376 break; |
377 } | 377 } |
378 | 378 |
379 LOG(FATAL) << "Invalid default resource type."; | 379 LOG(FATAL) << "Invalid default resource type."; |
380 return 0; | 380 return 0; |
381 } | 381 } |
382 | 382 |
383 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 383 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
384 const gfx::Size& size, | 384 gfx::Size size, |
385 GLenum target, | 385 GLenum target, |
386 GLenum texture_pool, | 386 GLenum texture_pool, |
387 GLint wrap_mode, | 387 GLint wrap_mode, |
388 TextureUsageHint hint, | 388 TextureUsageHint hint, |
389 ResourceFormat format) { | 389 ResourceFormat format) { |
390 DCHECK_LE(size.width(), max_texture_size_); | 390 DCHECK_LE(size.width(), max_texture_size_); |
391 DCHECK_LE(size.height(), max_texture_size_); | 391 DCHECK_LE(size.height(), max_texture_size_); |
392 DCHECK(thread_checker_.CalledOnValidThread()); | 392 DCHECK(thread_checker_.CalledOnValidThread()); |
393 | 393 |
394 ResourceId id = next_id_++; | 394 ResourceId id = next_id_++; |
395 Resource resource( | 395 Resource resource( |
396 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); | 396 0, size, target, GL_LINEAR, texture_pool, wrap_mode, hint, format); |
397 resource.allocated = false; | 397 resource.allocated = false; |
398 resources_[id] = resource; | 398 resources_[id] = resource; |
399 return id; | 399 return id; |
400 } | 400 } |
401 | 401 |
402 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( | 402 ResourceProvider::ResourceId ResourceProvider::CreateBitmap( |
403 const gfx::Size& size, GLint wrap_mode) { | 403 gfx::Size size, GLint wrap_mode) { |
404 DCHECK(thread_checker_.CalledOnValidThread()); | 404 DCHECK(thread_checker_.CalledOnValidThread()); |
405 | 405 |
406 scoped_ptr<SharedBitmap> bitmap; | 406 scoped_ptr<SharedBitmap> bitmap; |
407 if (shared_bitmap_manager_) | 407 if (shared_bitmap_manager_) |
408 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); | 408 bitmap = shared_bitmap_manager_->AllocateSharedBitmap(size); |
409 | 409 |
410 uint8_t* pixels; | 410 uint8_t* pixels; |
411 if (bitmap) | 411 if (bitmap) |
412 pixels = bitmap->pixels(); | 412 pixels = bitmap->pixels(); |
413 else | 413 else |
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1846 gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1847 return active_unit; | 1847 return active_unit; |
1848 } | 1848 } |
1849 | 1849 |
1850 GLES2Interface* ResourceProvider::ContextGL() const { | 1850 GLES2Interface* ResourceProvider::ContextGL() const { |
1851 ContextProvider* context_provider = output_surface_->context_provider(); | 1851 ContextProvider* context_provider = output_surface_->context_provider(); |
1852 return context_provider ? context_provider->ContextGL() : NULL; | 1852 return context_provider ? context_provider->ContextGL() : NULL; |
1853 } | 1853 } |
1854 | 1854 |
1855 } // namespace cc | 1855 } // namespace cc |
OLD | NEW |