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

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 14188053: gpu: Change Produce/ConsumeTexture to allow texture sharing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "gpu/command_buffer/service/mailbox_manager.h" 45 #include "gpu/command_buffer/service/mailbox_manager.h"
46 #include "gpu/command_buffer/service/memory_tracking.h" 46 #include "gpu/command_buffer/service/memory_tracking.h"
47 #include "gpu/command_buffer/service/program_manager.h" 47 #include "gpu/command_buffer/service/program_manager.h"
48 #include "gpu/command_buffer/service/query_manager.h" 48 #include "gpu/command_buffer/service/query_manager.h"
49 #include "gpu/command_buffer/service/renderbuffer_manager.h" 49 #include "gpu/command_buffer/service/renderbuffer_manager.h"
50 #include "gpu/command_buffer/service/shader_manager.h" 50 #include "gpu/command_buffer/service/shader_manager.h"
51 #include "gpu/command_buffer/service/shader_translator.h" 51 #include "gpu/command_buffer/service/shader_translator.h"
52 #include "gpu/command_buffer/service/shader_translator_cache.h" 52 #include "gpu/command_buffer/service/shader_translator_cache.h"
53 #include "gpu/command_buffer/service/stream_texture.h" 53 #include "gpu/command_buffer/service/stream_texture.h"
54 #include "gpu/command_buffer/service/stream_texture_manager.h" 54 #include "gpu/command_buffer/service/stream_texture_manager.h"
55 #include "gpu/command_buffer/service/texture_definition.h"
56 #include "gpu/command_buffer/service/texture_manager.h" 55 #include "gpu/command_buffer/service/texture_manager.h"
57 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 56 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
58 #include "gpu/command_buffer/service/vertex_array_manager.h" 57 #include "gpu/command_buffer/service/vertex_array_manager.h"
59 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" 58 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
60 #include "ui/gl/gl_bindings.h" 59 #include "ui/gl/gl_bindings.h"
61 #include "ui/gl/gl_image.h" 60 #include "ui/gl/gl_image.h"
62 #include "ui/gl/gl_implementation.h" 61 #include "ui/gl/gl_implementation.h"
63 #include "ui/gl/gl_surface.h" 62 #include "ui/gl/gl_surface.h"
64 #if defined(OS_MACOSX) 63 #if defined(OS_MACOSX)
65 #include "ui/surface/io_surface_support_mac.h" 64 #include "ui/surface/io_surface_support_mac.h"
(...skipping 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 state_.texture_units[tt].bound_texture_2d = ref; 2253 state_.texture_units[tt].bound_texture_2d = ref;
2255 glBindTexture(GL_TEXTURE_2D, ref->service_id()); 2254 glBindTexture(GL_TEXTURE_2D, ref->service_id());
2256 } 2255 }
2257 glActiveTexture(GL_TEXTURE0); 2256 glActiveTexture(GL_TEXTURE0);
2258 CHECK_GL_ERROR(); 2257 CHECK_GL_ERROR();
2259 2258
2260 ContextCreationAttribParser attrib_parser; 2259 ContextCreationAttribParser attrib_parser;
2261 if (!attrib_parser.Parse(attribs)) 2260 if (!attrib_parser.Parse(attribs))
2262 return false; 2261 return false;
2263 2262
2264 // These are NOT if the back buffer has these proprorties. They are
2265 // if we want the command buffer to enforce them regardless of what
2266 // the real backbuffer is assuming the real back buffer gives us more than
2267 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll
2268 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we
2269 // can't do anything about that.
2270
2271 GLint v = 0;
2272 glGetIntegerv(GL_ALPHA_BITS, &v);
2273 // This checks if the user requested RGBA and we have RGBA then RGBA. If the
2274 // user requested RGB then RGB. If the user did not specify a preference than
2275 // use whatever we were given. Same for DEPTH and STENCIL.
2276 back_buffer_color_format_ =
2277 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB;
2278 glGetIntegerv(GL_DEPTH_BITS, &v);
2279 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0;
2280 glGetIntegerv(GL_STENCIL_BITS, &v);
2281 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0;
2282
2283 if (offscreen) { 2263 if (offscreen) {
2284 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && 2264 if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 &&
2285 features().chromium_framebuffer_multisample) { 2265 features().chromium_framebuffer_multisample) {
2286 // Per ext_framebuffer_multisample spec, need max bound on sample count. 2266 // Per ext_framebuffer_multisample spec, need max bound on sample count.
2287 // max_sample_count must be initialized to a sane value. If 2267 // max_sample_count must be initialized to a sane value. If
2288 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. 2268 // glGetIntegerv() throws a GL error, it leaves its argument unchanged.
2289 GLint max_sample_count = 1; 2269 GLint max_sample_count = 1;
2290 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); 2270 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count);
2291 offscreen_target_samples_ = std::min(attrib_parser.samples_, 2271 offscreen_target_samples_ = std::min(attrib_parser.samples_,
2292 max_sample_count); 2272 max_sample_count);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 if (offscreen_saved_frame_buffer_->CheckStatus() != 2381 if (offscreen_saved_frame_buffer_->CheckStatus() !=
2402 GL_FRAMEBUFFER_COMPLETE) { 2382 GL_FRAMEBUFFER_COMPLETE) {
2403 LOG(ERROR) << "Offscreen saved FBO was incomplete."; 2383 LOG(ERROR) << "Offscreen saved FBO was incomplete.";
2404 Destroy(true); 2384 Destroy(true);
2405 return false; 2385 return false;
2406 } 2386 }
2407 2387
2408 // Bind to the new default frame buffer (the offscreen target frame buffer). 2388 // Bind to the new default frame buffer (the offscreen target frame buffer).
2409 // This should now be associated with ID zero. 2389 // This should now be associated with ID zero.
2410 DoBindFramebuffer(GL_FRAMEBUFFER, 0); 2390 DoBindFramebuffer(GL_FRAMEBUFFER, 0);
2391 } else {
2392 glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId());
2393 // These are NOT if the back buffer has these proprorties. They are
2394 // if we want the command buffer to enforce them regardless of what
2395 // the real backbuffer is assuming the real back buffer gives us more than
2396 // we ask for. In other words, if we ask for RGB and we get RGBA then we'll
2397 // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we
2398 // can't do anything about that.
2399
2400 GLint v = 0;
2401 glGetIntegerv(GL_ALPHA_BITS, &v);
2402 // This checks if the user requested RGBA and we have RGBA then RGBA. If the
2403 // user requested RGB then RGB. If the user did not specify a preference
2404 // than use whatever we were given. Same for DEPTH and STENCIL.
2405 back_buffer_color_format_ =
2406 (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB;
2407 glGetIntegerv(GL_DEPTH_BITS, &v);
2408 back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0;
2409 glGetIntegerv(GL_STENCIL_BITS, &v);
2410 back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0;
2411 } 2411 }
2412 2412
2413 // OpenGL ES 2.0 implicitly enables the desktop GL capability 2413 // OpenGL ES 2.0 implicitly enables the desktop GL capability
2414 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact 2414 // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact
2415 // isn't well documented; it was discovered in the Khronos OpenGL ES 2415 // isn't well documented; it was discovered in the Khronos OpenGL ES
2416 // mailing list archives. It also implicitly enables the desktop GL 2416 // mailing list archives. It also implicitly enables the desktop GL
2417 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord 2417 // capability GL_POINT_SPRITE to provide access to the gl_PointCoord
2418 // variable in fragment shaders. 2418 // variable in fragment shaders.
2419 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 2419 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
2420 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); 2420 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
(...skipping 7427 matching lines...) Expand 10 before | Expand all | Expand 10 after
9848 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); 9848 "mailbox[0]", static_cast<unsigned char>(mailbox[0]));
9849 9849
9850 TextureRef* texture_ref = GetTextureInfoForTarget(target); 9850 TextureRef* texture_ref = GetTextureInfoForTarget(target);
9851 if (!texture_ref) { 9851 if (!texture_ref) {
9852 LOCAL_SET_GL_ERROR( 9852 LOCAL_SET_GL_ERROR(
9853 GL_INVALID_OPERATION, 9853 GL_INVALID_OPERATION,
9854 "glProduceTextureCHROMIUM", "unknown texture for target"); 9854 "glProduceTextureCHROMIUM", "unknown texture for target");
9855 return; 9855 return;
9856 } 9856 }
9857 9857
9858 TextureDefinition* definition = texture_manager()->Save(texture_ref); 9858 Texture* produced = texture_manager()->Produce(texture_ref);
9859 if (!definition) { 9859 if (!produced) {
9860 LOCAL_SET_GL_ERROR( 9860 LOCAL_SET_GL_ERROR(
9861 GL_INVALID_OPERATION, 9861 GL_INVALID_OPERATION,
9862 "glProduceTextureCHROMIUM", "invalid texture"); 9862 "glProduceTextureCHROMIUM", "invalid texture");
9863 return; 9863 return;
9864 } 9864 }
9865 9865
9866 if (!group_->mailbox_manager()->ProduceTexture( 9866 if (!group_->mailbox_manager()->ProduceTexture(
9867 target, 9867 target,
9868 *reinterpret_cast<const MailboxName*>(mailbox), 9868 *reinterpret_cast<const MailboxName*>(mailbox),
9869 definition, 9869 produced)) {
9870 texture_manager())) {
9871 bool success = texture_manager()->Restore(
9872 "glProductTextureCHROMIUM", this, texture_ref, definition);
9873 DCHECK(success);
9874 LOCAL_SET_GL_ERROR( 9870 LOCAL_SET_GL_ERROR(
9875 GL_INVALID_OPERATION, 9871 GL_INVALID_OPERATION,
9876 "glProduceTextureCHROMIUM", "invalid mailbox name"); 9872 "glProduceTextureCHROMIUM", "invalid mailbox name");
9877 return; 9873 return;
9878 } 9874 }
9879
9880 glBindTexture(texture_ref->texture()->target(), texture_ref->service_id());
9881 } 9875 }
9882 9876
9883 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, 9877 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target,
9884 const GLbyte* mailbox) { 9878 const GLbyte* mailbox) {
9885 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", 9879 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM",
9886 "context", logger_.GetLogPrefix(), 9880 "context", logger_.GetLogPrefix(),
9887 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); 9881 "mailbox[0]", static_cast<unsigned char>(mailbox[0]));
9888 9882
9889 TextureRef* texture_ref = GetTextureInfoForTarget(target); 9883 scoped_refptr<TextureRef> texture_ref =
9884 GetTextureInfoForTargetUnlessDefault(target);
9890 if (!texture_ref) { 9885 if (!texture_ref) {
9891 LOCAL_SET_GL_ERROR( 9886 LOCAL_SET_GL_ERROR(
9892 GL_INVALID_OPERATION, 9887 GL_INVALID_OPERATION,
9893 "glConsumeTextureCHROMIUM", "unknown texture for target"); 9888 "glConsumeTextureCHROMIUM", "unknown texture for target");
9894 return; 9889 return;
9895 } 9890 }
9896 9891 if (texture_ref->texture()->IsAttachedToFramebuffer()) {
9897 scoped_ptr<TextureDefinition> definition( 9892 LOCAL_SET_GL_ERROR(
9893 GL_INVALID_OPERATION,
9894 "glConsumeTextureCHROMIUM", "texture attached to framebuffer");
9895 return;
9896 }
9897 GLuint client_id = texture_ref->client_id();
9898 if (!client_id) {
9899 LOCAL_SET_GL_ERROR(
9900 GL_INVALID_OPERATION,
9901 "glConsumeTextureCHROMIUM", "unknown texture for target");
9902 return;
9903 }
9904 Texture* texture =
9898 group_->mailbox_manager()->ConsumeTexture( 9905 group_->mailbox_manager()->ConsumeTexture(
9899 target, 9906 target,
9900 *reinterpret_cast<const MailboxName*>(mailbox))); 9907 *reinterpret_cast<const MailboxName*>(mailbox));
9901 if (!definition.get()) { 9908 if (!texture) {
9902 LOCAL_SET_GL_ERROR( 9909 LOCAL_SET_GL_ERROR(
9903 GL_INVALID_OPERATION, 9910 GL_INVALID_OPERATION,
9904 "glConsumeTextureCHROMIUM", "invalid mailbox name"); 9911 "glConsumeTextureCHROMIUM", "invalid mailbox name");
9905 return; 9912 return;
9906 } 9913 }
9907 9914 if (texture->target() != target) {
9908 if (!texture_manager()->Restore(
9909 "glConsumeTextureCHROMIUM", this, texture_ref, definition.release())) {
9910 LOCAL_SET_GL_ERROR( 9915 LOCAL_SET_GL_ERROR(
9911 GL_INVALID_OPERATION, 9916 GL_INVALID_OPERATION,
9912 "glConsumeTextureCHROMIUM", "invalid texture"); 9917 "glConsumeTextureCHROMIUM", "invalid target");
9913 return; 9918 return;
9914 } 9919 }
9920
9921 // TODO(piman): Instead of deleting and recreating the texture, we could
9922 // change the Texture inside the TextureRef. We need crbug.com/240504 to be
greggman 2013/05/24 17:51:54 I take it back. This code is fine as is. No need f
piman 2013/05/24 23:03:27 Done.
9923 // fixed first, and we'll need to notify all the decoder in the context group
9924 // that they need to rebind the current texture in all units when they're
9925 // made current again (since the service id for the TextureRef will have
9926 // changed). We currently disallow Consume on a texture bound to an FBO, but
9927 // to remove that limitation, we'll need a way to notify them to reattach the
9928 // texture when they're made current as well.
9929 DeleteTexturesHelper(1, &client_id);
9930 texture_ref = texture_manager()->Consume(client_id, texture);
9931 glBindTexture(target, texture_ref->service_id());
9932
9933 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
9934 unit.bind_target = target;
9935 switch (target) {
9936 case GL_TEXTURE_2D:
9937 unit.bound_texture_2d = texture_ref;
9938 break;
9939 case GL_TEXTURE_CUBE_MAP:
9940 unit.bound_texture_cube_map = texture_ref;
9941 break;
9942 case GL_TEXTURE_EXTERNAL_OES:
9943 unit.bound_texture_external_oes = texture_ref;
9944 break;
9945 case GL_TEXTURE_RECTANGLE_ARB:
9946 unit.bound_texture_rectangle_arb = texture_ref;
9947 break;
9948 default:
9949 NOTREACHED(); // Validation should prevent us getting here.
9950 break;
9951 }
9915 } 9952 }
9916 9953
9917 void GLES2DecoderImpl::DoInsertEventMarkerEXT( 9954 void GLES2DecoderImpl::DoInsertEventMarkerEXT(
9918 GLsizei length, const GLchar* marker) { 9955 GLsizei length, const GLchar* marker) {
9919 if (!marker) { 9956 if (!marker) {
9920 marker = ""; 9957 marker = "";
9921 } 9958 }
9922 debug_marker_manager_.SetMarker( 9959 debug_marker_manager_.SetMarker(
9923 length ? std::string(marker, length) : std::string(marker)); 9960 length ? std::string(marker, length) : std::string(marker));
9924 } 9961 }
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
10351 return error::kNoError; 10388 return error::kNoError;
10352 } 10389 }
10353 10390
10354 // Include the auto-generated part of this file. We split this because it means 10391 // Include the auto-generated part of this file. We split this because it means
10355 // we can easily edit the non-auto generated parts right here in this file 10392 // we can easily edit the non-auto generated parts right here in this file
10356 // instead of having to edit some template or the code generator. 10393 // instead of having to edit some template or the code generator.
10357 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10394 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10358 10395
10359 } // namespace gles2 10396 } // namespace gles2
10360 } // namespace gpu 10397 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698