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

Side by Side Diff: cc/resources/resource_provider.h

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments Created 7 years, 3 months 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 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_
6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/containers/hash_tables.h" 15 #include "base/containers/hash_tables.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
18 #include "cc/base/cc_export.h" 18 #include "cc/base/cc_export.h"
19 #include "cc/output/context_provider.h" 19 #include "cc/output/context_provider.h"
20 #include "cc/output/output_surface.h" 20 #include "cc/output/output_surface.h"
21 #include "cc/resources/resource_format.h"
21 #include "cc/resources/texture_mailbox.h" 22 #include "cc/resources/texture_mailbox.h"
22 #include "cc/resources/transferable_resource.h" 23 #include "cc/resources/transferable_resource.h"
23 #include "third_party/khronos/GLES2/gl2.h" 24 #include "third_party/khronos/GLES2/gl2.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 26 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "ui/gfx/size.h" 27 #include "ui/gfx/size.h"
27 28
28 namespace WebKit { class WebGraphicsContext3D; } 29 namespace WebKit { class WebGraphicsContext3D; }
29 30
30 namespace gfx { 31 namespace gfx {
(...skipping 16 matching lines...) Expand all
47 TextureUsageAny, 48 TextureUsageAny,
48 TextureUsageFramebuffer, 49 TextureUsageFramebuffer,
49 }; 50 };
50 enum ResourceType { 51 enum ResourceType {
51 InvalidType = 0, 52 InvalidType = 0,
52 GLTexture = 1, 53 GLTexture = 1,
53 Bitmap, 54 Bitmap,
54 }; 55 };
55 56
56 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface, 57 static scoped_ptr<ResourceProvider> Create(OutputSurface* output_surface,
57 int highp_threshold_min); 58 int highp_threshold_min,
58 59 bool use_rgba_4444_tiles,
60 bool force_rgba_tiles);
59 virtual ~ResourceProvider(); 61 virtual ~ResourceProvider();
60 62
61 void InitializeSoftware(); 63 void InitializeSoftware();
62 bool InitializeGL(); 64 bool InitializeGL();
63 65
64 void DidLoseOutputSurface() { lost_output_surface_ = true; } 66 void DidLoseOutputSurface() { lost_output_surface_ = true; }
65 67
66 int max_texture_size() const { return max_texture_size_; } 68 int max_texture_size() const { return max_texture_size_; }
67 GLenum best_texture_format() const { return best_texture_format_; } 69 ResourceFormat best_tile_texture_format() const {
reveman 2013/09/16 15:55:14 Sorry for not thinking about this earlier. The con
kaanb 2013/09/16 18:36:37 Done.
70 return use_rgba_4444_tiles_ ? RGBA_4444 : best_texture_format_;
71 }
72 ResourceFormat best_texture_format() const { return best_texture_format_; }
68 size_t num_resources() const { return resources_.size(); } 73 size_t num_resources() const { return resources_.size(); }
69 74
70 // Checks whether a resource is in use by a consumer. 75 // Checks whether a resource is in use by a consumer.
71 bool InUseByConsumer(ResourceId id); 76 bool InUseByConsumer(ResourceId id);
72 77
73 78
74 // Producer interface. 79 // Producer interface.
75 80
76 ResourceType default_resource_type() const { return default_resource_type_; } 81 ResourceType default_resource_type() const { return default_resource_type_; }
77 ResourceType GetResourceType(ResourceId id); 82 ResourceType GetResourceType(ResourceId id);
78 83
79 // Creates a resource of the default resource type. 84 // Creates a resource of the default resource type.
80 ResourceId CreateResource(gfx::Size size, 85 ResourceId CreateResource(gfx::Size size,
81 GLenum format,
82 GLint wrap_mode, 86 GLint wrap_mode,
83 TextureUsageHint hint); 87 TextureUsageHint hint,
88 ResourceFormat format);
84 89
85 // Creates a resource which is tagged as being managed for GPU memory 90 // Creates a resource which is tagged as being managed for GPU memory
86 // accounting purposes. 91 // accounting purposes.
87 ResourceId CreateManagedResource(gfx::Size size, 92 ResourceId CreateManagedResource(gfx::Size size,
88 GLenum format,
89 GLint wrap_mode, 93 GLint wrap_mode,
90 TextureUsageHint hint); 94 TextureUsageHint hint,
95 ResourceFormat format);
91 96
92 // You can also explicitly create a specific resource type. 97 // You can also explicitly create a specific resource type.
93 ResourceId CreateGLTexture(gfx::Size size, 98 ResourceId CreateGLTexture(gfx::Size size,
94 GLenum format,
95 GLenum texture_pool, 99 GLenum texture_pool,
96 GLint wrap_mode, 100 GLint wrap_mode,
97 TextureUsageHint hint); 101 TextureUsageHint hint,
102 ResourceFormat format);
98 103
99 ResourceId CreateBitmap(gfx::Size size); 104 ResourceId CreateBitmap(gfx::Size size);
100 // Wraps an external texture into a GL resource. 105 // Wraps an external texture into a GL resource.
101 ResourceId CreateResourceFromExternalTexture( 106 ResourceId CreateResourceFromExternalTexture(
102 unsigned texture_target, 107 unsigned texture_target,
103 unsigned texture_id); 108 unsigned texture_id);
104 109
105 // Wraps an external texture mailbox into a GL resource. 110 // Wraps an external texture mailbox into a GL resource.
106 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox); 111 ResourceId CreateResourceFromTextureMailbox(const TextureMailbox& mailbox);
107 112
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 328 }
324 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } 329 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); }
325 330
326 // Enable read lock fences for a specific resource. 331 // Enable read lock fences for a specific resource.
327 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); 332 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable);
328 333
329 // Indicates if we can currently lock this resource for write. 334 // Indicates if we can currently lock this resource for write.
330 bool CanLockForWrite(ResourceId id); 335 bool CanLockForWrite(ResourceId id);
331 336
332 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context); 337 static GLint GetActiveTextureUnit(WebKit::WebGraphicsContext3D* context);
338 static size_t BytesPerPixel(ResourceFormat format);
339 static GLenum GetGLDataType(ResourceFormat format);
340 static GLenum GetGLDataFormat(ResourceFormat format);
341 static GLenum GetGLInternalFormat(ResourceFormat format);
333 342
334 private: 343 private:
335 struct Resource { 344 struct Resource {
336 Resource(); 345 Resource();
337 ~Resource(); 346 ~Resource();
338 Resource(unsigned texture_id, 347 Resource(unsigned texture_id,
339 gfx::Size size, 348 gfx::Size size,
340 GLenum format,
341 GLenum filter, 349 GLenum filter,
342 GLenum texture_pool, 350 GLenum texture_pool,
343 GLint wrap_mode, 351 GLint wrap_mode,
344 TextureUsageHint hint); 352 TextureUsageHint hint,
353 ResourceFormat format);
345 Resource(uint8_t* pixels, 354 Resource(uint8_t* pixels,
346 gfx::Size size, 355 gfx::Size size,
347 GLenum format,
348 GLenum filter, 356 GLenum filter,
349 GLint wrap_mode); 357 GLint wrap_mode);
350 358
351 unsigned gl_id; 359 unsigned gl_id;
352 // Pixel buffer used for set pixels without unnecessary copying. 360 // Pixel buffer used for set pixels without unnecessary copying.
353 unsigned gl_pixel_buffer_id; 361 unsigned gl_pixel_buffer_id;
354 // Query used to determine when asynchronous set pixels complete. 362 // Query used to determine when asynchronous set pixels complete.
355 unsigned gl_upload_query_id; 363 unsigned gl_upload_query_id;
356 TextureMailbox mailbox; 364 TextureMailbox mailbox;
357 uint8_t* pixels; 365 uint8_t* pixels;
358 uint8_t* pixel_buffer; 366 uint8_t* pixel_buffer;
359 int lock_for_read_count; 367 int lock_for_read_count;
360 int imported_count; 368 int imported_count;
361 int exported_count; 369 int exported_count;
362 bool locked_for_write; 370 bool locked_for_write;
363 bool external; 371 bool external;
364 bool marked_for_deletion; 372 bool marked_for_deletion;
365 bool pending_set_pixels; 373 bool pending_set_pixels;
366 bool set_pixels_completion_forced; 374 bool set_pixels_completion_forced;
367 bool allocated; 375 bool allocated;
368 bool enable_read_lock_fences; 376 bool enable_read_lock_fences;
369 scoped_refptr<Fence> read_lock_fence; 377 scoped_refptr<Fence> read_lock_fence;
370 gfx::Size size; 378 gfx::Size size;
371 GLenum format;
372 // TODO(skyostil): Use a separate sampler object for filter state. 379 // TODO(skyostil): Use a separate sampler object for filter state.
373 GLenum filter; 380 GLenum filter;
374 unsigned image_id; 381 unsigned image_id;
375 GLenum texture_pool; 382 GLenum texture_pool;
376 GLint wrap_mode; 383 GLint wrap_mode;
377 TextureUsageHint hint; 384 TextureUsageHint hint;
378 ResourceType type; 385 ResourceType type;
386 ResourceFormat format;
379 }; 387 };
380 typedef base::hash_map<ResourceId, Resource> ResourceMap; 388 typedef base::hash_map<ResourceId, Resource> ResourceMap;
381 struct Child { 389 struct Child {
382 Child(); 390 Child();
383 ~Child(); 391 ~Child();
384 392
385 ResourceIdMap child_to_parent_map; 393 ResourceIdMap child_to_parent_map;
386 ResourceIdMap parent_to_child_map; 394 ResourceIdMap parent_to_child_map;
387 }; 395 };
388 typedef base::hash_map<int, Child> ChildMap; 396 typedef base::hash_map<int, Child> ChildMap;
389 397
390 bool ReadLockFenceHasPassed(Resource* resource) { 398 bool ReadLockFenceHasPassed(Resource* resource) {
391 return !resource->read_lock_fence.get() || 399 return !resource->read_lock_fence.get() ||
392 resource->read_lock_fence->HasPassed(); 400 resource->read_lock_fence->HasPassed();
393 } 401 }
394 402
395 explicit ResourceProvider(OutputSurface* output_surface, 403 ResourceProvider(OutputSurface* output_surface,
396 int highp_threshold_min); 404 int highp_threshold_min,
405 bool use_rgba_4444_tiles,
406 bool force_rgba_tiles);
397 407
398 void CleanUpGLIfNeeded(); 408 void CleanUpGLIfNeeded();
399 409
400 Resource* GetResource(ResourceId id); 410 Resource* GetResource(ResourceId id);
401 const Resource* LockForRead(ResourceId id); 411 const Resource* LockForRead(ResourceId id);
402 void UnlockForRead(ResourceId id); 412 void UnlockForRead(ResourceId id);
403 const Resource* LockForWrite(ResourceId id); 413 const Resource* LockForWrite(ResourceId id);
404 void UnlockForWrite(ResourceId id); 414 void UnlockForWrite(ResourceId id);
405 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, 415 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
406 const Resource* resource); 416 const Resource* resource);
(...skipping 30 matching lines...) Expand all
437 ResourceMap resources_; 447 ResourceMap resources_;
438 int next_child_; 448 int next_child_;
439 ChildMap children_; 449 ChildMap children_;
440 450
441 ResourceType default_resource_type_; 451 ResourceType default_resource_type_;
442 bool use_texture_storage_ext_; 452 bool use_texture_storage_ext_;
443 bool use_texture_usage_hint_; 453 bool use_texture_usage_hint_;
444 bool use_shallow_flush_; 454 bool use_shallow_flush_;
445 scoped_ptr<TextureUploader> texture_uploader_; 455 scoped_ptr<TextureUploader> texture_uploader_;
446 int max_texture_size_; 456 int max_texture_size_;
447 GLenum best_texture_format_; 457 ResourceFormat best_texture_format_;
448 458
449 base::ThreadChecker thread_checker_; 459 base::ThreadChecker thread_checker_;
450 460
451 scoped_refptr<Fence> current_read_lock_fence_; 461 scoped_refptr<Fence> current_read_lock_fence_;
462 bool use_rgba_4444_tiles_;
reveman 2013/09/16 15:55:14 nit: use_rgba_4444_texture_format
kaanb 2013/09/16 18:36:37 Done.
463 bool force_rgba_tiles_;
reveman 2013/09/16 15:55:14 Not clear to me exactly why we need |force_rgba_ti
kaanb 2013/09/16 18:36:37 Pixel tests use the InProcess context and ContextP
452 464
453 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 465 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
454 }; 466 };
455 467
456 } // namespace cc 468 } // namespace cc
457 469
458 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 470 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698