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

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: bilinear filter for rg88, float and half float added. Created 4 years, 5 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 case LUMINANCE_F32:
16 return 32; 17 return 32;
17 case RGBA_4444: 18 case RGBA_4444:
18 case RGB_565: 19 case RGB_565:
20 case RG_88:
19 case LUMINANCE_F16: 21 case LUMINANCE_F16:
20 return 16; 22 return 16;
21 case ALPHA_8: 23 case ALPHA_8:
22 case LUMINANCE_8: 24 case LUMINANCE_8:
23 case RED_8: 25 case RED_8:
24 return 8; 26 return 8;
25 case ETC1: 27 case ETC1:
26 return 4; 28 return 4;
27 } 29 }
28 NOTREACHED(); 30 NOTREACHED();
29 return 0; 31 return 0;
30 } 32 }
31 33
32 GLenum GLDataType(ResourceFormat format) { 34 GLenum GLDataType(ResourceFormat format) {
33 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 35 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
34 static const GLenum format_gl_data_type[] = { 36 static const GLenum format_gl_data_type[] = {
35 GL_UNSIGNED_BYTE, // RGBA_8888 37 GL_UNSIGNED_BYTE, // RGBA_8888
36 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 38 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
37 GL_UNSIGNED_BYTE, // BGRA_8888 39 GL_UNSIGNED_BYTE, // BGRA_8888
38 GL_UNSIGNED_BYTE, // ALPHA_8 40 GL_UNSIGNED_BYTE, // ALPHA_8
39 GL_UNSIGNED_BYTE, // LUMINANCE_8 41 GL_UNSIGNED_BYTE, // LUMINANCE_8
40 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, 42 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
41 GL_UNSIGNED_BYTE, // ETC1 43 GL_UNSIGNED_BYTE, // ETC1
42 GL_UNSIGNED_BYTE, // RED_8 44 GL_UNSIGNED_BYTE, // RED_8
43 GL_HALF_FLOAT_OES, // LUMINANCE_F16 45 GL_HALF_FLOAT_OES, // LUMINANCE_F16
46 GL_FLOAT, // LUMINANCE_F32
47 GL_UNSIGNED_BYTE, // RG_88
44 }; 48 };
45 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), 49 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1),
46 "format_gl_data_type does not handle all cases."); 50 "format_gl_data_type does not handle all cases.");
47 51
48 return format_gl_data_type[format]; 52 return format_gl_data_type[format];
49 } 53 }
50 54
51 GLenum GLDataFormat(ResourceFormat format) { 55 GLenum GLDataFormat(ResourceFormat format) {
52 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 56 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
53 static const GLenum format_gl_data_format[] = { 57 static const GLenum format_gl_data_format[] = {
54 GL_RGBA, // RGBA_8888 58 GL_RGBA, // RGBA_8888
55 GL_RGBA, // RGBA_4444 59 GL_RGBA, // RGBA_4444
56 GL_BGRA_EXT, // BGRA_8888 60 GL_BGRA_EXT, // BGRA_8888
57 GL_ALPHA, // ALPHA_8 61 GL_ALPHA, // ALPHA_8
58 GL_LUMINANCE, // LUMINANCE_8 62 GL_LUMINANCE, // LUMINANCE_8
59 GL_RGB, // RGB_565 63 GL_RGB, // RGB_565
60 GL_ETC1_RGB8_OES, // ETC1 64 GL_ETC1_RGB8_OES, // ETC1
61 GL_RED_EXT, // RED_8 65 GL_RED_EXT, // RED_8
62 GL_LUMINANCE, // LUMINANCE_F16 66 GL_LUMINANCE, // LUMINANCE_F16
67 GL_LUMINANCE, // LUMINANCE_F32
68 GL_RG_EXT, // RG_88
63 }; 69 };
64 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 70 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
65 "format_gl_data_format does not handle all cases."); 71 "format_gl_data_format does not handle all cases.");
66 return format_gl_data_format[format]; 72 return format_gl_data_format[format];
67 } 73 }
68 74
69 GLenum GLInternalFormat(ResourceFormat format) { 75 GLenum GLInternalFormat(ResourceFormat format) {
70 // In GLES2, the internal format must match the texture format. (It no longer 76 // 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.) 77 // is true in GLES3, however it still holds for the BGRA extension.)
72 return GLDataFormat(format); 78 return GLDataFormat(format);
(...skipping 10 matching lines...) Expand all
83 static const GLenum format_gl_data_format[] = { 89 static const GLenum format_gl_data_format[] = {
84 GL_RGBA, // RGBA_8888 90 GL_RGBA, // RGBA_8888
85 GL_RGBA, // RGBA_4444 91 GL_RGBA, // RGBA_4444
86 GL_RGBA, // BGRA_8888 92 GL_RGBA, // BGRA_8888
87 GL_ALPHA, // ALPHA_8 93 GL_ALPHA, // ALPHA_8
88 GL_LUMINANCE, // LUMINANCE_8 94 GL_LUMINANCE, // LUMINANCE_8
89 GL_RGB, // RGB_565 95 GL_RGB, // RGB_565
90 GL_RGB, // ETC1 96 GL_RGB, // ETC1
91 GL_LUMINANCE, // RED_8 97 GL_LUMINANCE, // RED_8
92 GL_LUMINANCE, // LUMINANCE_F16 98 GL_LUMINANCE, // LUMINANCE_F16
99 GL_LUMINANCE, // LUMINANCE_F32
100 GL_RG_EXT, // RG_88
93 }; 101 };
94 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 102 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
95 "format_gl_data_format does not handle all cases."); 103 "format_gl_data_format does not handle all cases.");
96 return format_gl_data_format[format]; 104 return format_gl_data_format[format];
97 } 105 }
98 106
99 gfx::BufferFormat BufferFormat(ResourceFormat format) { 107 gfx::BufferFormat BufferFormat(ResourceFormat format) {
100 switch (format) { 108 switch (format) {
101 case BGRA_8888: 109 case BGRA_8888:
102 return gfx::BufferFormat::BGRA_8888; 110 return gfx::BufferFormat::BGRA_8888;
103 case RED_8: 111 case RED_8:
104 return gfx::BufferFormat::R_8; 112 return gfx::BufferFormat::R_8;
105 case RGBA_4444: 113 case RGBA_4444:
106 return gfx::BufferFormat::RGBA_4444; 114 return gfx::BufferFormat::RGBA_4444;
107 case RGBA_8888: 115 case RGBA_8888:
108 return gfx::BufferFormat::RGBA_8888; 116 return gfx::BufferFormat::RGBA_8888;
109 case ETC1: 117 case ETC1:
110 return gfx::BufferFormat::ETC1; 118 return gfx::BufferFormat::ETC1;
111 case ALPHA_8: 119 case ALPHA_8:
112 case LUMINANCE_8: 120 case LUMINANCE_8:
113 case RGB_565: 121 case RGB_565:
114 case LUMINANCE_F16: 122 case LUMINANCE_F16:
123 case LUMINANCE_F32:
124 case RG_88:
115 break; 125 break;
116 } 126 }
117 NOTREACHED(); 127 NOTREACHED();
118 return gfx::BufferFormat::RGBA_8888; 128 return gfx::BufferFormat::RGBA_8888;
119 } 129 }
120 130
121 bool IsResourceFormatCompressed(ResourceFormat format) { 131 bool IsResourceFormatCompressed(ResourceFormat format) {
122 return format == ETC1; 132 return format == ETC1;
123 } 133 }
124 134
125 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { 135 bool DoesResourceFormatSupportAlpha(ResourceFormat format) {
126 switch (format) { 136 switch (format) {
127 case RGBA_4444: 137 case RGBA_4444:
128 case RGBA_8888: 138 case RGBA_8888:
129 case BGRA_8888: 139 case BGRA_8888:
130 case ALPHA_8: 140 case ALPHA_8:
131 return true; 141 return true;
132 case LUMINANCE_8: 142 case LUMINANCE_8:
133 case RGB_565: 143 case RGB_565:
134 case ETC1: 144 case ETC1:
135 case RED_8: 145 case RED_8:
136 case LUMINANCE_F16: 146 case LUMINANCE_F16:
147 case LUMINANCE_F32:
148 case RG_88:
137 return false; 149 return false;
138 } 150 }
139 NOTREACHED(); 151 NOTREACHED();
140 return false; 152 return false;
141 } 153 }
142 154
143 } // namespace cc 155 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698