OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
11 #include "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "cc/base/util.h" |
15 #include "cc/output/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/output/gl_renderer.h" // For the GLC() macro. |
16 #include "cc/resources/platform_color.h" | 17 #include "cc/resources/platform_color.h" |
17 #include "cc/resources/returned_resource.h" | 18 #include "cc/resources/returned_resource.h" |
18 #include "cc/resources/transferable_resource.h" | 19 #include "cc/resources/transferable_resource.h" |
19 #include "cc/scheduler/texture_uploader.h" | 20 #include "cc/scheduler/texture_uploader.h" |
20 #include "gpu/GLES2/gl2extchromium.h" | 21 #include "gpu/GLES2/gl2extchromium.h" |
21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 22 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
22 #include "third_party/khronos/GLES2/gl2.h" | 23 #include "third_party/khronos/GLES2/gl2.h" |
23 #include "third_party/khronos/GLES2/gl2ext.h" | 24 #include "third_party/khronos/GLES2/gl2ext.h" |
24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/vector2d.h" | 26 #include "ui/gfx/vector2d.h" |
26 | 27 |
27 using WebKit::WebGraphicsContext3D; | 28 using WebKit::WebGraphicsContext3D; |
28 | 29 |
29 namespace cc { | 30 namespace cc { |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 // Measured in seconds. | 34 // Measured in seconds. |
34 const double kSoftwareUploadTickRate = 0.000250; | 35 const double kSoftwareUploadTickRate = 0.000250; |
35 const double kTextureUploadTickRate = 0.004; | 36 const double kTextureUploadTickRate = 0.004; |
36 | 37 |
37 GLenum TextureToStorageFormat(GLenum texture_format) { | 38 GLenum TextureToStorageFormat(ResourceFormat format) { |
38 GLenum storage_format = GL_RGBA8_OES; | 39 GLenum storage_format = GL_RGBA8_OES; |
39 switch (texture_format) { | 40 switch (format) { |
40 case GL_RGBA: | 41 case RGBA_8888: |
| 42 case RGBA_4444: |
| 43 case LUMINANCE_8: |
41 break; | 44 break; |
42 case GL_BGRA_EXT: | 45 case BGRA_8888: |
43 storage_format = GL_BGRA8_EXT; | 46 storage_format = GL_BGRA8_EXT; |
44 break; | 47 break; |
45 default: | |
46 NOTREACHED(); | |
47 break; | |
48 } | 48 } |
49 | 49 |
50 return storage_format; | 50 return storage_format; |
51 } | 51 } |
52 | 52 |
53 bool IsTextureFormatSupportedForStorage(GLenum format) { | 53 bool IsFormatSupportedForStorage(ResourceFormat format) { |
54 return (format == GL_RGBA || format == GL_BGRA_EXT); | 54 switch (format) { |
| 55 case RGBA_8888: |
| 56 case BGRA_8888: |
| 57 return true; |
| 58 case RGBA_4444: |
| 59 case LUMINANCE_8: |
| 60 return false; |
| 61 } |
| 62 return false; |
55 } | 63 } |
56 | 64 |
57 class ScopedSetActiveTexture { | 65 class ScopedSetActiveTexture { |
58 public: | 66 public: |
59 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) | 67 ScopedSetActiveTexture(WebGraphicsContext3D* context3d, GLenum unit) |
60 : context3d_(context3d), unit_(unit) { | 68 : context3d_(context3d), unit_(unit) { |
61 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); | 69 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(context3d_)); |
62 | 70 |
63 if (unit_ != GL_TEXTURE0) | 71 if (unit_ != GL_TEXTURE0) |
64 GLC(context3d_, context3d_->activeTexture(unit_)); | 72 GLC(context3d_, context3d_->activeTexture(unit_)); |
(...skipping 23 matching lines...) Expand all Loading... |
88 exported_count(0), | 96 exported_count(0), |
89 locked_for_write(false), | 97 locked_for_write(false), |
90 external(false), | 98 external(false), |
91 marked_for_deletion(false), | 99 marked_for_deletion(false), |
92 pending_set_pixels(false), | 100 pending_set_pixels(false), |
93 set_pixels_completion_forced(false), | 101 set_pixels_completion_forced(false), |
94 allocated(false), | 102 allocated(false), |
95 enable_read_lock_fences(false), | 103 enable_read_lock_fences(false), |
96 read_lock_fence(NULL), | 104 read_lock_fence(NULL), |
97 size(), | 105 size(), |
98 format(0), | |
99 original_filter(0), | 106 original_filter(0), |
100 filter(0), | 107 filter(0), |
101 target(0), | 108 target(0), |
102 image_id(0), | 109 image_id(0), |
103 texture_pool(0), | 110 texture_pool(0), |
104 wrap_mode(0), | 111 wrap_mode(0), |
105 hint(TextureUsageAny), | 112 hint(TextureUsageAny), |
106 type(static_cast<ResourceType>(0)) {} | 113 type(static_cast<ResourceType>(0)), |
| 114 format(RGBA_8888) {} |
107 | 115 |
108 ResourceProvider::Resource::~Resource() {} | 116 ResourceProvider::Resource::~Resource() {} |
109 | 117 |
110 ResourceProvider::Resource::Resource( | 118 ResourceProvider::Resource::Resource( |
111 unsigned texture_id, | 119 unsigned texture_id, |
112 gfx::Size size, | 120 gfx::Size size, |
113 GLenum format, | |
114 GLenum filter, | 121 GLenum filter, |
115 GLenum texture_pool, | 122 GLenum texture_pool, |
116 GLint wrap_mode, | 123 GLint wrap_mode, |
117 TextureUsageHint hint) | 124 TextureUsageHint hint, |
| 125 ResourceFormat format) |
118 : gl_id(texture_id), | 126 : gl_id(texture_id), |
119 gl_pixel_buffer_id(0), | 127 gl_pixel_buffer_id(0), |
120 gl_upload_query_id(0), | 128 gl_upload_query_id(0), |
121 pixels(NULL), | 129 pixels(NULL), |
122 pixel_buffer(NULL), | 130 pixel_buffer(NULL), |
123 lock_for_read_count(0), | 131 lock_for_read_count(0), |
124 imported_count(0), | 132 imported_count(0), |
125 exported_count(0), | 133 exported_count(0), |
126 locked_for_write(false), | 134 locked_for_write(false), |
127 external(false), | 135 external(false), |
128 marked_for_deletion(false), | 136 marked_for_deletion(false), |
129 pending_set_pixels(false), | 137 pending_set_pixels(false), |
130 set_pixels_completion_forced(false), | 138 set_pixels_completion_forced(false), |
131 allocated(false), | 139 allocated(false), |
132 enable_read_lock_fences(false), | 140 enable_read_lock_fences(false), |
133 read_lock_fence(NULL), | 141 read_lock_fence(NULL), |
134 size(size), | 142 size(size), |
135 format(format), | |
136 original_filter(filter), | 143 original_filter(filter), |
137 filter(filter), | 144 filter(filter), |
138 target(0), | 145 target(0), |
139 image_id(0), | 146 image_id(0), |
140 texture_pool(texture_pool), | 147 texture_pool(texture_pool), |
141 wrap_mode(wrap_mode), | 148 wrap_mode(wrap_mode), |
142 hint(hint), | 149 hint(hint), |
143 type(GLTexture) { | 150 type(GLTexture), |
| 151 format(format) { |
144 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 152 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
145 } | 153 } |
146 | 154 |
147 ResourceProvider::Resource::Resource( | 155 ResourceProvider::Resource::Resource( |
148 uint8_t* pixels, | 156 uint8_t* pixels, |
149 gfx::Size size, | 157 gfx::Size size, |
150 GLenum format, | |
151 GLenum filter, | 158 GLenum filter, |
152 GLint wrap_mode) | 159 GLint wrap_mode) |
153 : gl_id(0), | 160 : gl_id(0), |
154 gl_pixel_buffer_id(0), | 161 gl_pixel_buffer_id(0), |
155 gl_upload_query_id(0), | 162 gl_upload_query_id(0), |
156 pixels(pixels), | 163 pixels(pixels), |
157 pixel_buffer(NULL), | 164 pixel_buffer(NULL), |
158 lock_for_read_count(0), | 165 lock_for_read_count(0), |
159 imported_count(0), | 166 imported_count(0), |
160 exported_count(0), | 167 exported_count(0), |
161 locked_for_write(false), | 168 locked_for_write(false), |
162 external(false), | 169 external(false), |
163 marked_for_deletion(false), | 170 marked_for_deletion(false), |
164 pending_set_pixels(false), | 171 pending_set_pixels(false), |
165 set_pixels_completion_forced(false), | 172 set_pixels_completion_forced(false), |
166 allocated(false), | 173 allocated(false), |
167 enable_read_lock_fences(false), | 174 enable_read_lock_fences(false), |
168 read_lock_fence(NULL), | 175 read_lock_fence(NULL), |
169 size(size), | 176 size(size), |
170 format(format), | |
171 original_filter(filter), | 177 original_filter(filter), |
172 filter(filter), | 178 filter(filter), |
173 target(0), | 179 target(0), |
174 image_id(0), | 180 image_id(0), |
175 texture_pool(0), | 181 texture_pool(0), |
176 wrap_mode(wrap_mode), | 182 wrap_mode(wrap_mode), |
177 hint(TextureUsageAny), | 183 hint(TextureUsageAny), |
178 type(Bitmap) { | 184 type(Bitmap), |
| 185 format(RGBA_8888) { |
179 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); | 186 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); |
180 } | 187 } |
181 | 188 |
182 ResourceProvider::Child::Child() {} | 189 ResourceProvider::Child::Child() {} |
183 | 190 |
184 ResourceProvider::Child::~Child() {} | 191 ResourceProvider::Child::~Child() {} |
185 | 192 |
186 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 193 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
187 OutputSurface* output_surface, | 194 OutputSurface* output_surface, |
188 int highp_threshold_min) { | 195 int highp_threshold_min, |
| 196 bool use_rgba_4444_texture_format) { |
189 scoped_ptr<ResourceProvider> resource_provider( | 197 scoped_ptr<ResourceProvider> resource_provider( |
190 new ResourceProvider(output_surface, highp_threshold_min)); | 198 new ResourceProvider(output_surface, |
| 199 highp_threshold_min, |
| 200 use_rgba_4444_texture_format)); |
191 | 201 |
192 bool success = false; | 202 bool success = false; |
193 if (resource_provider->Context3d()) { | 203 if (resource_provider->Context3d()) { |
194 success = resource_provider->InitializeGL(); | 204 success = resource_provider->InitializeGL(); |
195 } else { | 205 } else { |
196 resource_provider->InitializeSoftware(); | 206 resource_provider->InitializeSoftware(); |
197 success = true; | 207 success = true; |
198 } | 208 } |
199 | 209 |
200 if (!success) | 210 if (!success) |
201 return scoped_ptr<ResourceProvider>(); | 211 return scoped_ptr<ResourceProvider>(); |
202 | 212 |
203 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); | 213 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); |
204 return resource_provider.Pass(); | 214 return resource_provider.Pass(); |
205 } | 215 } |
206 | 216 |
207 ResourceProvider::~ResourceProvider() { | 217 ResourceProvider::~ResourceProvider() { |
208 while (!resources_.empty()) | 218 while (!resources_.empty()) |
209 DeleteResourceInternal(resources_.begin(), ForShutdown); | 219 DeleteResourceInternal(resources_.begin(), ForShutdown); |
210 | 220 |
211 CleanUpGLIfNeeded(); | 221 CleanUpGLIfNeeded(); |
212 } | 222 } |
213 | 223 |
214 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 224 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
215 Resource* resource = GetResource(id); | 225 Resource* resource = GetResource(id); |
216 return resource->lock_for_read_count > 0 || resource->exported_count > 0; | 226 return resource->lock_for_read_count > 0 || resource->exported_count > 0; |
217 } | 227 } |
218 | 228 |
219 ResourceProvider::ResourceId ResourceProvider::CreateResource( | 229 ResourceProvider::ResourceId ResourceProvider::CreateResource( |
220 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 230 gfx::Size size, |
| 231 GLint wrap_mode, |
| 232 TextureUsageHint hint, |
| 233 ResourceFormat format) { |
221 DCHECK(!size.IsEmpty()); | 234 DCHECK(!size.IsEmpty()); |
222 switch (default_resource_type_) { | 235 switch (default_resource_type_) { |
223 case GLTexture: | 236 case GLTexture: |
224 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, | 237 return CreateGLTexture(size, |
225 wrap_mode, hint); | 238 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, |
| 239 wrap_mode, |
| 240 hint, |
| 241 format); |
226 case Bitmap: | 242 case Bitmap: |
227 // The only wrap_mode currently implemented in software mode is | 243 DCHECK_EQ(RGBA_8888, format); |
228 // GL_CLAMP_TO_EDGE. | |
229 // http://crbug.com/284796 | |
230 DCHECK(format == GL_RGBA); | |
231 return CreateBitmap(size); | 244 return CreateBitmap(size); |
232 case InvalidType: | 245 case InvalidType: |
233 break; | 246 break; |
234 } | 247 } |
235 | 248 |
236 LOG(FATAL) << "Invalid default resource type."; | 249 LOG(FATAL) << "Invalid default resource type."; |
237 return 0; | 250 return 0; |
238 } | 251 } |
239 | 252 |
240 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( | 253 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( |
241 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { | 254 gfx::Size size, |
| 255 GLint wrap_mode, |
| 256 TextureUsageHint hint, |
| 257 ResourceFormat format) { |
242 DCHECK(!size.IsEmpty()); | 258 DCHECK(!size.IsEmpty()); |
243 switch (default_resource_type_) { | 259 switch (default_resource_type_) { |
244 case GLTexture: | 260 case GLTexture: |
245 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, | 261 return CreateGLTexture(size, |
246 wrap_mode, hint); | 262 GL_TEXTURE_POOL_MANAGED_CHROMIUM, |
| 263 wrap_mode, |
| 264 hint, |
| 265 format); |
247 case Bitmap: | 266 case Bitmap: |
248 DCHECK(format == GL_RGBA); | 267 DCHECK_EQ(RGBA_8888, format); |
249 return CreateBitmap(size); | 268 return CreateBitmap(size); |
250 case InvalidType: | 269 case InvalidType: |
251 break; | 270 break; |
252 } | 271 } |
253 | 272 |
254 LOG(FATAL) << "Invalid default resource type."; | 273 LOG(FATAL) << "Invalid default resource type."; |
255 return 0; | 274 return 0; |
256 } | 275 } |
257 | 276 |
258 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( | 277 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( |
259 gfx::Size size, | 278 gfx::Size size, |
260 GLenum format, | |
261 GLenum texture_pool, | 279 GLenum texture_pool, |
262 GLint wrap_mode, | 280 GLint wrap_mode, |
263 TextureUsageHint hint) { | 281 TextureUsageHint hint, |
| 282 ResourceFormat format) { |
264 DCHECK_LE(size.width(), max_texture_size_); | 283 DCHECK_LE(size.width(), max_texture_size_); |
265 DCHECK_LE(size.height(), max_texture_size_); | 284 DCHECK_LE(size.height(), max_texture_size_); |
266 DCHECK(thread_checker_.CalledOnValidThread()); | 285 DCHECK(thread_checker_.CalledOnValidThread()); |
267 | 286 |
268 ResourceId id = next_id_++; | 287 ResourceId id = next_id_++; |
269 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); | 288 Resource resource(0, size, GL_LINEAR, texture_pool, wrap_mode, hint, format); |
270 resource.allocated = false; | 289 resource.allocated = false; |
271 resources_[id] = resource; | 290 resources_[id] = resource; |
272 return id; | 291 return id; |
273 } | 292 } |
274 | 293 |
275 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { | 294 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { |
276 DCHECK(thread_checker_.CalledOnValidThread()); | 295 DCHECK(thread_checker_.CalledOnValidThread()); |
277 | 296 |
278 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; | 297 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; |
279 | 298 |
280 ResourceId id = next_id_++; | 299 ResourceId id = next_id_++; |
281 Resource resource(pixels, size, GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 300 Resource resource(pixels, size, GL_LINEAR, GL_CLAMP_TO_EDGE); |
282 resource.allocated = true; | 301 resource.allocated = true; |
283 resources_[id] = resource; | 302 resources_[id] = resource; |
284 return id; | 303 return id; |
285 } | 304 } |
286 | 305 |
287 ResourceProvider::ResourceId | 306 ResourceProvider::ResourceId |
288 ResourceProvider::CreateResourceFromExternalTexture( | 307 ResourceProvider::CreateResourceFromExternalTexture( |
289 unsigned texture_target, | 308 unsigned texture_target, |
290 unsigned texture_id) { | 309 unsigned texture_id) { |
291 DCHECK(thread_checker_.CalledOnValidThread()); | 310 DCHECK(thread_checker_.CalledOnValidThread()); |
292 | 311 |
293 WebGraphicsContext3D* context3d = Context3d(); | 312 WebGraphicsContext3D* context3d = Context3d(); |
294 DCHECK(context3d); | 313 DCHECK(context3d); |
295 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); | 314 GLC(context3d, context3d->bindTexture(texture_target, texture_id)); |
296 GLC(context3d, context3d->texParameteri( | 315 GLC(context3d, context3d->texParameteri( |
297 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 316 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
298 GLC(context3d, context3d->texParameteri( | 317 GLC(context3d, context3d->texParameteri( |
299 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 318 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
300 GLC(context3d, context3d->texParameteri( | 319 GLC(context3d, context3d->texParameteri( |
301 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); | 320 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); |
302 GLC(context3d, context3d->texParameteri( | 321 GLC(context3d, context3d->texParameteri( |
303 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); | 322 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); |
304 | 323 |
305 ResourceId id = next_id_++; | 324 ResourceId id = next_id_++; |
306 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 325 Resource resource(texture_id, |
307 TextureUsageAny); | 326 gfx::Size(), |
| 327 GL_LINEAR, |
| 328 0, |
| 329 GL_CLAMP_TO_EDGE, |
| 330 TextureUsageAny, |
| 331 RGBA_8888); |
308 resource.external = true; | 332 resource.external = true; |
309 resource.allocated = true; | 333 resource.allocated = true; |
310 resources_[id] = resource; | 334 resources_[id] = resource; |
311 return id; | 335 return id; |
312 } | 336 } |
313 | 337 |
314 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 338 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
315 const TextureMailbox& mailbox, | 339 const TextureMailbox& mailbox, |
316 scoped_ptr<SingleReleaseCallback> release_callback) { | 340 scoped_ptr<SingleReleaseCallback> release_callback) { |
317 DCHECK(thread_checker_.CalledOnValidThread()); | 341 DCHECK(thread_checker_.CalledOnValidThread()); |
318 // Just store the information. Mailbox will be consumed in LockForRead(). | 342 // Just store the information. Mailbox will be consumed in LockForRead(). |
319 ResourceId id = next_id_++; | 343 ResourceId id = next_id_++; |
320 DCHECK(mailbox.IsValid()); | 344 DCHECK(mailbox.IsValid()); |
321 Resource& resource = resources_[id]; | 345 Resource& resource = resources_[id]; |
322 if (mailbox.IsTexture()) { | 346 if (mailbox.IsTexture()) { |
323 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, | 347 resource = Resource(0, |
324 TextureUsageAny); | 348 gfx::Size(), |
| 349 GL_LINEAR, |
| 350 0, |
| 351 GL_CLAMP_TO_EDGE, |
| 352 TextureUsageAny, |
| 353 RGBA_8888); |
325 } else { | 354 } else { |
326 DCHECK(mailbox.IsSharedMemory()); | 355 DCHECK(mailbox.IsSharedMemory()); |
327 base::SharedMemory* shared_memory = mailbox.shared_memory(); | 356 base::SharedMemory* shared_memory = mailbox.shared_memory(); |
328 DCHECK(shared_memory->memory()); | 357 DCHECK(shared_memory->memory()); |
329 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); | 358 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); |
330 resource = Resource(pixels, mailbox.shared_memory_size(), | 359 resource = Resource( |
331 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); | 360 pixels, mailbox.shared_memory_size(), GL_LINEAR, GL_CLAMP_TO_EDGE); |
332 } | 361 } |
333 resource.external = true; | 362 resource.external = true; |
334 resource.allocated = true; | 363 resource.allocated = true; |
335 resource.mailbox = mailbox; | 364 resource.mailbox = mailbox; |
336 resource.release_callback = | 365 resource.release_callback = |
337 base::Bind(&SingleReleaseCallback::Run, | 366 base::Bind(&SingleReleaseCallback::Run, |
338 base::Owned(release_callback.release())); | 367 base::Owned(release_callback.release())); |
339 return id; | 368 return id; |
340 } | 369 } |
341 | 370 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 texture_uploader_->Upload(image, | 470 texture_uploader_->Upload(image, |
442 image_rect, | 471 image_rect, |
443 source_rect, | 472 source_rect, |
444 dest_offset, | 473 dest_offset, |
445 resource->format, | 474 resource->format, |
446 resource->size); | 475 resource->size); |
447 } | 476 } |
448 | 477 |
449 if (resource->pixels) { | 478 if (resource->pixels) { |
450 DCHECK(resource->allocated); | 479 DCHECK(resource->allocated); |
451 DCHECK(resource->format == GL_RGBA); | 480 DCHECK_EQ(RGBA_8888, resource->format); |
452 SkBitmap src_full; | 481 SkBitmap src_full; |
453 src_full.setConfig( | 482 src_full.setConfig( |
454 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); | 483 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); |
455 src_full.setPixels(const_cast<uint8_t*>(image)); | 484 src_full.setPixels(const_cast<uint8_t*>(image)); |
456 SkBitmap src_subset; | 485 SkBitmap src_subset; |
457 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), | 486 SkIRect sk_source_rect = SkIRect::MakeXYWH(source_rect.x(), |
458 source_rect.y(), | 487 source_rect.y(), |
459 source_rect.width(), | 488 source_rect.width(), |
460 source_rect.height()); | 489 source_rect.height()); |
461 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); | 490 sk_source_rect.offset(-image_rect.x(), -image_rect.y()); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 DCHECK(texture_id_); | 694 DCHECK(texture_id_); |
666 } | 695 } |
667 | 696 |
668 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 697 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
669 resource_provider_->UnlockForWrite(resource_id_); | 698 resource_provider_->UnlockForWrite(resource_id_); |
670 } | 699 } |
671 | 700 |
672 void ResourceProvider::PopulateSkBitmapWithResource( | 701 void ResourceProvider::PopulateSkBitmapWithResource( |
673 SkBitmap* sk_bitmap, const Resource* resource) { | 702 SkBitmap* sk_bitmap, const Resource* resource) { |
674 DCHECK(resource->pixels); | 703 DCHECK(resource->pixels); |
675 DCHECK(resource->format == GL_RGBA); | 704 DCHECK_EQ(RGBA_8888, resource->format); |
676 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, | 705 sk_bitmap->setConfig(SkBitmap::kARGB_8888_Config, |
677 resource->size.width(), | 706 resource->size.width(), |
678 resource->size.height()); | 707 resource->size.height()); |
679 sk_bitmap->setPixels(resource->pixels); | 708 sk_bitmap->setPixels(resource->pixels); |
680 } | 709 } |
681 | 710 |
682 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 711 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
683 ResourceProvider* resource_provider, | 712 ResourceProvider* resource_provider, |
684 ResourceProvider::ResourceId resource_id) | 713 ResourceProvider::ResourceId resource_id) |
685 : resource_provider_(resource_provider), | 714 : resource_provider_(resource_provider), |
(...skipping 14 matching lines...) Expand all Loading... |
700 ResourceProvider::PopulateSkBitmapWithResource( | 729 ResourceProvider::PopulateSkBitmapWithResource( |
701 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); | 730 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); |
702 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); | 731 sk_canvas_.reset(new SkCanvas(sk_bitmap_)); |
703 } | 732 } |
704 | 733 |
705 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 734 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
706 resource_provider_->UnlockForWrite(resource_id_); | 735 resource_provider_->UnlockForWrite(resource_id_); |
707 } | 736 } |
708 | 737 |
709 ResourceProvider::ResourceProvider(OutputSurface* output_surface, | 738 ResourceProvider::ResourceProvider(OutputSurface* output_surface, |
710 int highp_threshold_min) | 739 int highp_threshold_min, |
| 740 bool use_rgba_4444_texture_format) |
711 : output_surface_(output_surface), | 741 : output_surface_(output_surface), |
712 lost_output_surface_(false), | 742 lost_output_surface_(false), |
713 highp_threshold_min_(highp_threshold_min), | 743 highp_threshold_min_(highp_threshold_min), |
714 next_id_(1), | 744 next_id_(1), |
715 next_child_(1), | 745 next_child_(1), |
716 default_resource_type_(InvalidType), | 746 default_resource_type_(InvalidType), |
717 use_texture_storage_ext_(false), | 747 use_texture_storage_ext_(false), |
718 use_texture_usage_hint_(false), | 748 use_texture_usage_hint_(false), |
719 use_shallow_flush_(false), | 749 use_shallow_flush_(false), |
720 max_texture_size_(0), | 750 max_texture_size_(0), |
721 best_texture_format_(0) { | 751 best_texture_format_(RGBA_8888), |
| 752 use_rgba_4444_texture_format_(use_rgba_4444_texture_format) { |
722 DCHECK(output_surface_->HasClient()); | 753 DCHECK(output_surface_->HasClient()); |
723 } | 754 } |
724 | 755 |
725 void ResourceProvider::InitializeSoftware() { | 756 void ResourceProvider::InitializeSoftware() { |
726 DCHECK(thread_checker_.CalledOnValidThread()); | 757 DCHECK(thread_checker_.CalledOnValidThread()); |
727 DCHECK_NE(Bitmap, default_resource_type_); | 758 DCHECK_NE(Bitmap, default_resource_type_); |
728 | 759 |
729 CleanUpGLIfNeeded(); | 760 CleanUpGLIfNeeded(); |
730 | 761 |
731 default_resource_type_ = Bitmap; | 762 default_resource_type_ = Bitmap; |
732 max_texture_size_ = INT_MAX / 2; | 763 max_texture_size_ = INT_MAX / 2; |
733 best_texture_format_ = GL_RGBA; | 764 best_texture_format_ = RGBA_8888; |
734 } | 765 } |
735 | 766 |
736 bool ResourceProvider::InitializeGL() { | 767 bool ResourceProvider::InitializeGL() { |
737 DCHECK(thread_checker_.CalledOnValidThread()); | 768 DCHECK(thread_checker_.CalledOnValidThread()); |
738 DCHECK(!texture_uploader_); | 769 DCHECK(!texture_uploader_); |
739 DCHECK_NE(GLTexture, default_resource_type_); | 770 DCHECK_NE(GLTexture, default_resource_type_); |
740 | 771 |
741 WebGraphicsContext3D* context3d = Context3d(); | 772 WebGraphicsContext3D* context3d = Context3d(); |
742 DCHECK(context3d); | 773 DCHECK(context3d); |
743 | 774 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 // deadlocks and/or security issues. The caller is responsible for | 955 // deadlocks and/or security issues. The caller is responsible for |
925 // waiting asynchronously, and resetting sync_point before calling this. | 956 // waiting asynchronously, and resetting sync_point before calling this. |
926 // However if the parent is a renderer (e.g. browser tag), it may be ok | 957 // However if the parent is a renderer (e.g. browser tag), it may be ok |
927 // (and is simpler) to wait. | 958 // (and is simpler) to wait. |
928 if (it->sync_point) | 959 if (it->sync_point) |
929 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 960 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
930 GLC(context3d, texture_id = context3d->createTexture()); | 961 GLC(context3d, texture_id = context3d->createTexture()); |
931 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); | 962 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); |
932 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 963 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
933 it->mailbox.name)); | 964 it->mailbox.name)); |
| 965 |
934 ResourceId id = next_id_++; | 966 ResourceId id = next_id_++; |
935 Resource resource( | 967 Resource resource( |
936 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, | 968 texture_id, |
937 TextureUsageAny); | 969 it->size, |
| 970 it->filter, |
| 971 0, |
| 972 GL_CLAMP_TO_EDGE, |
| 973 TextureUsageAny, |
| 974 it->format); |
938 resource.mailbox.SetName(it->mailbox); | 975 resource.mailbox.SetName(it->mailbox); |
939 // Don't allocate a texture for a child. | 976 // Don't allocate a texture for a child. |
940 resource.allocated = true; | 977 resource.allocated = true; |
941 resource.imported_count = 1; | 978 resource.imported_count = 1; |
942 resources_[id] = resource; | 979 resources_[id] = resource; |
943 child_info.parent_to_child_map[id] = it->id; | 980 child_info.parent_to_child_map[id] = it->id; |
944 child_info.child_to_parent_map[it->id] = id; | 981 child_info.child_to_parent_map[it->id] = id; |
945 } | 982 } |
946 } | 983 } |
947 | 984 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 DCHECK(!resource->image_id); | 1053 DCHECK(!resource->image_id); |
1017 | 1054 |
1018 if (resource->type == GLTexture) { | 1055 if (resource->type == GLTexture) { |
1019 WebGraphicsContext3D* context3d = Context3d(); | 1056 WebGraphicsContext3D* context3d = Context3d(); |
1020 DCHECK(context3d); | 1057 DCHECK(context3d); |
1021 if (!resource->gl_pixel_buffer_id) | 1058 if (!resource->gl_pixel_buffer_id) |
1022 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 1059 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
1023 context3d->bindBuffer( | 1060 context3d->bindBuffer( |
1024 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1061 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1025 resource->gl_pixel_buffer_id); | 1062 resource->gl_pixel_buffer_id); |
| 1063 unsigned bytes_per_pixel = BytesPerPixel(resource->format); |
1026 context3d->bufferData( | 1064 context3d->bufferData( |
1027 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1065 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1028 4 * resource->size.GetArea(), | 1066 resource->size.height() * RoundUp(bytes_per_pixel |
| 1067 * resource->size.width(), 4u), |
1029 NULL, | 1068 NULL, |
1030 GL_DYNAMIC_DRAW); | 1069 GL_DYNAMIC_DRAW); |
1031 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1070 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1032 } | 1071 } |
1033 | 1072 |
1034 if (resource->pixels) { | 1073 if (resource->pixels) { |
1035 if (resource->pixel_buffer) | 1074 if (resource->pixel_buffer) |
1036 return; | 1075 return; |
1037 | 1076 |
1038 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; | 1077 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1233 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1195 context3d->bindBuffer( | 1234 context3d->bindBuffer( |
1196 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1235 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1197 resource->gl_pixel_buffer_id); | 1236 resource->gl_pixel_buffer_id); |
1198 if (!resource->gl_upload_query_id) | 1237 if (!resource->gl_upload_query_id) |
1199 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1238 resource->gl_upload_query_id = context3d->createQueryEXT(); |
1200 context3d->beginQueryEXT( | 1239 context3d->beginQueryEXT( |
1201 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, | 1240 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, |
1202 resource->gl_upload_query_id); | 1241 resource->gl_upload_query_id); |
1203 if (allocate) { | 1242 if (allocate) { |
1204 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1243 context3d->asyncTexImage2DCHROMIUM( |
1205 0, /* level */ | 1244 GL_TEXTURE_2D, |
1206 resource->format, | 1245 0, /* level */ |
1207 resource->size.width(), | 1246 GetGLInternalFormat(resource->format), |
1208 resource->size.height(), | 1247 resource->size.width(), |
1209 0, /* border */ | 1248 resource->size.height(), |
1210 resource->format, | 1249 0, /* border */ |
1211 GL_UNSIGNED_BYTE, | 1250 GetGLDataFormat(resource->format), |
1212 NULL); | 1251 GetGLDataType(resource->format), |
| 1252 NULL); |
1213 } else { | 1253 } else { |
1214 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1254 context3d->asyncTexSubImage2DCHROMIUM( |
1215 0, /* level */ | 1255 GL_TEXTURE_2D, |
1216 0, /* x */ | 1256 0, /* level */ |
1217 0, /* y */ | 1257 0, /* x */ |
1218 resource->size.width(), | 1258 0, /* y */ |
1219 resource->size.height(), | 1259 resource->size.width(), |
1220 resource->format, | 1260 resource->size.height(), |
1221 GL_UNSIGNED_BYTE, | 1261 GetGLDataFormat(resource->format), |
1222 NULL); | 1262 GetGLDataType(resource->format), |
| 1263 NULL); |
1223 } | 1264 } |
1224 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); | 1265 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); |
1225 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1266 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1226 } | 1267 } |
1227 | 1268 |
1228 if (resource->pixels) { | 1269 if (resource->pixels) { |
1229 DCHECK(!resource->mailbox.IsValid()); | 1270 DCHECK(!resource->mailbox.IsValid()); |
1230 DCHECK(resource->pixel_buffer); | 1271 DCHECK(resource->pixel_buffer); |
1231 DCHECK(resource->format == GL_RGBA); | 1272 DCHECK_EQ(RGBA_8888, resource->format); |
1232 | 1273 |
1233 std::swap(resource->pixels, resource->pixel_buffer); | 1274 std::swap(resource->pixels, resource->pixel_buffer); |
1234 delete[] resource->pixel_buffer; | 1275 delete[] resource->pixel_buffer; |
1235 resource->pixel_buffer = NULL; | 1276 resource->pixel_buffer = NULL; |
1236 } | 1277 } |
1237 | 1278 |
1238 resource->pending_set_pixels = true; | 1279 resource->pending_set_pixels = true; |
1239 resource->set_pixels_completion_forced = false; | 1280 resource->set_pixels_completion_forced = false; |
1240 } | 1281 } |
1241 | 1282 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 void ResourceProvider::LazyAllocate(Resource* resource) { | 1368 void ResourceProvider::LazyAllocate(Resource* resource) { |
1328 DCHECK(resource); | 1369 DCHECK(resource); |
1329 LazyCreate(resource); | 1370 LazyCreate(resource); |
1330 | 1371 |
1331 DCHECK(resource->gl_id || resource->allocated); | 1372 DCHECK(resource->gl_id || resource->allocated); |
1332 if (resource->allocated || !resource->gl_id) | 1373 if (resource->allocated || !resource->gl_id) |
1333 return; | 1374 return; |
1334 resource->allocated = true; | 1375 resource->allocated = true; |
1335 WebGraphicsContext3D* context3d = Context3d(); | 1376 WebGraphicsContext3D* context3d = Context3d(); |
1336 gfx::Size& size = resource->size; | 1377 gfx::Size& size = resource->size; |
1337 GLenum format = resource->format; | 1378 ResourceFormat format = resource->format; |
1338 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1379 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1339 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1380 if (use_texture_storage_ext_ && IsFormatSupportedForStorage(format)) { |
1340 GLenum storage_format = TextureToStorageFormat(format); | 1381 GLenum storage_format = TextureToStorageFormat(format); |
1341 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1382 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
1342 1, | 1383 1, |
1343 storage_format, | 1384 storage_format, |
1344 size.width(), | 1385 size.width(), |
1345 size.height())); | 1386 size.height())); |
1346 } else { | 1387 } else { |
1347 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1388 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
1348 0, | 1389 0, |
1349 format, | 1390 GetGLInternalFormat(format), |
1350 size.width(), | 1391 size.width(), |
1351 size.height(), | 1392 size.height(), |
1352 0, | 1393 0, |
1353 format, | 1394 GetGLDataFormat(format), |
1354 GL_UNSIGNED_BYTE, | 1395 GetGLDataType(format), |
1355 NULL)); | 1396 NULL)); |
1356 } | 1397 } |
1357 } | 1398 } |
1358 | 1399 |
1359 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1400 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1360 bool enable) { | 1401 bool enable) { |
1361 Resource* resource = GetResource(id); | 1402 Resource* resource = GetResource(id); |
1362 resource->enable_read_lock_fences = enable; | 1403 resource->enable_read_lock_fences = enable; |
1363 } | 1404 } |
1364 | 1405 |
1365 void ResourceProvider::AcquireImage(ResourceId id) { | 1406 void ResourceProvider::AcquireImage(ResourceId id) { |
1366 Resource* resource = GetResource(id); | 1407 Resource* resource = GetResource(id); |
1367 DCHECK(!resource->external); | 1408 DCHECK(!resource->external); |
1368 DCHECK_EQ(resource->exported_count, 0); | 1409 DCHECK_EQ(resource->exported_count, 0); |
1369 | 1410 |
1370 if (resource->type != GLTexture) | 1411 if (resource->type != GLTexture) |
1371 return; | 1412 return; |
1372 | 1413 |
1373 if (resource->image_id) | 1414 if (resource->image_id) |
1374 return; | 1415 return; |
1375 | 1416 |
1376 resource->allocated = true; | 1417 resource->allocated = true; |
1377 WebGraphicsContext3D* context3d = Context3d(); | 1418 WebGraphicsContext3D* context3d = Context3d(); |
1378 DCHECK(context3d); | 1419 DCHECK(context3d); |
1379 DCHECK_EQ(static_cast<GLenum>(GL_RGBA), resource->format); | 1420 DCHECK_EQ(RGBA_8888, resource->format); |
1380 resource->image_id = context3d->createImageCHROMIUM( | 1421 resource->image_id = context3d->createImageCHROMIUM( |
1381 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | 1422 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
1382 DCHECK(resource->image_id); | 1423 DCHECK(resource->image_id); |
1383 } | 1424 } |
1384 | 1425 |
1385 void ResourceProvider::ReleaseImage(ResourceId id) { | 1426 void ResourceProvider::ReleaseImage(ResourceId id) { |
1386 Resource* resource = GetResource(id); | 1427 Resource* resource = GetResource(id); |
1387 DCHECK(!resource->external); | 1428 DCHECK(!resource->external); |
1388 DCHECK_EQ(resource->exported_count, 0); | 1429 DCHECK_EQ(resource->exported_count, 0); |
1389 | 1430 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 GLint active_unit = 0; | 1490 GLint active_unit = 0; |
1450 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); | 1491 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); |
1451 return active_unit; | 1492 return active_unit; |
1452 } | 1493 } |
1453 | 1494 |
1454 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { | 1495 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { |
1455 ContextProvider* context_provider = output_surface_->context_provider(); | 1496 ContextProvider* context_provider = output_surface_->context_provider(); |
1456 return context_provider ? context_provider->Context3d() : NULL; | 1497 return context_provider ? context_provider->Context3d() : NULL; |
1457 } | 1498 } |
1458 | 1499 |
| 1500 size_t ResourceProvider::BytesPerPixel(ResourceFormat format) { |
| 1501 size_t components_per_pixel = 0; |
| 1502 switch (format) { |
| 1503 case RGBA_8888: |
| 1504 case RGBA_4444: |
| 1505 case BGRA_8888: |
| 1506 components_per_pixel = 4; |
| 1507 break; |
| 1508 case LUMINANCE_8: |
| 1509 components_per_pixel = 1; |
| 1510 break; |
| 1511 } |
| 1512 size_t bits_per_component = 0; |
| 1513 switch (format) { |
| 1514 case RGBA_8888: |
| 1515 case BGRA_8888: |
| 1516 case LUMINANCE_8: |
| 1517 bits_per_component = 8; |
| 1518 break; |
| 1519 case RGBA_4444: |
| 1520 bits_per_component = 4; |
| 1521 break; |
| 1522 } |
| 1523 const size_t kBitsPerByte = 8; |
| 1524 return (components_per_pixel * bits_per_component) / kBitsPerByte; |
| 1525 } |
| 1526 |
| 1527 GLenum ResourceProvider::GetGLDataType(ResourceFormat format) { |
| 1528 switch (format) { |
| 1529 case RGBA_4444: |
| 1530 return GL_UNSIGNED_SHORT_4_4_4_4; |
| 1531 case RGBA_8888: |
| 1532 case BGRA_8888: |
| 1533 case LUMINANCE_8: |
| 1534 return GL_UNSIGNED_BYTE; |
| 1535 } |
| 1536 NOTREACHED(); |
| 1537 return GL_UNSIGNED_BYTE; |
| 1538 } |
| 1539 |
| 1540 GLenum ResourceProvider::GetGLDataFormat(ResourceFormat format) { |
| 1541 switch (format) { |
| 1542 case RGBA_8888: |
| 1543 case RGBA_4444: |
| 1544 return GL_RGBA; |
| 1545 case BGRA_8888: |
| 1546 return GL_BGRA_EXT; |
| 1547 case LUMINANCE_8: |
| 1548 return GL_LUMINANCE; |
| 1549 } |
| 1550 NOTREACHED(); |
| 1551 return GL_RGBA; |
| 1552 } |
| 1553 |
| 1554 GLenum ResourceProvider::GetGLInternalFormat(ResourceFormat format) { |
| 1555 return GetGLDataFormat(format); |
| 1556 } |
| 1557 |
1459 } // namespace cc | 1558 } // namespace cc |
OLD | NEW |