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

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

Issue 1535833002: Delete CC. (Closed) Base URL: git@github.com:domokit/mojo.git@moz-5
Patch Set: rebase Created 4 years, 11 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
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_
6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_
7
8 #include <deque>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "base/basictypes.h"
15 #include "base/callback.h"
16 #include "base/containers/hash_tables.h"
17 #include "base/memory/linked_ptr.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/threading/thread_checker.h"
20 #include "cc/output/context_provider.h"
21 #include "cc/output/output_surface.h"
22 #include "cc/resources/release_callback_impl.h"
23 #include "cc/resources/resource_format.h"
24 #include "cc/resources/return_callback.h"
25 #include "cc/resources/shared_bitmap.h"
26 #include "cc/resources/single_release_callback_impl.h"
27 #include "cc/resources/texture_mailbox.h"
28 #include "cc/resources/transferable_resource.h"
29 #include "third_party/khronos/GLES2/gl2.h"
30 #include "third_party/khronos/GLES2/gl2ext.h"
31 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "third_party/skia/include/core/SkCanvas.h"
33 #include "ui/gfx/geometry/size.h"
34
35 class GrContext;
36
37 namespace gpu {
38 class GpuMemoryBufferManager;
39 namespace gles {
40 class GLES2Interface;
41 }
42 }
43
44 namespace gfx {
45 class GpuMemoryBuffer;
46 class Rect;
47 class Vector2d;
48 }
49
50 namespace cc {
51 class BlockingTaskRunner;
52 class IdAllocator;
53 class SharedBitmap;
54 class SharedBitmapManager;
55 class TextureUploader;
56
57 // This class is not thread-safe and can only be called from the thread it was
58 // created on (in practice, the impl thread).
59 class ResourceProvider {
60 private:
61 struct Resource;
62
63 public:
64 typedef unsigned ResourceId;
65 typedef std::vector<ResourceId> ResourceIdArray;
66 typedef std::set<ResourceId> ResourceIdSet;
67 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap;
68 enum TextureHint {
69 TEXTURE_HINT_DEFAULT = 0x0,
70 TEXTURE_HINT_IMMUTABLE = 0x1,
71 TEXTURE_HINT_FRAMEBUFFER = 0x2,
72 TEXTURE_HINT_IMMUTABLE_FRAMEBUFFER =
73 TEXTURE_HINT_IMMUTABLE | TEXTURE_HINT_FRAMEBUFFER
74 };
75 enum ResourceType {
76 RESOURCE_TYPE_INVALID = 0,
77 RESOURCE_TYPE_GL_TEXTURE = 1,
78 RESOURCE_TYPE_BITMAP,
79 };
80
81 static scoped_ptr<ResourceProvider> Create(
82 OutputSurface* output_surface,
83 SharedBitmapManager* shared_bitmap_manager,
84 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
85 BlockingTaskRunner* blocking_main_thread_task_runner,
86 int highp_threshold_min,
87 bool use_rgba_4444_texture_format,
88 size_t id_allocation_chunk_size);
89 virtual ~ResourceProvider();
90
91 void InitializeSoftware();
92 void InitializeGL();
93
94 void DidLoseOutputSurface() { lost_output_surface_ = true; }
95
96 int max_texture_size() const { return max_texture_size_; }
97 ResourceFormat memory_efficient_texture_format() const {
98 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_;
99 }
100 ResourceFormat best_texture_format() const { return best_texture_format_; }
101 ResourceFormat yuv_resource_format() const { return yuv_resource_format_; }
102 bool use_sync_query() const { return use_sync_query_; }
103 size_t num_resources() const { return resources_.size(); }
104
105 // Checks whether a resource is in use by a consumer.
106 bool InUseByConsumer(ResourceId id);
107
108 bool IsLost(ResourceId id);
109 bool AllowOverlay(ResourceId id);
110
111 // Producer interface.
112
113 ResourceType default_resource_type() const { return default_resource_type_; }
114 ResourceType GetResourceType(ResourceId id);
115
116 // Creates a resource of the default resource type.
117 ResourceId CreateResource(const gfx::Size& size,
118 GLint wrap_mode,
119 TextureHint hint,
120 ResourceFormat format);
121
122 // Creates a resource which is tagged as being managed for GPU memory
123 // accounting purposes.
124 ResourceId CreateManagedResource(const gfx::Size& size,
125 GLenum target,
126 GLint wrap_mode,
127 TextureHint hint,
128 ResourceFormat format);
129
130 // You can also explicitly create a specific resource type.
131 ResourceId CreateGLTexture(const gfx::Size& size,
132 GLenum target,
133 GLenum texture_pool,
134 GLint wrap_mode,
135 TextureHint hint,
136 ResourceFormat format);
137
138 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode);
139 // Wraps an IOSurface into a GL resource.
140 ResourceId CreateResourceFromIOSurface(const gfx::Size& size,
141 unsigned io_surface_id);
142
143 // Wraps an external texture mailbox into a GL resource.
144 ResourceId CreateResourceFromTextureMailbox(
145 const TextureMailbox& mailbox,
146 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl);
147
148 void DeleteResource(ResourceId id);
149
150 // Update pixels from image, copying source_rect (in image) to dest_offset (in
151 // the resource).
152 // NOTE: DEPRECATED. Use CopyToResource() instead.
153 void SetPixels(ResourceId id,
154 const uint8_t* image,
155 const gfx::Rect& image_rect,
156 const gfx::Rect& source_rect,
157 const gfx::Vector2d& dest_offset);
158 void CopyToResource(ResourceId id,
159 const uint8_t* image,
160 const gfx::Size& image_size);
161
162 // Check upload status.
163 size_t NumBlockingUploads();
164 void MarkPendingUploadsAsNonBlocking();
165 size_t EstimatedUploadsPerTick();
166 void FlushUploads();
167 void ReleaseCachedData();
168 base::TimeTicks EstimatedUploadCompletionTime(size_t uploads_per_tick);
169
170 // Only flush the command buffer if supported.
171 // Returns true if the shallow flush occurred, false otherwise.
172 bool ShallowFlushIfSupported();
173
174 // Creates accounting for a child. Returns a child ID.
175 int CreateChild(const ReturnCallback& return_callback);
176
177 // Destroys accounting for the child, deleting all accounted resources.
178 void DestroyChild(int child);
179
180 // Gets the child->parent resource ID map.
181 const ResourceIdMap& GetChildToParentMap(int child) const;
182
183 // Prepares resources to be transfered to the parent, moving them to
184 // mailboxes and serializing meta-data into TransferableResources.
185 // Resources are not removed from the ResourceProvider, but are marked as
186 // "in use".
187 void PrepareSendToParent(const ResourceIdArray& resources,
188 TransferableResourceArray* transferable_resources);
189
190 // Receives resources from a child, moving them from mailboxes. Resource IDs
191 // passed are in the child namespace, and will be translated to the parent
192 // namespace, added to the child->parent map.
193 // This adds the resources to the working set in the ResourceProvider without
194 // declaring which resources are in use. Use DeclareUsedResourcesFromChild
195 // after calling this method to do that. All calls to ReceiveFromChild should
196 // be followed by a DeclareUsedResourcesFromChild.
197 // NOTE: if the sync_point is set on any TransferableResource, this will
198 // wait on it.
199 void ReceiveFromChild(
200 int child, const TransferableResourceArray& transferable_resources);
201
202 // Once a set of resources have been received, they may or may not be used.
203 // This declares what set of resources are currently in use from the child,
204 // releasing any other resources back to the child.
205 void DeclareUsedResourcesFromChild(
206 int child,
207 const ResourceIdArray& resources_from_child);
208
209 // Receives resources from the parent, moving them from mailboxes. Resource
210 // IDs passed are in the child namespace.
211 // NOTE: if the sync_point is set on any TransferableResource, this will
212 // wait on it.
213 void ReceiveReturnsFromParent(
214 const ReturnedResourceArray& transferable_resources);
215
216 // The following lock classes are part of the ResourceProvider API and are
217 // needed to read and write the resource contents. The user must ensure
218 // that they only use GL locks on GL resources, etc, and this is enforced
219 // by assertions.
220 class ScopedReadLockGL {
221 public:
222 ScopedReadLockGL(ResourceProvider* resource_provider,
223 ResourceProvider::ResourceId resource_id);
224 virtual ~ScopedReadLockGL();
225
226 unsigned texture_id() const { return texture_id_; }
227
228 protected:
229 ResourceProvider* resource_provider_;
230 ResourceProvider::ResourceId resource_id_;
231
232 private:
233 unsigned texture_id_;
234
235 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
236 };
237
238 class ScopedSamplerGL : public ScopedReadLockGL {
239 public:
240 ScopedSamplerGL(ResourceProvider* resource_provider,
241 ResourceProvider::ResourceId resource_id,
242 GLenum filter);
243 ScopedSamplerGL(ResourceProvider* resource_provider,
244 ResourceProvider::ResourceId resource_id,
245 GLenum unit,
246 GLenum filter);
247 ~ScopedSamplerGL() override;
248
249 GLenum target() const { return target_; }
250
251 private:
252 GLenum unit_;
253 GLenum target_;
254
255 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
256 };
257
258 class ScopedWriteLockGL {
259 public:
260 ScopedWriteLockGL(ResourceProvider* resource_provider,
261 ResourceProvider::ResourceId resource_id);
262 ~ScopedWriteLockGL();
263
264 unsigned texture_id() const { return texture_id_; }
265
266 private:
267 ResourceProvider* resource_provider_;
268 ResourceProvider::Resource* resource_;
269 unsigned texture_id_;
270
271 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
272 };
273
274 class ScopedReadLockSoftware {
275 public:
276 ScopedReadLockSoftware(ResourceProvider* resource_provider,
277 ResourceProvider::ResourceId resource_id);
278 ~ScopedReadLockSoftware();
279
280 const SkBitmap* sk_bitmap() const {
281 DCHECK(valid());
282 return &sk_bitmap_;
283 }
284 GLint wrap_mode() const { return wrap_mode_; }
285
286 bool valid() const { return !!sk_bitmap_.getPixels(); }
287
288 private:
289 ResourceProvider* resource_provider_;
290 ResourceProvider::ResourceId resource_id_;
291 SkBitmap sk_bitmap_;
292 GLint wrap_mode_;
293
294 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockSoftware);
295 };
296
297 class ScopedWriteLockSoftware {
298 public:
299 ScopedWriteLockSoftware(ResourceProvider* resource_provider,
300 ResourceProvider::ResourceId resource_id);
301 ~ScopedWriteLockSoftware();
302
303 SkBitmap& sk_bitmap() { return sk_bitmap_; }
304 bool valid() const { return !!sk_bitmap_.getPixels(); }
305
306 private:
307 ResourceProvider* resource_provider_;
308 ResourceProvider::Resource* resource_;
309 SkBitmap sk_bitmap_;
310 base::ThreadChecker thread_checker_;
311
312 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
313 };
314
315 class ScopedWriteLockGpuMemoryBuffer {
316 public:
317 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider,
318 ResourceProvider::ResourceId resource_id);
319 ~ScopedWriteLockGpuMemoryBuffer();
320
321 gfx::GpuMemoryBuffer* GetGpuMemoryBuffer();
322
323 private:
324 ResourceProvider* resource_provider_;
325 ResourceProvider::Resource* resource_;
326 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
327 gfx::GpuMemoryBuffer* gpu_memory_buffer_;
328 gfx::Size size_;
329 ResourceFormat format_;
330 base::ThreadChecker thread_checker_;
331
332 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer);
333 };
334
335 class ScopedWriteLockGr {
336 public:
337 ScopedWriteLockGr(ResourceProvider* resource_provider,
338 ResourceProvider::ResourceId resource_id);
339 ~ScopedWriteLockGr();
340
341 void InitSkSurface(bool use_worker_context,
342 bool use_distance_field_text,
343 bool can_use_lcd_text,
344 int msaa_sample_count);
345 void ReleaseSkSurface();
346
347 SkSurface* sk_surface() { return sk_surface_.get(); }
348 ResourceProvider::Resource* resource() { return resource_; }
349
350 private:
351 ResourceProvider* resource_provider_;
352 ResourceProvider::Resource* resource_;
353 base::ThreadChecker thread_checker_;
354 skia::RefPtr<SkSurface> sk_surface_;
355
356 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr);
357 };
358
359 class Fence : public base::RefCounted<Fence> {
360 public:
361 Fence() {}
362
363 virtual void Set() = 0;
364 virtual bool HasPassed() = 0;
365 virtual void Wait() = 0;
366
367 protected:
368 friend class base::RefCounted<Fence>;
369 virtual ~Fence() {}
370
371 private:
372 DISALLOW_COPY_AND_ASSIGN(Fence);
373 };
374
375 class SynchronousFence : public ResourceProvider::Fence {
376 public:
377 explicit SynchronousFence(gpu::gles2::GLES2Interface* gl);
378
379 // Overridden from Fence:
380 void Set() override;
381 bool HasPassed() override;
382 void Wait() override;
383
384 // Returns true if fence has been set but not yet synchornized.
385 bool has_synchronized() const { return has_synchronized_; }
386
387 private:
388 ~SynchronousFence() override;
389
390 void Synchronize();
391
392 gpu::gles2::GLES2Interface* gl_;
393 bool has_synchronized_;
394
395 DISALLOW_COPY_AND_ASSIGN(SynchronousFence);
396 };
397
398 // Acquire pixel buffer for resource. The pixel buffer can be used to
399 // set resource pixels without performing unnecessary copying.
400 void AcquirePixelBuffer(ResourceId resource);
401 void ReleasePixelBuffer(ResourceId resource);
402 // Map/unmap the acquired pixel buffer.
403 uint8_t* MapPixelBuffer(ResourceId id, int* stride);
404 void UnmapPixelBuffer(ResourceId id);
405 // Asynchronously update pixels from acquired pixel buffer.
406 void BeginSetPixels(ResourceId id);
407 void ForceSetPixelsToComplete(ResourceId id);
408 bool DidSetPixelsComplete(ResourceId id);
409
410 // For tests only! This prevents detecting uninitialized reads.
411 // Use SetPixels or LockForWrite to allocate implicitly.
412 void AllocateForTesting(ResourceId id);
413
414 // For tests only!
415 void CreateForTesting(ResourceId id);
416
417 GLenum TargetForTesting(ResourceId id);
418
419 // Sets the current read fence. If a resource is locked for read
420 // and has read fences enabled, the resource will not allow writes
421 // until this fence has passed.
422 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; }
423
424 // Indicates if we can currently lock this resource for write.
425 bool CanLockForWrite(ResourceId id);
426
427 // Copy pixels from source to destination.
428 void CopyResource(ResourceId source_id, ResourceId dest_id);
429
430 void WaitSyncPointIfNeeded(ResourceId id);
431
432 void WaitReadLockIfNeeded(ResourceId id);
433
434 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl);
435
436 OutputSurface* output_surface() { return output_surface_; }
437
438 private:
439 struct Resource {
440 enum Origin { INTERNAL, EXTERNAL, DELEGATED };
441
442 Resource();
443 ~Resource();
444 Resource(unsigned texture_id,
445 const gfx::Size& size,
446 Origin origin,
447 GLenum target,
448 GLenum filter,
449 GLenum texture_pool,
450 GLint wrap_mode,
451 TextureHint hint,
452 ResourceFormat format);
453 Resource(uint8_t* pixels,
454 SharedBitmap* bitmap,
455 const gfx::Size& size,
456 Origin origin,
457 GLenum filter,
458 GLint wrap_mode);
459 Resource(const SharedBitmapId& bitmap_id,
460 const gfx::Size& size,
461 Origin origin,
462 GLenum filter,
463 GLint wrap_mode);
464
465 int child_id;
466 unsigned gl_id;
467 // Pixel buffer used for set pixels without unnecessary copying.
468 unsigned gl_pixel_buffer_id;
469 // Query used to determine when asynchronous set pixels complete.
470 unsigned gl_upload_query_id;
471 // Query used to determine when read lock fence has passed.
472 unsigned gl_read_lock_query_id;
473 TextureMailbox mailbox;
474 ReleaseCallbackImpl release_callback_impl;
475 uint8_t* pixels;
476 int lock_for_read_count;
477 int imported_count;
478 int exported_count;
479 bool dirty_image : 1;
480 bool locked_for_write : 1;
481 bool lost : 1;
482 bool marked_for_deletion : 1;
483 bool pending_set_pixels : 1;
484 bool set_pixels_completion_forced : 1;
485 bool allocated : 1;
486 bool read_lock_fences_enabled : 1;
487 bool has_shared_bitmap_id : 1;
488 bool allow_overlay : 1;
489 scoped_refptr<Fence> read_lock_fence;
490 gfx::Size size;
491 Origin origin;
492 GLenum target;
493 // TODO(skyostil): Use a separate sampler object for filter state.
494 GLenum original_filter;
495 GLenum filter;
496 unsigned image_id;
497 unsigned bound_image_id;
498 GLenum texture_pool;
499 GLint wrap_mode;
500 TextureHint hint;
501 ResourceType type;
502 ResourceFormat format;
503 SharedBitmapId shared_bitmap_id;
504 SharedBitmap* shared_bitmap;
505 gfx::GpuMemoryBuffer* gpu_memory_buffer;
506 };
507 typedef base::hash_map<ResourceId, Resource> ResourceMap;
508
509 static bool CompareResourceMapIteratorsByChildId(
510 const std::pair<ReturnedResource, ResourceMap::iterator>& a,
511 const std::pair<ReturnedResource, ResourceMap::iterator>& b);
512
513 struct Child {
514 Child();
515 ~Child();
516
517 ResourceIdMap child_to_parent_map;
518 ResourceIdMap parent_to_child_map;
519 ReturnCallback return_callback;
520 ResourceIdSet in_use_resources;
521 bool marked_for_deletion;
522 };
523 typedef base::hash_map<int, Child> ChildMap;
524
525 bool ReadLockFenceHasPassed(const Resource* resource) {
526 return !resource->read_lock_fence.get() ||
527 resource->read_lock_fence->HasPassed();
528 }
529
530 ResourceProvider(OutputSurface* output_surface,
531 SharedBitmapManager* shared_bitmap_manager,
532 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
533 BlockingTaskRunner* blocking_main_thread_task_runner,
534 int highp_threshold_min,
535 bool use_rgba_4444_texture_format,
536 size_t id_allocation_chunk_size);
537
538 void CleanUpGLIfNeeded();
539
540 Resource* GetResource(ResourceId id);
541 const Resource* LockForRead(ResourceId id);
542 void UnlockForRead(ResourceId id);
543 Resource* LockForWrite(ResourceId id);
544 void UnlockForWrite(Resource* resource);
545
546 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
547 const Resource* resource);
548
549 void TransferResource(gpu::gles2::GLES2Interface* gl,
550 ResourceId id,
551 TransferableResource* resource);
552 enum DeleteStyle {
553 NORMAL,
554 FOR_SHUTDOWN,
555 };
556 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
557 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
558 DeleteStyle style,
559 const ResourceIdArray& unused);
560 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
561 void LazyCreate(Resource* resource);
562 void LazyAllocate(Resource* resource);
563
564 void BindImageForSampling(Resource* resource);
565 // Binds the given GL resource to a texture target for sampling using the
566 // specified filter for both minification and magnification. Returns the
567 // texture target used. The resource must be locked for reading.
568 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter);
569
570 // Returns NULL if the output_surface_ does not have a ContextProvider.
571 gpu::gles2::GLES2Interface* ContextGL() const;
572 class GrContext* GrContext(bool worker_context) const;
573
574 OutputSurface* output_surface_;
575 SharedBitmapManager* shared_bitmap_manager_;
576 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager_;
577 BlockingTaskRunner* blocking_main_thread_task_runner_;
578 bool lost_output_surface_;
579 int highp_threshold_min_;
580 ResourceId next_id_;
581 ResourceMap resources_;
582 int next_child_;
583 ChildMap children_;
584
585 ResourceType default_resource_type_;
586 bool use_texture_storage_ext_;
587 bool use_texture_format_bgra_;
588 bool use_texture_usage_hint_;
589 bool use_compressed_texture_etc1_;
590 ResourceFormat yuv_resource_format_;
591 scoped_ptr<TextureUploader> texture_uploader_;
592 int max_texture_size_;
593 ResourceFormat best_texture_format_;
594
595 base::ThreadChecker thread_checker_;
596
597 scoped_refptr<Fence> current_read_lock_fence_;
598 bool use_rgba_4444_texture_format_;
599
600 const size_t id_allocation_chunk_size_;
601 scoped_ptr<IdAllocator> texture_id_allocator_;
602 scoped_ptr<IdAllocator> buffer_id_allocator_;
603
604 bool use_sync_query_;
605 // Fence used for CopyResource if CHROMIUM_sync_query is not supported.
606 scoped_refptr<SynchronousFence> synchronous_fence_;
607
608 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
609 };
610
611 // TODO(epenner): Move these format conversions to resource_format.h
612 // once that builds on mac (npapi.h currently #includes OpenGL.h).
613 inline unsigned BitsPerPixel(ResourceFormat format) {
614 switch (format) {
615 case BGRA_8888:
616 case RGBA_8888:
617 return 32;
618 case RGBA_4444:
619 case RGB_565:
620 return 16;
621 case ALPHA_8:
622 case LUMINANCE_8:
623 case RED_8:
624 return 8;
625 case ETC1:
626 return 4;
627 }
628 NOTREACHED();
629 return 0;
630 }
631
632 inline GLenum GLDataType(ResourceFormat format) {
633 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
634 static const unsigned format_gl_data_type[RESOURCE_FORMAT_MAX + 1] = {
635 GL_UNSIGNED_BYTE, // RGBA_8888
636 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
637 GL_UNSIGNED_BYTE, // BGRA_8888
638 GL_UNSIGNED_BYTE, // ALPHA_8
639 GL_UNSIGNED_BYTE, // LUMINANCE_8
640 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
641 GL_UNSIGNED_BYTE, // ETC1
642 GL_UNSIGNED_BYTE // RED_8
643 };
644 return format_gl_data_type[format];
645 }
646
647 inline GLenum GLDataFormat(ResourceFormat format) {
648 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
649 static const unsigned format_gl_data_format[RESOURCE_FORMAT_MAX + 1] = {
650 GL_RGBA, // RGBA_8888
651 GL_RGBA, // RGBA_4444
652 GL_BGRA_EXT, // BGRA_8888
653 GL_ALPHA, // ALPHA_8
654 GL_LUMINANCE, // LUMINANCE_8
655 GL_RGB, // RGB_565
656 GL_ETC1_RGB8_OES, // ETC1
657 GL_RED_EXT // RED_8
658 };
659 return format_gl_data_format[format];
660 }
661
662 inline GLenum GLInternalFormat(ResourceFormat format) {
663 return GLDataFormat(format);
664 }
665
666 } // namespace cc
667
668 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/resources/resource_pool.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698