[NaCl SDK]: use standard __BEGIN_DECLS macros in sys/select.h
[chromium-blink-merge.git] / cc / resources / resource_provider.h
blob3295aee5ac43f46603fc01897f686fcabc9c3cb6
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.
5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_
6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_
8 #include <deque>
9 #include <set>
10 #include <string>
11 #include <utility>
12 #include <vector>
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/base/cc_export.h"
21 #include "cc/output/context_provider.h"
22 #include "cc/output/output_surface.h"
23 #include "cc/resources/raster_buffer.h"
24 #include "cc/resources/release_callback_impl.h"
25 #include "cc/resources/resource_format.h"
26 #include "cc/resources/return_callback.h"
27 #include "cc/resources/shared_bitmap.h"
28 #include "cc/resources/single_release_callback_impl.h"
29 #include "cc/resources/texture_mailbox.h"
30 #include "cc/resources/transferable_resource.h"
31 #include "third_party/khronos/GLES2/gl2.h"
32 #include "third_party/khronos/GLES2/gl2ext.h"
33 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "third_party/skia/include/core/SkCanvas.h"
35 #include "ui/gfx/size.h"
37 class GrContext;
39 namespace gpu {
40 namespace gles {
41 class GLES2Interface;
45 namespace gfx {
46 class Rect;
47 class Vector2d;
50 namespace cc {
51 class BlockingTaskRunner;
52 class IdAllocator;
53 class SharedBitmap;
54 class SharedBitmapManager;
55 class TextureUploader;
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 CC_EXPORT ResourceProvider {
60 public:
61 typedef unsigned ResourceId;
62 typedef std::vector<ResourceId> ResourceIdArray;
63 typedef std::set<ResourceId> ResourceIdSet;
64 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap;
65 enum TextureHint {
66 TextureHintDefault = 0x0,
67 TextureHintImmutable = 0x1,
68 TextureHintFramebuffer = 0x2,
69 TextureHintImmutableFramebuffer =
70 TextureHintImmutable | TextureHintFramebuffer
72 enum ResourceType {
73 InvalidType = 0,
74 GLTexture = 1,
75 Bitmap,
78 static scoped_ptr<ResourceProvider> Create(
79 OutputSurface* output_surface,
80 SharedBitmapManager* shared_bitmap_manager,
81 BlockingTaskRunner* blocking_main_thread_task_runner,
82 int highp_threshold_min,
83 bool use_rgba_4444_texture_format,
84 size_t id_allocation_chunk_size,
85 bool use_distance_field_text);
86 virtual ~ResourceProvider();
88 void InitializeSoftware();
89 void InitializeGL();
91 void DidLoseOutputSurface() { lost_output_surface_ = true; }
93 int max_texture_size() const { return max_texture_size_; }
94 ResourceFormat memory_efficient_texture_format() const {
95 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_;
97 ResourceFormat best_texture_format() const { return best_texture_format_; }
98 bool use_sync_query() const { return use_sync_query_; }
99 size_t num_resources() const { return resources_.size(); }
101 // Checks whether a resource is in use by a consumer.
102 bool InUseByConsumer(ResourceId id);
104 bool IsLost(ResourceId id);
105 bool AllowOverlay(ResourceId id);
107 // Producer interface.
109 ResourceType default_resource_type() const { return default_resource_type_; }
110 ResourceType GetResourceType(ResourceId id);
112 // Creates a resource of the default resource type.
113 ResourceId CreateResource(const gfx::Size& size,
114 GLint wrap_mode,
115 TextureHint hint,
116 ResourceFormat format);
118 // Creates a resource which is tagged as being managed for GPU memory
119 // accounting purposes.
120 ResourceId CreateManagedResource(const gfx::Size& size,
121 GLenum target,
122 GLint wrap_mode,
123 TextureHint hint,
124 ResourceFormat format);
126 // You can also explicitly create a specific resource type.
127 ResourceId CreateGLTexture(const gfx::Size& size,
128 GLenum target,
129 GLenum texture_pool,
130 GLint wrap_mode,
131 TextureHint hint,
132 ResourceFormat format);
134 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode);
135 // Wraps an IOSurface into a GL resource.
136 ResourceId CreateResourceFromIOSurface(const gfx::Size& size,
137 unsigned io_surface_id);
139 // Wraps an external texture mailbox into a GL resource.
140 ResourceId CreateResourceFromTextureMailbox(
141 const TextureMailbox& mailbox,
142 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl);
144 void DeleteResource(ResourceId id);
146 // Update pixels from image, copying source_rect (in image) to dest_offset (in
147 // the resource).
148 void SetPixels(ResourceId id,
149 const uint8_t* image,
150 const gfx::Rect& image_rect,
151 const gfx::Rect& source_rect,
152 const gfx::Vector2d& dest_offset);
154 // Check upload status.
155 size_t NumBlockingUploads();
156 void MarkPendingUploadsAsNonBlocking();
157 size_t EstimatedUploadsPerTick();
158 void FlushUploads();
159 void ReleaseCachedData();
160 base::TimeTicks EstimatedUploadCompletionTime(size_t uploads_per_tick);
162 // Only flush the command buffer if supported.
163 // Returns true if the shallow flush occurred, false otherwise.
164 bool ShallowFlushIfSupported();
166 // Creates accounting for a child. Returns a child ID.
167 int CreateChild(const ReturnCallback& return_callback);
169 // Destroys accounting for the child, deleting all accounted resources.
170 void DestroyChild(int child);
172 // Gets the child->parent resource ID map.
173 const ResourceIdMap& GetChildToParentMap(int child) const;
175 // Prepares resources to be transfered to the parent, moving them to
176 // mailboxes and serializing meta-data into TransferableResources.
177 // Resources are not removed from the ResourceProvider, but are marked as
178 // "in use".
179 void PrepareSendToParent(const ResourceIdArray& resources,
180 TransferableResourceArray* transferable_resources);
182 // Receives resources from a child, moving them from mailboxes. Resource IDs
183 // passed are in the child namespace, and will be translated to the parent
184 // namespace, added to the child->parent map.
185 // This adds the resources to the working set in the ResourceProvider without
186 // declaring which resources are in use. Use DeclareUsedResourcesFromChild
187 // after calling this method to do that. All calls to ReceiveFromChild should
188 // be followed by a DeclareUsedResourcesFromChild.
189 // NOTE: if the sync_point is set on any TransferableResource, this will
190 // wait on it.
191 void ReceiveFromChild(
192 int child, const TransferableResourceArray& transferable_resources);
194 // Once a set of resources have been received, they may or may not be used.
195 // This declares what set of resources are currently in use from the child,
196 // releasing any other resources back to the child.
197 void DeclareUsedResourcesFromChild(
198 int child,
199 const ResourceIdArray& resources_from_child);
201 // Receives resources from the parent, moving them from mailboxes. Resource
202 // IDs passed are in the child namespace.
203 // NOTE: if the sync_point is set on any TransferableResource, this will
204 // wait on it.
205 void ReceiveReturnsFromParent(
206 const ReturnedResourceArray& transferable_resources);
208 // The following lock classes are part of the ResourceProvider API and are
209 // needed to read and write the resource contents. The user must ensure
210 // that they only use GL locks on GL resources, etc, and this is enforced
211 // by assertions.
212 class CC_EXPORT ScopedReadLockGL {
213 public:
214 ScopedReadLockGL(ResourceProvider* resource_provider,
215 ResourceProvider::ResourceId resource_id);
216 virtual ~ScopedReadLockGL();
218 unsigned texture_id() const { return texture_id_; }
220 protected:
221 ResourceProvider* resource_provider_;
222 ResourceProvider::ResourceId resource_id_;
224 private:
225 unsigned texture_id_;
227 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL);
230 class CC_EXPORT ScopedSamplerGL : public ScopedReadLockGL {
231 public:
232 ScopedSamplerGL(ResourceProvider* resource_provider,
233 ResourceProvider::ResourceId resource_id,
234 GLenum filter);
235 ScopedSamplerGL(ResourceProvider* resource_provider,
236 ResourceProvider::ResourceId resource_id,
237 GLenum unit,
238 GLenum filter);
239 virtual ~ScopedSamplerGL();
241 GLenum target() const { return target_; }
243 private:
244 GLenum unit_;
245 GLenum target_;
247 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL);
250 class CC_EXPORT ScopedWriteLockGL {
251 public:
252 ScopedWriteLockGL(ResourceProvider* resource_provider,
253 ResourceProvider::ResourceId resource_id);
254 ~ScopedWriteLockGL();
256 unsigned texture_id() const { return texture_id_; }
258 private:
259 ResourceProvider* resource_provider_;
260 ResourceProvider::ResourceId resource_id_;
261 unsigned texture_id_;
263 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL);
266 class CC_EXPORT ScopedReadLockSoftware {
267 public:
268 ScopedReadLockSoftware(ResourceProvider* resource_provider,
269 ResourceProvider::ResourceId resource_id);
270 ~ScopedReadLockSoftware();
272 const SkBitmap* sk_bitmap() const {
273 DCHECK(valid());
274 return &sk_bitmap_;
276 GLint wrap_mode() const { return wrap_mode_; }
278 bool valid() const { return !!sk_bitmap_.getPixels(); }
280 private:
281 ResourceProvider* resource_provider_;
282 ResourceProvider::ResourceId resource_id_;
283 SkBitmap sk_bitmap_;
284 GLint wrap_mode_;
286 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockSoftware);
289 class CC_EXPORT ScopedWriteLockSoftware {
290 public:
291 ScopedWriteLockSoftware(ResourceProvider* resource_provider,
292 ResourceProvider::ResourceId resource_id);
293 ~ScopedWriteLockSoftware();
295 SkCanvas* sk_canvas() { return sk_canvas_.get(); }
296 bool valid() const { return !!sk_bitmap_.getPixels(); }
298 private:
299 ResourceProvider* resource_provider_;
300 ResourceProvider::ResourceId resource_id_;
301 SkBitmap sk_bitmap_;
302 scoped_ptr<SkCanvas> sk_canvas_;
304 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware);
307 class Fence : public base::RefCounted<Fence> {
308 public:
309 Fence() {}
311 virtual void Set() = 0;
312 virtual bool HasPassed() = 0;
314 protected:
315 friend class base::RefCounted<Fence>;
316 virtual ~Fence() {}
318 private:
319 DISALLOW_COPY_AND_ASSIGN(Fence);
322 // Returns a RasterBuffer for gpu rasterization.
323 // Call Release before the resource can be read or used for compositing.
324 // It is used for direct gpu rasterization.
325 RasterBuffer* AcquireGpuRasterBuffer(ResourceId id);
326 void ReleaseGpuRasterBuffer(ResourceId id);
328 // Returns a RasterBuffer backed by an image buffer. ReleaseImageRasterBuffer
329 // returns true if RasterBuffer was written to while acquired.
330 // Rasterizing to the RasterBuffer writes the content into the image buffer,
331 // which is internally bound to the underlying resource when read.
332 // Call Release before the resource can be read or used for compositing.
333 // It is used by ImageRasterWorkerPool.
334 RasterBuffer* AcquireImageRasterBuffer(ResourceId id);
335 bool ReleaseImageRasterBuffer(ResourceId id);
337 // Returns a RasterBuffer backed by pixel buffer. ReleasePixelRasterBuffer
338 // returns true if RasterBuffer was written to while acquired.
339 // The pixel buffer needs to be uploaded to the underlying resource
340 // using BeginSetPixels before the resouce can be used for compositing.
341 // It is used by PixelRasterWorkerPool.
342 RasterBuffer* AcquirePixelRasterBuffer(ResourceId id);
343 bool ReleasePixelRasterBuffer(ResourceId id);
345 // Asynchronously update pixels from acquired pixel buffer.
346 void BeginSetPixels(ResourceId id);
347 void ForceSetPixelsToComplete(ResourceId id);
348 bool DidSetPixelsComplete(ResourceId id);
350 // For tests only! This prevents detecting uninitialized reads.
351 // Use SetPixels or LockForWrite to allocate implicitly.
352 void AllocateForTesting(ResourceId id);
354 // For tests only!
355 void CreateForTesting(ResourceId id);
357 GLenum TargetForTesting(ResourceId id);
359 // Sets the current read fence. If a resource is locked for read
360 // and has read fences enabled, the resource will not allow writes
361 // until this fence has passed.
362 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; }
364 // Enable read lock fences for a specific resource.
365 void EnableReadLockFences(ResourceProvider::ResourceId id);
367 // Indicates if we can currently lock this resource for write.
368 bool CanLockForWrite(ResourceId id);
370 // Copy pixels from source to destination.
371 void CopyResource(ResourceId source_id, ResourceId dest_id);
373 void WaitSyncPointIfNeeded(ResourceId id);
375 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl);
377 private:
378 class GpuRasterBuffer;
379 class ImageRasterBuffer;
380 class PixelRasterBuffer;
382 struct Resource {
383 enum Origin { Internal, External, Delegated };
385 Resource();
386 ~Resource();
387 Resource(unsigned texture_id,
388 const gfx::Size& size,
389 Origin origin,
390 GLenum target,
391 GLenum filter,
392 GLenum texture_pool,
393 GLint wrap_mode,
394 TextureHint hint,
395 ResourceFormat format);
396 Resource(uint8_t* pixels,
397 SharedBitmap* bitmap,
398 const gfx::Size& size,
399 Origin origin,
400 GLenum filter,
401 GLint wrap_mode);
402 Resource(const SharedBitmapId& bitmap_id,
403 const gfx::Size& size,
404 Origin origin,
405 GLenum filter,
406 GLint wrap_mode);
408 int child_id;
409 unsigned gl_id;
410 // Pixel buffer used for set pixels without unnecessary copying.
411 unsigned gl_pixel_buffer_id;
412 // Query used to determine when asynchronous set pixels complete.
413 unsigned gl_upload_query_id;
414 // Query used to determine when read lock fence has passed.
415 unsigned gl_read_lock_query_id;
416 TextureMailbox mailbox;
417 ReleaseCallbackImpl release_callback_impl;
418 uint8_t* pixels;
419 int lock_for_read_count;
420 int imported_count;
421 int exported_count;
422 bool dirty_image : 1;
423 bool locked_for_write : 1;
424 bool lost : 1;
425 bool marked_for_deletion : 1;
426 bool pending_set_pixels : 1;
427 bool set_pixels_completion_forced : 1;
428 bool allocated : 1;
429 bool read_lock_fences_enabled : 1;
430 bool has_shared_bitmap_id : 1;
431 bool allow_overlay : 1;
432 scoped_refptr<Fence> read_lock_fence;
433 gfx::Size size;
434 Origin origin;
435 GLenum target;
436 // TODO(skyostil): Use a separate sampler object for filter state.
437 GLenum original_filter;
438 GLenum filter;
439 unsigned image_id;
440 unsigned bound_image_id;
441 GLenum texture_pool;
442 GLint wrap_mode;
443 TextureHint hint;
444 ResourceType type;
445 ResourceFormat format;
446 SharedBitmapId shared_bitmap_id;
447 SharedBitmap* shared_bitmap;
448 linked_ptr<GpuRasterBuffer> gpu_raster_buffer;
449 linked_ptr<ImageRasterBuffer> image_raster_buffer;
450 linked_ptr<PixelRasterBuffer> pixel_raster_buffer;
452 typedef base::hash_map<ResourceId, Resource> ResourceMap;
454 class GpuRasterBuffer : public RasterBuffer {
455 public:
456 GpuRasterBuffer(const Resource* resource,
457 ResourceProvider* resource_provider,
458 bool use_distance_field_text);
459 virtual ~GpuRasterBuffer();
461 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE;
462 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE;
464 private:
465 const Resource* resource_;
466 ResourceProvider* resource_provider_;
467 skia::RefPtr<SkSurface> surface_;
469 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer);
472 class ImageRasterBuffer : public RasterBuffer {
473 public:
474 ImageRasterBuffer(const Resource* resource,
475 ResourceProvider* resource_provider);
476 virtual ~ImageRasterBuffer();
478 void MapBuffer();
479 bool UnmapBuffer();
481 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE;
482 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE;
484 private:
485 const Resource* resource_;
486 ResourceProvider* resource_provider_;
487 uint8_t* mapped_buffer_;
488 SkBitmap raster_bitmap_;
489 bool raster_bitmap_changed_;
490 int stride_;
492 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer);
495 class PixelRasterBuffer : public RasterBuffer {
496 public:
497 PixelRasterBuffer(const Resource* resource,
498 ResourceProvider* resource_provider);
499 virtual ~PixelRasterBuffer();
501 void MapBuffer();
502 bool UnmapBuffer();
504 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE;
505 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE;
507 private:
508 const Resource* resource_;
509 ResourceProvider* resource_provider_;
510 uint8_t* mapped_buffer_;
511 SkBitmap raster_bitmap_;
512 bool raster_bitmap_changed_;
513 int stride_;
515 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer);
518 static bool CompareResourceMapIteratorsByChildId(
519 const std::pair<ReturnedResource, ResourceMap::iterator>& a,
520 const std::pair<ReturnedResource, ResourceMap::iterator>& b);
522 struct Child {
523 Child();
524 ~Child();
526 ResourceIdMap child_to_parent_map;
527 ResourceIdMap parent_to_child_map;
528 ReturnCallback return_callback;
529 ResourceIdSet in_use_resources;
530 bool marked_for_deletion;
532 typedef base::hash_map<int, Child> ChildMap;
534 bool ReadLockFenceHasPassed(const Resource* resource) {
535 return !resource->read_lock_fence.get() ||
536 resource->read_lock_fence->HasPassed();
539 ResourceProvider(OutputSurface* output_surface,
540 SharedBitmapManager* shared_bitmap_manager,
541 BlockingTaskRunner* blocking_main_thread_task_runner,
542 int highp_threshold_min,
543 bool use_rgba_4444_texture_format,
544 size_t id_allocation_chunk_size,
545 bool use_distance_field_text);
547 void CleanUpGLIfNeeded();
549 Resource* GetResource(ResourceId id);
550 const Resource* LockForRead(ResourceId id);
551 void UnlockForRead(ResourceId id);
552 const Resource* LockForWrite(ResourceId id);
553 void UnlockForWrite(ResourceId id);
554 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
555 const Resource* resource);
557 void TransferResource(gpu::gles2::GLES2Interface* gl,
558 ResourceId id,
559 TransferableResource* resource);
560 enum DeleteStyle {
561 Normal,
562 ForShutdown,
564 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
565 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
566 DeleteStyle style,
567 const ResourceIdArray& unused);
568 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
569 void LazyCreate(Resource* resource);
570 void LazyAllocate(Resource* resource);
572 // TODO(alokp): Move the implementation to PixelRasterBuffer.
573 // Acquire pixel buffer for resource. The pixel buffer can be used to
574 // set resource pixels without performing unnecessary copying.
575 void AcquirePixelBuffer(Resource* resource);
576 void ReleasePixelBuffer(Resource* resource);
577 // Map/unmap the acquired pixel buffer.
578 uint8_t* MapPixelBuffer(const Resource* resource, int* stride);
579 void UnmapPixelBuffer(const Resource* resource);
581 // TODO(alokp): Move the implementation to ImageRasterBuffer.
582 // Acquire and release an image. The image allows direct
583 // manipulation of texture memory.
584 void AcquireImage(Resource* resource);
585 void ReleaseImage(Resource* resource);
586 // Maps the acquired image so that its pixels could be modified.
587 // Unmap is called when all pixels are set.
588 uint8_t* MapImage(const Resource* resource, int* stride);
589 void UnmapImage(const Resource* resource);
591 void BindImageForSampling(Resource* resource);
592 // Binds the given GL resource to a texture target for sampling using the
593 // specified filter for both minification and magnification. Returns the
594 // texture target used. The resource must be locked for reading.
595 GLenum BindForSampling(ResourceProvider::ResourceId resource_id,
596 GLenum unit,
597 GLenum filter);
599 // Returns NULL if the output_surface_ does not have a ContextProvider.
600 gpu::gles2::GLES2Interface* ContextGL() const;
601 class GrContext* GrContext() const;
603 OutputSurface* output_surface_;
604 SharedBitmapManager* shared_bitmap_manager_;
605 BlockingTaskRunner* blocking_main_thread_task_runner_;
606 bool lost_output_surface_;
607 int highp_threshold_min_;
608 ResourceId next_id_;
609 ResourceMap resources_;
610 int next_child_;
611 ChildMap children_;
613 ResourceType default_resource_type_;
614 bool use_texture_storage_ext_;
615 bool use_texture_format_bgra_;
616 bool use_texture_usage_hint_;
617 bool use_compressed_texture_etc1_;
618 scoped_ptr<TextureUploader> texture_uploader_;
619 int max_texture_size_;
620 ResourceFormat best_texture_format_;
622 base::ThreadChecker thread_checker_;
624 scoped_refptr<Fence> current_read_lock_fence_;
625 bool use_rgba_4444_texture_format_;
627 const size_t id_allocation_chunk_size_;
628 scoped_ptr<IdAllocator> texture_id_allocator_;
629 scoped_ptr<IdAllocator> buffer_id_allocator_;
631 bool use_sync_query_;
633 bool use_distance_field_text_;
635 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
639 // TODO(epenner): Move these format conversions to resource_format.h
640 // once that builds on mac (npapi.h currently #includes OpenGL.h).
641 inline unsigned BitsPerPixel(ResourceFormat format) {
642 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
643 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = {
644 32, // RGBA_8888
645 16, // RGBA_4444
646 32, // BGRA_8888
647 8, // ALPHA_8
648 8, // LUMINANCE_8
649 16, // RGB_565,
650 4 // ETC1
652 return format_bits_per_pixel[format];
655 inline GLenum GLDataType(ResourceFormat format) {
656 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
657 static const unsigned format_gl_data_type[RESOURCE_FORMAT_MAX + 1] = {
658 GL_UNSIGNED_BYTE, // RGBA_8888
659 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
660 GL_UNSIGNED_BYTE, // BGRA_8888
661 GL_UNSIGNED_BYTE, // ALPHA_8
662 GL_UNSIGNED_BYTE, // LUMINANCE_8
663 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
664 GL_UNSIGNED_BYTE // ETC1
666 return format_gl_data_type[format];
669 inline GLenum GLDataFormat(ResourceFormat format) {
670 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
671 static const unsigned format_gl_data_format[RESOURCE_FORMAT_MAX + 1] = {
672 GL_RGBA, // RGBA_8888
673 GL_RGBA, // RGBA_4444
674 GL_BGRA_EXT, // BGRA_8888
675 GL_ALPHA, // ALPHA_8
676 GL_LUMINANCE, // LUMINANCE_8
677 GL_RGB, // RGB_565
678 GL_ETC1_RGB8_OES // ETC1
680 return format_gl_data_format[format];
683 inline GLenum GLInternalFormat(ResourceFormat format) {
684 return GLDataFormat(format);
687 } // namespace cc
689 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_