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

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

Issue 2674493003: Add compositor support for half-float RGBA buffers and textures (Closed)
Patch Set: Don't enable on non-ES3 yet Created 3 years, 10 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_format.h ('k') | cc/resources/resource_format_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "ui/gfx/gpu_memory_buffer.h" 9 #include "ui/gfx/gpu_memory_buffer.h"
10 10
11 namespace cc { 11 namespace cc {
12 12
13 int BitsPerPixel(ResourceFormat format) { 13 int BitsPerPixel(ResourceFormat format) {
14 switch (format) { 14 switch (format) {
15 case RGBA_F16:
16 return 64;
15 case BGRA_8888: 17 case BGRA_8888:
16 case RGBA_8888: 18 case RGBA_8888:
17 return 32; 19 return 32;
18 case RGBA_4444: 20 case RGBA_4444:
19 case RGB_565: 21 case RGB_565:
20 case LUMINANCE_F16: 22 case LUMINANCE_F16:
21 return 16; 23 return 16;
22 case ALPHA_8: 24 case ALPHA_8:
23 case LUMINANCE_8: 25 case LUMINANCE_8:
24 case RED_8: 26 case RED_8:
(...skipping 10 matching lines...) Expand all
35 static const GLenum format_gl_data_type[] = { 37 static const GLenum format_gl_data_type[] = {
36 GL_UNSIGNED_BYTE, // RGBA_8888 38 GL_UNSIGNED_BYTE, // RGBA_8888
37 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 39 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
38 GL_UNSIGNED_BYTE, // BGRA_8888 40 GL_UNSIGNED_BYTE, // BGRA_8888
39 GL_UNSIGNED_BYTE, // ALPHA_8 41 GL_UNSIGNED_BYTE, // ALPHA_8
40 GL_UNSIGNED_BYTE, // LUMINANCE_8 42 GL_UNSIGNED_BYTE, // LUMINANCE_8
41 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, 43 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
42 GL_UNSIGNED_BYTE, // ETC1 44 GL_UNSIGNED_BYTE, // ETC1
43 GL_UNSIGNED_BYTE, // RED_8 45 GL_UNSIGNED_BYTE, // RED_8
44 GL_HALF_FLOAT_OES, // LUMINANCE_F16 46 GL_HALF_FLOAT_OES, // LUMINANCE_F16
47 GL_HALF_FLOAT_OES, // RGBA_F16
45 }; 48 };
46 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), 49 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1),
47 "format_gl_data_type does not handle all cases."); 50 "format_gl_data_type does not handle all cases.");
48 51
49 return format_gl_data_type[format]; 52 return format_gl_data_type[format];
50 } 53 }
51 54
52 GLenum GLDataFormat(ResourceFormat format) { 55 GLenum GLDataFormat(ResourceFormat format) {
53 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 56 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
54 static const GLenum format_gl_data_format[] = { 57 static const GLenum format_gl_data_format[] = {
55 GL_RGBA, // RGBA_8888 58 GL_RGBA, // RGBA_8888
56 GL_RGBA, // RGBA_4444 59 GL_RGBA, // RGBA_4444
57 GL_BGRA_EXT, // BGRA_8888 60 GL_BGRA_EXT, // BGRA_8888
58 GL_ALPHA, // ALPHA_8 61 GL_ALPHA, // ALPHA_8
59 GL_LUMINANCE, // LUMINANCE_8 62 GL_LUMINANCE, // LUMINANCE_8
60 GL_RGB, // RGB_565 63 GL_RGB, // RGB_565
61 GL_ETC1_RGB8_OES, // ETC1 64 GL_ETC1_RGB8_OES, // ETC1
62 GL_RED_EXT, // RED_8 65 GL_RED_EXT, // RED_8
63 GL_LUMINANCE, // LUMINANCE_F16 66 GL_LUMINANCE, // LUMINANCE_F16
67 GL_RGBA, // RGBA_F16
64 }; 68 };
65 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 69 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
66 "format_gl_data_format does not handle all cases."); 70 "format_gl_data_format does not handle all cases.");
67 return format_gl_data_format[format]; 71 return format_gl_data_format[format];
68 } 72 }
69 73
70 GLenum GLInternalFormat(ResourceFormat format) { 74 GLenum GLInternalFormat(ResourceFormat format) {
71 // In GLES2, the internal format must match the texture format. (It no longer 75 // In GLES2, the internal format must match the texture format. (It no longer
72 // is true in GLES3, however it still holds for the BGRA extension.) 76 // is true in GLES3, however it still holds for the BGRA extension.)
73 return GLDataFormat(format); 77 return GLDataFormat(format);
(...skipping 10 matching lines...) Expand all
84 static const GLenum format_gl_data_format[] = { 88 static const GLenum format_gl_data_format[] = {
85 GL_RGBA, // RGBA_8888 89 GL_RGBA, // RGBA_8888
86 GL_RGBA, // RGBA_4444 90 GL_RGBA, // RGBA_4444
87 GL_RGBA, // BGRA_8888 91 GL_RGBA, // BGRA_8888
88 GL_ALPHA, // ALPHA_8 92 GL_ALPHA, // ALPHA_8
89 GL_LUMINANCE, // LUMINANCE_8 93 GL_LUMINANCE, // LUMINANCE_8
90 GL_RGB, // RGB_565 94 GL_RGB, // RGB_565
91 GL_RGB, // ETC1 95 GL_RGB, // ETC1
92 GL_LUMINANCE, // RED_8 96 GL_LUMINANCE, // RED_8
93 GL_LUMINANCE, // LUMINANCE_F16 97 GL_LUMINANCE, // LUMINANCE_F16
98 GL_RGBA, // RGBA_F16
94 }; 99 };
95 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 100 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
96 "format_gl_data_format does not handle all cases."); 101 "format_gl_data_format does not handle all cases.");
97 return format_gl_data_format[format]; 102 return format_gl_data_format[format];
98 } 103 }
99 104
100 gfx::BufferFormat BufferFormat(ResourceFormat format) { 105 gfx::BufferFormat BufferFormat(ResourceFormat format) {
101 switch (format) { 106 switch (format) {
102 case BGRA_8888: 107 case BGRA_8888:
103 return gfx::BufferFormat::BGRA_8888; 108 return gfx::BufferFormat::BGRA_8888;
104 case RED_8: 109 case RED_8:
105 return gfx::BufferFormat::R_8; 110 return gfx::BufferFormat::R_8;
106 case RGBA_4444: 111 case RGBA_4444:
107 return gfx::BufferFormat::RGBA_4444; 112 return gfx::BufferFormat::RGBA_4444;
108 case RGBA_8888: 113 case RGBA_8888:
109 return gfx::BufferFormat::RGBA_8888; 114 return gfx::BufferFormat::RGBA_8888;
110 case ETC1: 115 case ETC1:
111 return gfx::BufferFormat::ETC1; 116 return gfx::BufferFormat::ETC1;
112 case ALPHA_8: 117 case ALPHA_8:
113 case LUMINANCE_8: 118 case LUMINANCE_8:
114 case RGB_565: 119 case RGB_565:
115 case LUMINANCE_F16: 120 case LUMINANCE_F16:
121 case RGBA_F16:
116 break; 122 break;
117 } 123 }
118 NOTREACHED(); 124 NOTREACHED();
119 return gfx::BufferFormat::RGBA_8888; 125 return gfx::BufferFormat::RGBA_8888;
120 } 126 }
121 127
122 bool IsResourceFormatCompressed(ResourceFormat format) { 128 bool IsResourceFormatCompressed(ResourceFormat format) {
123 return format == ETC1; 129 return format == ETC1;
124 } 130 }
125 131
126 bool DoesResourceFormatSupportAlpha(ResourceFormat format) { 132 bool DoesResourceFormatSupportAlpha(ResourceFormat format) {
127 switch (format) { 133 switch (format) {
128 case RGBA_4444: 134 case RGBA_4444:
129 case RGBA_8888: 135 case RGBA_8888:
130 case BGRA_8888: 136 case BGRA_8888:
131 case ALPHA_8: 137 case ALPHA_8:
138 case RGBA_F16:
132 return true; 139 return true;
133 case LUMINANCE_8: 140 case LUMINANCE_8:
134 case RGB_565: 141 case RGB_565:
135 case ETC1: 142 case ETC1:
136 case RED_8: 143 case RED_8:
137 case LUMINANCE_F16: 144 case LUMINANCE_F16:
138 return false; 145 return false;
139 } 146 }
140 NOTREACHED(); 147 NOTREACHED();
141 return false; 148 return false;
142 } 149 }
143 150
144 } // namespace cc 151 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_format.h ('k') | cc/resources/resource_format_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698