OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 #include "platform/graphics/gpu/DrawingBuffer.h" | 31 #include "platform/graphics/gpu/DrawingBuffer.h" |
32 | 32 |
33 #include <algorithm> | 33 #include <algorithm> |
34 #include <memory> | 34 #include <memory> |
35 #include "cc/resources/shared_bitmap.h" | 35 #include "cc/resources/shared_bitmap.h" |
36 #include "gpu/GLES2/gl2extchromium.h" | 36 #include "gpu/GLES2/gl2extchromium.h" |
37 #include "gpu/command_buffer/client/gles2_interface.h" | 37 #include "gpu/command_buffer/client/gles2_interface.h" |
38 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 38 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
39 #include "gpu/command_buffer/common/capabilities.h" | 39 #include "gpu/command_buffer/common/capabilities.h" |
40 #include "gpu/command_buffer/common/gpu_memory_buffer_support.h" | |
41 #include "platform/RuntimeEnabledFeatures.h" | 40 #include "platform/RuntimeEnabledFeatures.h" |
42 #include "platform/graphics/AcceleratedStaticBitmapImage.h" | 41 #include "platform/graphics/AcceleratedStaticBitmapImage.h" |
43 #include "platform/graphics/GraphicsLayer.h" | 42 #include "platform/graphics/GraphicsLayer.h" |
44 #include "platform/graphics/ImageBuffer.h" | 43 #include "platform/graphics/ImageBuffer.h" |
45 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h" | 44 #include "platform/graphics/WebGraphicsContext3DProviderWrapper.h" |
46 #include "platform/graphics/gpu/Extensions3DUtil.h" | 45 #include "platform/graphics/gpu/Extensions3DUtil.h" |
47 #include "platform/instrumentation/tracing/TraceEvent.h" | 46 #include "platform/instrumentation/tracing/TraceEvent.h" |
48 #include "platform/wtf/CheckedNumeric.h" | 47 #include "platform/wtf/CheckedNumeric.h" |
49 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" | 48 #include "platform/wtf/typed_arrays/ArrayBufferContents.h" |
50 #include "public/platform/Platform.h" | 49 #include "public/platform/Platform.h" |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 | 524 |
526 DrawingBuffer::ColorBufferParameters | 525 DrawingBuffer::ColorBufferParameters |
527 DrawingBuffer::GpuMemoryBufferColorBufferParameters() { | 526 DrawingBuffer::GpuMemoryBufferColorBufferParameters() { |
528 #if OS(MACOSX) | 527 #if OS(MACOSX) |
529 // A CHROMIUM_image backed texture requires a specialized set of parameters | 528 // A CHROMIUM_image backed texture requires a specialized set of parameters |
530 // on OSX. | 529 // on OSX. |
531 ColorBufferParameters parameters; | 530 ColorBufferParameters parameters; |
532 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; | 531 parameters.target = GC3D_TEXTURE_RECTANGLE_ARB; |
533 | 532 |
534 if (want_alpha_channel_) { | 533 if (want_alpha_channel_) { |
535 parameters.creation_internal_color_format = GL_RGBA; | 534 parameters.allocate_alpha_channel = true; |
536 parameters.internal_color_format = GL_RGBA; | |
537 } else if (ContextProvider() | 535 } else if (ContextProvider() |
538 ->GetCapabilities() | 536 ->GetCapabilities() |
539 .chromium_image_rgb_emulation) { | 537 .chromium_image_rgb_emulation) { |
540 parameters.creation_internal_color_format = GL_RGB; | 538 parameters.allocate_alpha_channel = false; |
541 parameters.internal_color_format = GL_RGBA; | |
542 } else { | 539 } else { |
543 GLenum format = | 540 parameters.allocate_alpha_channel = |
544 DefaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; | 541 DefaultBufferRequiresAlphaChannelToBePreserved(); |
545 parameters.creation_internal_color_format = format; | |
546 parameters.internal_color_format = format; | |
547 } | 542 } |
548 | |
549 // Unused when CHROMIUM_image is being used. | |
550 parameters.color_format = 0; | |
551 return parameters; | 543 return parameters; |
552 #else | 544 #else |
553 return TextureColorBufferParameters(); | 545 return TextureColorBufferParameters(); |
554 #endif | 546 #endif |
555 } | 547 } |
556 | 548 |
557 DrawingBuffer::ColorBufferParameters | 549 DrawingBuffer::ColorBufferParameters |
558 DrawingBuffer::TextureColorBufferParameters() { | 550 DrawingBuffer::TextureColorBufferParameters() { |
559 ColorBufferParameters parameters; | 551 ColorBufferParameters parameters; |
560 parameters.target = GL_TEXTURE_2D; | 552 parameters.target = GL_TEXTURE_2D; |
561 if (want_alpha_channel_) { | 553 if (want_alpha_channel_) { |
562 parameters.internal_color_format = GL_RGBA; | 554 parameters.allocate_alpha_channel = true; |
563 parameters.creation_internal_color_format = GL_RGBA; | |
564 parameters.color_format = GL_RGBA; | |
565 } else if (ContextProvider() | 555 } else if (ContextProvider() |
566 ->GetCapabilities() | 556 ->GetCapabilities() |
567 .emulate_rgb_buffer_with_rgba) { | 557 .emulate_rgb_buffer_with_rgba) { |
568 parameters.internal_color_format = GL_RGBA; | 558 parameters.allocate_alpha_channel = true; |
569 parameters.creation_internal_color_format = GL_RGBA; | |
570 parameters.color_format = GL_RGBA; | |
571 } else { | 559 } else { |
572 GLenum format = | 560 parameters.allocate_alpha_channel = |
573 DefaultBufferRequiresAlphaChannelToBePreserved() ? GL_RGBA : GL_RGB; | 561 DefaultBufferRequiresAlphaChannelToBePreserved(); |
574 parameters.creation_internal_color_format = format; | |
575 parameters.internal_color_format = format; | |
576 parameters.color_format = format; | |
577 } | 562 } |
578 return parameters; | 563 return parameters; |
579 } | 564 } |
580 | 565 |
581 PassRefPtr<DrawingBuffer::ColorBuffer> | 566 PassRefPtr<DrawingBuffer::ColorBuffer> |
582 DrawingBuffer::CreateOrRecycleColorBuffer() { | 567 DrawingBuffer::CreateOrRecycleColorBuffer() { |
583 DCHECK(state_restorer_); | 568 DCHECK(state_restorer_); |
584 if (!recycled_color_buffer_queue_.IsEmpty()) { | 569 if (!recycled_color_buffer_queue_.IsEmpty()) { |
585 RefPtr<ColorBuffer> recycled = recycled_color_buffer_queue_.TakeLast(); | 570 RefPtr<ColorBuffer> recycled = recycled_color_buffer_queue_.TakeLast(); |
586 if (recycled->receive_sync_token.HasData()) | 571 if (recycled->receive_sync_token.HasData()) |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 | 1134 |
1150 // Select the Parameters for the texture object. Allocate the backing | 1135 // Select the Parameters for the texture object. Allocate the backing |
1151 // GpuMemoryBuffer and GLImage, if one is going to be used. | 1136 // GpuMemoryBuffer and GLImage, if one is going to be used. |
1152 ColorBufferParameters parameters; | 1137 ColorBufferParameters parameters; |
1153 GLuint image_id = 0; | 1138 GLuint image_id = 0; |
1154 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; | 1139 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer; |
1155 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = | 1140 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager = |
1156 Platform::Current()->GetGpuMemoryBufferManager(); | 1141 Platform::Current()->GetGpuMemoryBufferManager(); |
1157 if (ShouldUseChromiumImage() && gpu_memory_buffer_manager) { | 1142 if (ShouldUseChromiumImage() && gpu_memory_buffer_manager) { |
1158 parameters = GpuMemoryBufferColorBufferParameters(); | 1143 parameters = GpuMemoryBufferColorBufferParameters(); |
1159 gfx::BufferFormat buffer_format = gpu::DefaultBufferFormatForImageFormat( | 1144 gfx::BufferFormat buffer_format; |
1160 parameters.creation_internal_color_format); | 1145 GLenum gl_format = GL_NONE; |
| 1146 if (parameters.allocate_alpha_channel) { |
| 1147 buffer_format = gfx::BufferFormat::RGBA_8888; |
| 1148 gl_format = GL_RGBA; |
| 1149 } else { |
| 1150 buffer_format = gfx::BufferFormat::BGRX_8888; |
| 1151 gl_format = GL_RGB; |
| 1152 } |
1161 gpu_memory_buffer = gpu_memory_buffer_manager->CreateGpuMemoryBuffer( | 1153 gpu_memory_buffer = gpu_memory_buffer_manager->CreateGpuMemoryBuffer( |
1162 gfx::Size(size), buffer_format, gfx::BufferUsage::SCANOUT, | 1154 gfx::Size(size), buffer_format, gfx::BufferUsage::SCANOUT, |
1163 gpu::kNullSurfaceHandle); | 1155 gpu::kNullSurfaceHandle); |
1164 if (gpu_memory_buffer) { | 1156 if (gpu_memory_buffer) { |
1165 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) | 1157 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled()) |
1166 gpu_memory_buffer->SetColorSpaceForScanout(color_space_); | 1158 gpu_memory_buffer->SetColorSpaceForScanout(color_space_); |
1167 image_id = gl_->CreateImageCHROMIUM( | 1159 image_id = |
1168 gpu_memory_buffer->AsClientBuffer(), size.Width(), size.Height(), | 1160 gl_->CreateImageCHROMIUM(gpu_memory_buffer->AsClientBuffer(), |
1169 parameters.creation_internal_color_format); | 1161 size.Width(), size.Height(), gl_format); |
1170 if (!image_id) | 1162 if (!image_id) |
1171 gpu_memory_buffer.reset(); | 1163 gpu_memory_buffer.reset(); |
1172 } | 1164 } |
1173 } else { | 1165 } else { |
1174 parameters = TextureColorBufferParameters(); | 1166 parameters = TextureColorBufferParameters(); |
1175 } | 1167 } |
1176 | 1168 |
1177 // Allocate the texture for this object. | 1169 // Allocate the texture for this object. |
1178 GLuint texture_id = 0; | 1170 GLuint texture_id = 0; |
1179 { | 1171 { |
1180 gl_->GenTextures(1, &texture_id); | 1172 gl_->GenTextures(1, &texture_id); |
1181 gl_->BindTexture(parameters.target, texture_id); | 1173 gl_->BindTexture(parameters.target, texture_id); |
1182 gl_->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 1174 gl_->TexParameteri(parameters.target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
1183 gl_->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 1175 gl_->TexParameteri(parameters.target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
1184 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1176 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
1185 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1177 gl_->TexParameteri(parameters.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
1186 } | 1178 } |
1187 | 1179 |
1188 // If this is GpuMemoryBuffer-backed, then bind the texture to the | 1180 // If this is GpuMemoryBuffer-backed, then bind the texture to the |
1189 // GpuMemoryBuffer's GLImage. Otherwise, allocate ordinary texture storage. | 1181 // GpuMemoryBuffer's GLImage. Otherwise, allocate ordinary texture storage. |
1190 if (image_id) { | 1182 if (image_id) { |
1191 gl_->BindTexImage2DCHROMIUM(parameters.target, image_id); | 1183 gl_->BindTexImage2DCHROMIUM(parameters.target, image_id); |
1192 } else { | 1184 } else { |
1193 if (storage_texture_supported_) { | 1185 if (storage_texture_supported_) { |
1194 GLenum internal_storage_format = GL_NONE; | 1186 GLenum internal_storage_format = |
1195 if (parameters.creation_internal_color_format == GL_RGB) { | 1187 parameters.allocate_alpha_channel ? GL_RGBA8 : GL_RGB8; |
1196 internal_storage_format = GL_RGB8; | |
1197 } else if (parameters.creation_internal_color_format == GL_RGBA) { | |
1198 internal_storage_format = GL_RGBA8; | |
1199 } else { | |
1200 NOTREACHED(); | |
1201 } | |
1202 gl_->TexStorage2DEXT(GL_TEXTURE_2D, 1, internal_storage_format, | 1188 gl_->TexStorage2DEXT(GL_TEXTURE_2D, 1, internal_storage_format, |
1203 size.Width(), size.Height()); | 1189 size.Width(), size.Height()); |
1204 } else { | 1190 } else { |
1205 gl_->TexImage2D(parameters.target, 0, | 1191 GLenum gl_format = parameters.allocate_alpha_channel ? GL_RGBA : GL_RGB; |
1206 parameters.creation_internal_color_format, size.Width(), | 1192 gl_->TexImage2D(parameters.target, 0, gl_format, size.Width(), |
1207 size.Height(), 0, parameters.color_format, | 1193 size.Height(), 0, gl_format, GL_UNSIGNED_BYTE, 0); |
1208 GL_UNSIGNED_BYTE, 0); | |
1209 } | 1194 } |
1210 } | 1195 } |
1211 | 1196 |
1212 // Clear the alpha channel if this is RGB emulated. | 1197 // Clear the alpha channel if this is RGB emulated. |
1213 if (image_id && !want_alpha_channel_ && | 1198 if (image_id && !want_alpha_channel_ && |
1214 ContextProvider()->GetCapabilities().chromium_image_rgb_emulation) { | 1199 ContextProvider()->GetCapabilities().chromium_image_rgb_emulation) { |
1215 GLuint fbo = 0; | 1200 GLuint fbo = 0; |
1216 | 1201 |
1217 state_restorer_->SetClearStateDirty(); | 1202 state_restorer_->SetClearStateDirty(); |
1218 gl_->GenFramebuffers(1, &fbo); | 1203 gl_->GenFramebuffers(1, &fbo); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 if (pixel_unpack_buffer_binding_dirty_) | 1288 if (pixel_unpack_buffer_binding_dirty_) |
1304 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); | 1289 client->DrawingBufferClientRestorePixelUnpackBufferBinding(); |
1305 } | 1290 } |
1306 | 1291 |
1307 bool DrawingBuffer::ShouldUseChromiumImage() { | 1292 bool DrawingBuffer::ShouldUseChromiumImage() { |
1308 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && | 1293 return RuntimeEnabledFeatures::webGLImageChromiumEnabled() && |
1309 chromium_image_usage_ == kAllowChromiumImage; | 1294 chromium_image_usage_ == kAllowChromiumImage; |
1310 } | 1295 } |
1311 | 1296 |
1312 } // namespace blink | 1297 } // namespace blink |
OLD | NEW |