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

Side by Side Diff: cc/resources/resource_format.cc

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: WebGL video to texture support and readPixels from R16UI for CPU access Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_format.h" 5 #include "cc/resources/resource_format.h"
6 6
7 #include "third_party/khronos/GLES2/gl2.h" 7 #include "third_party/khronos/GLES2/gl2.h"
8 #include "third_party/khronos/GLES2/gl2ext.h" 8 #include "third_party/khronos/GLES2/gl2ext.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 int BitsPerPixel(ResourceFormat format) { 12 int BitsPerPixel(ResourceFormat format) {
13 switch (format) { 13 switch (format) {
14 case BGRA_8888: 14 case BGRA_8888:
15 case RGBA_8888: 15 case RGBA_8888:
16 return 32; 16 return 32;
17 case RGBA_4444: 17 case RGBA_4444:
18 case RGB_565: 18 case RGB_565:
19 case RG_88:
19 case LUMINANCE_F16: 20 case LUMINANCE_F16:
20 return 16; 21 return 16;
21 case ALPHA_8: 22 case ALPHA_8:
22 case LUMINANCE_8: 23 case LUMINANCE_8:
23 case RED_8: 24 case RED_8:
24 return 8; 25 return 8;
25 case ETC1: 26 case ETC1:
26 return 4; 27 return 4;
27 } 28 }
28 NOTREACHED(); 29 NOTREACHED();
29 return 0; 30 return 0;
30 } 31 }
31 32
32 GLenum GLDataType(ResourceFormat format) { 33 GLenum GLDataType(ResourceFormat format) {
33 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 34 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
34 static const GLenum format_gl_data_type[] = { 35 static const GLenum format_gl_data_type[] = {
35 GL_UNSIGNED_BYTE, // RGBA_8888 36 GL_UNSIGNED_BYTE, // RGBA_8888
36 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 37 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
37 GL_UNSIGNED_BYTE, // BGRA_8888 38 GL_UNSIGNED_BYTE, // BGRA_8888
38 GL_UNSIGNED_BYTE, // ALPHA_8 39 GL_UNSIGNED_BYTE, // ALPHA_8
39 GL_UNSIGNED_BYTE, // LUMINANCE_8 40 GL_UNSIGNED_BYTE, // LUMINANCE_8
40 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, 41 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
41 GL_UNSIGNED_BYTE, // ETC1 42 GL_UNSIGNED_BYTE, // ETC1
42 GL_UNSIGNED_BYTE, // RED_8 43 GL_UNSIGNED_BYTE, // RED_8
43 GL_HALF_FLOAT_OES, // LUMINANCE_F16 44 GL_HALF_FLOAT_OES, // LUMINANCE_F16
45 GL_UNSIGNED_BYTE, // RG_88
44 }; 46 };
45 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), 47 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1),
46 "format_gl_data_type does not handle all cases."); 48 "format_gl_data_type does not handle all cases.");
47 49
48 return format_gl_data_type[format]; 50 return format_gl_data_type[format];
49 } 51 }
50 52
51 GLenum GLDataFormat(ResourceFormat format) { 53 GLenum GLDataFormat(ResourceFormat format) {
52 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 54 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
53 static const GLenum format_gl_data_format[] = { 55 static const GLenum format_gl_data_format[] = {
54 GL_RGBA, // RGBA_8888 56 GL_RGBA, // RGBA_8888
55 GL_RGBA, // RGBA_4444 57 GL_RGBA, // RGBA_4444
56 GL_BGRA_EXT, // BGRA_8888 58 GL_BGRA_EXT, // BGRA_8888
57 GL_ALPHA, // ALPHA_8 59 GL_ALPHA, // ALPHA_8
58 GL_LUMINANCE, // LUMINANCE_8 60 GL_LUMINANCE, // LUMINANCE_8
59 GL_RGB, // RGB_565 61 GL_RGB, // RGB_565
60 GL_ETC1_RGB8_OES, // ETC1 62 GL_ETC1_RGB8_OES, // ETC1
61 GL_RED_EXT, // RED_8 63 GL_RED_EXT, // RED_8
62 GL_LUMINANCE, // LUMINANCE_F16 64 GL_LUMINANCE, // LUMINANCE_F16
65 GL_RG_EXT, // RG_88
63 }; 66 };
64 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 67 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
65 "format_gl_data_format does not handle all cases."); 68 "format_gl_data_format does not handle all cases.");
66 return format_gl_data_format[format]; 69 return format_gl_data_format[format];
67 } 70 }
68 71
69 GLenum GLInternalFormat(ResourceFormat format) { 72 GLenum GLInternalFormat(ResourceFormat format) {
70 // In GLES2, the internal format must match the texture format. (It no longer 73 // In GLES2, the internal format must match the texture format. (It no longer
71 // is true in GLES3, however it still holds for the BGRA extension.) 74 // is true in GLES3, however it still holds for the BGRA extension.)
72 return GLDataFormat(format); 75 return GLDataFormat(format);
(...skipping 10 matching lines...) Expand all
83 static const GLenum format_gl_data_format[] = { 86 static const GLenum format_gl_data_format[] = {
84 GL_RGBA, // RGBA_8888 87 GL_RGBA, // RGBA_8888
85 GL_RGBA, // RGBA_4444 88 GL_RGBA, // RGBA_4444
86 GL_RGBA, // BGRA_8888 89 GL_RGBA, // BGRA_8888
87 GL_ALPHA, // ALPHA_8 90 GL_ALPHA, // ALPHA_8
88 GL_LUMINANCE, // LUMINANCE_8 91 GL_LUMINANCE, // LUMINANCE_8
89 GL_RGB, // RGB_565 92 GL_RGB, // RGB_565
90 GL_RGB, // ETC1 93 GL_RGB, // ETC1
91 GL_LUMINANCE, // RED_8 94 GL_LUMINANCE, // RED_8
92 GL_LUMINANCE, // LUMINANCE_F16 95 GL_LUMINANCE, // LUMINANCE_F16
96 GL_RG_EXT, // RG_88
93 }; 97 };
94 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 98 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
95 "format_gl_data_format does not handle all cases."); 99 "format_gl_data_format does not handle all cases.");
96 return format_gl_data_format[format]; 100 return format_gl_data_format[format];
97 } 101 }
98 102
99 gfx::BufferFormat BufferFormat(ResourceFormat format) { 103 gfx::BufferFormat BufferFormat(ResourceFormat format) {
100 switch (format) { 104 switch (format) {
101 case BGRA_8888: 105 case BGRA_8888:
102 return gfx::BufferFormat::BGRA_8888; 106 return gfx::BufferFormat::BGRA_8888;
103 case RED_8: 107 case RED_8:
104 return gfx::BufferFormat::R_8; 108 return gfx::BufferFormat::R_8;
105 case RGBA_4444: 109 case RGBA_4444:
106 return gfx::BufferFormat::RGBA_4444; 110 return gfx::BufferFormat::RGBA_4444;
107 case RGBA_8888: 111 case RGBA_8888:
108 return gfx::BufferFormat::RGBA_8888; 112 return gfx::BufferFormat::RGBA_8888;
109 case ETC1: 113 case ETC1:
110 return gfx::BufferFormat::ETC1; 114 return gfx::BufferFormat::ETC1;
111 case ALPHA_8: 115 case ALPHA_8:
112 case LUMINANCE_8: 116 case LUMINANCE_8:
113 case RGB_565: 117 case RGB_565:
114 case LUMINANCE_F16: 118 case LUMINANCE_F16:
119 case RG_88:
115 break; 120 break;
116 } 121 }
117 NOTREACHED(); 122 NOTREACHED();
118 return gfx::BufferFormat::RGBA_8888; 123 return gfx::BufferFormat::RGBA_8888;
119 } 124 }
120 125
121 bool IsResourceFormatCompressed(ResourceFormat format) { 126 bool IsResourceFormatCompressed(ResourceFormat format) {
122 return format == ETC1; 127 return format == ETC1;
123 } 128 }
124 129
125 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { 130 bool DoesResourceFormatSupportAlpha(ResourceFormat format) {
126 switch (format) { 131 switch (format) {
127 case RGBA_4444: 132 case RGBA_4444:
128 case RGBA_8888: 133 case RGBA_8888:
129 case BGRA_8888: 134 case BGRA_8888:
130 case ALPHA_8: 135 case ALPHA_8:
131 return true; 136 return true;
132 case LUMINANCE_8: 137 case LUMINANCE_8:
133 case RGB_565: 138 case RGB_565:
134 case ETC1: 139 case ETC1:
135 case RED_8: 140 case RED_8:
136 case LUMINANCE_F16: 141 case LUMINANCE_F16:
142 case RG_88:
137 return false; 143 return false;
138 } 144 }
139 NOTREACHED(); 145 NOTREACHED();
140 return false; 146 return false;
141 } 147 }
142 148
143 } // namespace cc 149 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698