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

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

Issue 2061743004: Implement native GMB backbuffers in the GLES2 Command Decoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from piman. 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 (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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 30 matching lines...) Expand all
41 #include "gpu/command_buffer/service/gl_utils.h" 41 #include "gpu/command_buffer/service/gl_utils.h"
42 #include "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa _intel.h" 42 #include "gpu/command_buffer/service/gles2_cmd_apply_framebuffer_attachment_cmaa _intel.h"
43 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" 43 #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h"
44 #include "gpu/command_buffer/service/gles2_cmd_copy_tex_image.h" 44 #include "gpu/command_buffer/service/gles2_cmd_copy_tex_image.h"
45 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" 45 #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h"
46 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h" 46 #include "gpu/command_buffer/service/gles2_cmd_decoder_passthrough.h"
47 #include "gpu/command_buffer/service/gles2_cmd_validation.h" 47 #include "gpu/command_buffer/service/gles2_cmd_validation.h"
48 #include "gpu/command_buffer/service/gpu_preferences.h" 48 #include "gpu/command_buffer/service/gpu_preferences.h"
49 #include "gpu/command_buffer/service/gpu_state_tracer.h" 49 #include "gpu/command_buffer/service/gpu_state_tracer.h"
50 #include "gpu/command_buffer/service/gpu_tracer.h" 50 #include "gpu/command_buffer/service/gpu_tracer.h"
51 #include "gpu/command_buffer/service/image_factory.h"
51 #include "gpu/command_buffer/service/image_manager.h" 52 #include "gpu/command_buffer/service/image_manager.h"
52 #include "gpu/command_buffer/service/logger.h" 53 #include "gpu/command_buffer/service/logger.h"
53 #include "gpu/command_buffer/service/mailbox_manager.h" 54 #include "gpu/command_buffer/service/mailbox_manager.h"
54 #include "gpu/command_buffer/service/memory_tracking.h" 55 #include "gpu/command_buffer/service/memory_tracking.h"
55 #include "gpu/command_buffer/service/path_manager.h" 56 #include "gpu/command_buffer/service/path_manager.h"
56 #include "gpu/command_buffer/service/program_manager.h" 57 #include "gpu/command_buffer/service/program_manager.h"
57 #include "gpu/command_buffer/service/query_manager.h" 58 #include "gpu/command_buffer/service/query_manager.h"
58 #include "gpu/command_buffer/service/renderbuffer_manager.h" 59 #include "gpu/command_buffer/service/renderbuffer_manager.h"
59 #include "gpu/command_buffer/service/sampler_manager.h" 60 #include "gpu/command_buffer/service/sampler_manager.h"
60 #include "gpu/command_buffer/service/shader_manager.h" 61 #include "gpu/command_buffer/service/shader_manager.h"
61 #include "gpu/command_buffer/service/shader_translator.h" 62 #include "gpu/command_buffer/service/shader_translator.h"
62 #include "gpu/command_buffer/service/texture_manager.h" 63 #include "gpu/command_buffer/service/texture_manager.h"
63 #include "gpu/command_buffer/service/transform_feedback_manager.h" 64 #include "gpu/command_buffer/service/transform_feedback_manager.h"
64 #include "gpu/command_buffer/service/vertex_array_manager.h" 65 #include "gpu/command_buffer/service/vertex_array_manager.h"
65 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 66 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
66 #include "third_party/smhasher/src/City.h" 67 #include "third_party/smhasher/src/City.h"
68 #include "ui/gfx/buffer_types.h"
67 #include "ui/gfx/geometry/point.h" 69 #include "ui/gfx/geometry/point.h"
68 #include "ui/gfx/geometry/rect.h" 70 #include "ui/gfx/geometry/rect.h"
69 #include "ui/gfx/geometry/size.h" 71 #include "ui/gfx/geometry/size.h"
72 #include "ui/gfx/gpu_memory_buffer.h"
70 #include "ui/gfx/overlay_transform.h" 73 #include "ui/gfx/overlay_transform.h"
71 #include "ui/gfx/transform.h" 74 #include "ui/gfx/transform.h"
72 #include "ui/gl/gl_bindings.h" 75 #include "ui/gl/gl_bindings.h"
73 #include "ui/gl/gl_context.h" 76 #include "ui/gl/gl_context.h"
74 #include "ui/gl/gl_fence.h" 77 #include "ui/gl/gl_fence.h"
75 #include "ui/gl/gl_image.h" 78 #include "ui/gl/gl_image.h"
76 #include "ui/gl/gl_implementation.h" 79 #include "ui/gl/gl_implementation.h"
77 #include "ui/gl/gl_surface.h" 80 #include "ui/gl/gl_surface.h"
78 #include "ui/gl/gl_version_info.h" 81 #include "ui/gl/gl_version_info.h"
79 #include "ui/gl/gpu_timing.h" 82 #include "ui/gl/gpu_timing.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 void Copy(const gfx::Size& size, GLenum format); 403 void Copy(const gfx::Size& size, GLenum format);
401 404
402 // Destroy the render texture. This must be explicitly called before 405 // Destroy the render texture. This must be explicitly called before
403 // destroying this object. 406 // destroying this object.
404 void Destroy(); 407 void Destroy();
405 408
406 // Invalidate the texture. This can be used when a context is lost and it is 409 // Invalidate the texture. This can be used when a context is lost and it is
407 // not possible to make it current in order to free the resource. 410 // not possible to make it current in order to free the resource.
408 void Invalidate(); 411 void Invalidate();
409 412
413 // The bind point for the texture.
414 GLenum Target();
415
410 scoped_refptr<TextureRef> texture_ref() { return texture_ref_; } 416 scoped_refptr<TextureRef> texture_ref() { return texture_ref_; }
411 417
412 GLuint id() const { 418 GLuint id() const {
413 return texture_ref_ ? texture_ref_->service_id() : 0; 419 return texture_ref_ ? texture_ref_->service_id() : 0;
414 } 420 }
415 421
416 gfx::Size size() const { 422 gfx::Size size() const {
417 return size_; 423 return size_;
418 } 424 }
419 425
420 private: 426 private:
427 // The texture must be bound to Target() before calling this method.
428 // Returns whether the operation was successful.
429 bool AllocateNativeGpuMemoryBuffer(const gfx::Size& size,
430 GLenum format,
431 bool zero);
432
433 // The texture must be bound to Target() before calling this method.
434 void DestroyNativeGpuMemoryBuffer(bool have_context);
435
421 MemoryTypeTracker memory_tracker_; 436 MemoryTypeTracker memory_tracker_;
422 size_t bytes_allocated_; 437 size_t bytes_allocated_;
423 gfx::Size size_; 438 gfx::Size size_;
424 GLES2DecoderImpl* decoder_; 439 GLES2DecoderImpl* decoder_;
425 440
426 scoped_refptr<TextureRef> texture_ref_; 441 scoped_refptr<TextureRef> texture_ref_;
427 442
443 // The image that backs the texture, if its backed by a native
444 // GpuMemoryBuffer.
445 scoped_refptr<gl::GLImage> image_;
446
428 DISALLOW_COPY_AND_ASSIGN(BackTexture); 447 DISALLOW_COPY_AND_ASSIGN(BackTexture);
429 }; 448 };
430 449
431 // Encapsulates an OpenGL render buffer of any format. 450 // Encapsulates an OpenGL render buffer of any format.
432 class BackRenderbuffer { 451 class BackRenderbuffer {
433 public: 452 public:
434 explicit BackRenderbuffer( 453 explicit BackRenderbuffer(GLES2DecoderImpl* decoder);
435 RenderbufferManager* renderbuffer_manager,
436 MemoryTracker* memory_tracker,
437 ContextState* state);
438 ~BackRenderbuffer(); 454 ~BackRenderbuffer();
439 455
440 // Create a new render buffer. 456 // Create a new render buffer.
441 void Create(); 457 void Create();
442 458
443 // Set the initial size and format of a render buffer or resize it. 459 // Set the initial size and format of a render buffer or resize it.
444 bool AllocateStorage(const FeatureInfo* feature_info, 460 bool AllocateStorage(const FeatureInfo* feature_info,
445 const gfx::Size& size, 461 const gfx::Size& size,
446 GLenum format, 462 GLenum format,
447 GLsizei samples); 463 GLsizei samples);
448 464
449 // Destroy the render buffer. This must be explicitly called before destroying 465 // Destroy the render buffer. This must be explicitly called before destroying
450 // this object. 466 // this object.
451 void Destroy(); 467 void Destroy();
452 468
453 // Invalidate the render buffer. This can be used when a context is lost and 469 // Invalidate the render buffer. This can be used when a context is lost and
454 // it is not possible to make it current in order to free the resource. 470 // it is not possible to make it current in order to free the resource.
455 void Invalidate(); 471 void Invalidate();
456 472
457 GLuint id() const { 473 GLuint id() const {
458 return id_; 474 return id_;
459 } 475 }
460 476
461 private: 477 private:
462 RenderbufferManager* renderbuffer_manager_; 478 GLES2DecoderImpl* decoder_;
463 MemoryTypeTracker memory_tracker_; 479 MemoryTypeTracker memory_tracker_;
464 ContextState* state_;
465 size_t bytes_allocated_; 480 size_t bytes_allocated_;
466 GLuint id_; 481 GLuint id_;
467 DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); 482 DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer);
468 }; 483 };
469 484
470 // Encapsulates an OpenGL frame buffer. 485 // Encapsulates an OpenGL frame buffer.
471 class BackFramebuffer { 486 class BackFramebuffer {
472 public: 487 public:
473 explicit BackFramebuffer(GLES2DecoderImpl* decoder); 488 explicit BackFramebuffer(GLES2DecoderImpl* decoder);
474 ~BackFramebuffer(); 489 ~BackFramebuffer();
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 679
665 // Restores the current state to the user's settings. 680 // Restores the current state to the user's settings.
666 void RestoreCurrentFramebufferBindings(); 681 void RestoreCurrentFramebufferBindings();
667 682
668 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. 683 // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer.
669 void ApplyDirtyState(); 684 void ApplyDirtyState();
670 685
671 // These check the state of the currently bound framebuffer or the 686 // These check the state of the currently bound framebuffer or the
672 // backbuffer if no framebuffer is bound. 687 // backbuffer if no framebuffer is bound.
673 // Check with all attached and enabled color attachments. 688 // Check with all attached and enabled color attachments.
674 bool BoundFramebufferHasColorAttachmentWithAlpha(); 689 bool BoundFramebufferAllowsChangesToAlphaChannel();
675 bool BoundFramebufferHasDepthAttachment(); 690 bool BoundFramebufferHasDepthAttachment();
676 bool BoundFramebufferHasStencilAttachment(); 691 bool BoundFramebufferHasStencilAttachment();
677 692
678 error::ContextLostReason GetContextLostReason() override; 693 error::ContextLostReason GetContextLostReason() override;
679 694
680 // Overriden from ErrorStateClient. 695 // Overriden from ErrorStateClient.
681 void OnContextLostError() override; 696 void OnContextLostError() override;
682 void OnOutOfMemoryError() override; 697 void OnOutOfMemoryError() override;
683 698
684 // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. 699 // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound.
(...skipping 19 matching lines...) Expand all
704 GLbitfield mask, 719 GLbitfield mask,
705 GLenum filter); 720 GLenum filter);
706 721
707 PathManager* path_manager() { return group_->path_manager(); } 722 PathManager* path_manager() { return group_->path_manager(); }
708 723
709 private: 724 private:
710 friend class ScopedFrameBufferBinder; 725 friend class ScopedFrameBufferBinder;
711 friend class ScopedFrameBufferReadPixelHelper; 726 friend class ScopedFrameBufferReadPixelHelper;
712 friend class ScopedResolvedFrameBufferBinder; 727 friend class ScopedResolvedFrameBufferBinder;
713 friend class BackFramebuffer; 728 friend class BackFramebuffer;
729 friend class BackRenderbuffer;
714 friend class BackTexture; 730 friend class BackTexture;
715 731
716 enum FramebufferOperation { 732 enum FramebufferOperation {
717 kFramebufferDiscard, 733 kFramebufferDiscard,
718 kFramebufferInvalidate, 734 kFramebufferInvalidate,
719 kFramebufferInvalidateSub 735 kFramebufferInvalidateSub
720 }; 736 };
721 737
722 enum BindIndexedBufferFunctionType { 738 enum BindIndexedBufferFunctionType {
723 kBindBufferBase, 739 kBindBufferBase,
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 error::Error WillAccessBoundFramebufferForRead() { 1957 error::Error WillAccessBoundFramebufferForRead() {
1942 if (ShouldDeferReads()) 1958 if (ShouldDeferReads())
1943 return error::kDeferCommandUntilLater; 1959 return error::kDeferCommandUntilLater;
1944 if (!offscreen_target_frame_buffer_.get() && 1960 if (!offscreen_target_frame_buffer_.get() &&
1945 !framebuffer_state_.bound_read_framebuffer.get() && 1961 !framebuffer_state_.bound_read_framebuffer.get() &&
1946 !surface_->SetBackbufferAllocation(true)) 1962 !surface_->SetBackbufferAllocation(true))
1947 return error::kLostContext; 1963 return error::kLostContext;
1948 return error::kNoError; 1964 return error::kNoError;
1949 } 1965 }
1950 1966
1951 bool BackBufferHasAlpha() const { 1967 // Whether the back buffer exposed to the client has an alpha channel. Note
1968 // that this is potentially different from whether the implementation of the
1969 // back buffer has an alpha channel.
1970 bool ClientExposedBackBufferHasAlpha() const {
1952 if (back_buffer_draw_buffer_ == GL_NONE) 1971 if (back_buffer_draw_buffer_ == GL_NONE)
1953 return false; 1972 return false;
1954 if (offscreen_target_frame_buffer_.get()) { 1973 if (offscreen_target_frame_buffer_.get()) {
1955 return (offscreen_target_color_format_ == GL_RGBA || 1974 return offscreen_buffer_should_have_alpha_;
1956 offscreen_target_color_format_ == GL_RGBA8);
1957 } 1975 }
1958 return (back_buffer_color_format_ == GL_RGBA || 1976 return (back_buffer_color_format_ == GL_RGBA ||
1959 back_buffer_color_format_ == GL_RGBA8); 1977 back_buffer_color_format_ == GL_RGBA8);
1960 } 1978 }
1961 1979
1980 // If the back buffer has a non-emulated alpha channel, the clear color should
1981 // be 0. Otherwise, the clear color should be 1.
1982 GLfloat BackBufferAlphaClearColor() const {
1983 return offscreen_buffer_should_have_alpha_ ? 0.f : 1.f;
1984 }
1985
1962 // Set remaining commands to process to 0 to force DoCommands to return 1986 // Set remaining commands to process to 0 to force DoCommands to return
1963 // and allow context preemption and GPU watchdog checks in CommandExecutor(). 1987 // and allow context preemption and GPU watchdog checks in CommandExecutor().
1964 void ExitCommandProcessingEarly() { commands_to_process_ = 0; } 1988 void ExitCommandProcessingEarly() { commands_to_process_ = 0; }
1965 1989
1966 void ProcessPendingReadPixels(bool did_finish); 1990 void ProcessPendingReadPixels(bool did_finish);
1967 void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); 1991 void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer);
1968 1992
1969 // Checks to see if the inserted fence has completed. 1993 // Checks to see if the inserted fence has completed.
1970 void ProcessDescheduleUntilFinished(); 1994 void ProcessDescheduleUntilFinished();
1971 1995
1972 void DoBindFragmentInputLocationCHROMIUM(GLuint program_id, 1996 void DoBindFragmentInputLocationCHROMIUM(GLuint program_id,
1973 GLint location, 1997 GLint location,
1974 const std::string& name); 1998 const std::string& name);
1975 1999
1976 // If |texture_manager_version_| doesn't match the current version, then this 2000 // If |texture_manager_version_| doesn't match the current version, then this
1977 // will rebind all external textures to match their current service_id. 2001 // will rebind all external textures to match their current service_id.
1978 void RestoreAllExternalTextureBindingsIfNeeded() override; 2002 void RestoreAllExternalTextureBindingsIfNeeded() override;
1979 2003
1980 const SamplerState& GetSamplerStateForTextureUnit(GLenum target, GLuint unit); 2004 const SamplerState& GetSamplerStateForTextureUnit(GLenum target, GLuint unit);
1981 2005
1982 // copyTexImage2D doesn't work on OSX under very specific conditions. 2006 // copyTexImage2D doesn't work on OSX under very specific conditions.
1983 // Returns whether those conditions have been met. If this method returns 2007 // Returns whether those conditions have been met. If this method returns
1984 // true, |source_texture_service_id| and |source_texture_target| are also 2008 // true, |source_texture_service_id| and |source_texture_target| are also
1985 // populated, since they are needed to implement the workaround. 2009 // populated, since they are needed to implement the workaround.
1986 bool NeedsCopyTextureImageWorkaround(GLenum internal_format, 2010 bool NeedsCopyTextureImageWorkaround(GLenum internal_format,
1987 int32_t channels_exist, 2011 int32_t channels_exist,
1988 GLuint* source_texture_service_id, 2012 GLuint* source_texture_service_id,
1989 GLenum* source_texture_target); 2013 GLenum* source_texture_target);
1990 2014
2015 // Whether a texture backed by a Chromium Image needs to emulate GL_RGB format
2016 // using GL_RGBA and glColorMask.
2017 bool ChromiumImageNeedsRGBEmulation();
2018
1991 bool InitializeCopyTexImageBlitter(const char* function_name); 2019 bool InitializeCopyTexImageBlitter(const char* function_name);
1992 bool InitializeCopyTextureCHROMIUM(const char* function_name); 2020 bool InitializeCopyTextureCHROMIUM(const char* function_name);
1993 // Generate a member function prototype for each command in an automated and 2021 // Generate a member function prototype for each command in an automated and
1994 // typesafe way. 2022 // typesafe way.
1995 #define GLES2_CMD_OP(name) \ 2023 #define GLES2_CMD_OP(name) \
1996 Error Handle##name(uint32_t immediate_data_size, const void* data); 2024 Error Handle##name(uint32_t immediate_data_size, const void* data);
1997 2025
1998 GLES2_COMMAND_LIST(GLES2_CMD_OP) 2026 GLES2_COMMAND_LIST(GLES2_CMD_OP)
1999 2027
2000 #undef GLES2_CMD_OP 2028 #undef GLES2_CMD_OP
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 2068
2041 // The offscreen frame buffer that the client renders to. With EGL, the 2069 // The offscreen frame buffer that the client renders to. With EGL, the
2042 // depth and stencil buffers are separate. With regular GL there is a single 2070 // depth and stencil buffers are separate. With regular GL there is a single
2043 // packed depth stencil buffer in offscreen_target_depth_render_buffer_. 2071 // packed depth stencil buffer in offscreen_target_depth_render_buffer_.
2044 // offscreen_target_stencil_render_buffer_ is unused. 2072 // offscreen_target_stencil_render_buffer_ is unused.
2045 std::unique_ptr<BackFramebuffer> offscreen_target_frame_buffer_; 2073 std::unique_ptr<BackFramebuffer> offscreen_target_frame_buffer_;
2046 std::unique_ptr<BackTexture> offscreen_target_color_texture_; 2074 std::unique_ptr<BackTexture> offscreen_target_color_texture_;
2047 std::unique_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; 2075 std::unique_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_;
2048 std::unique_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; 2076 std::unique_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_;
2049 std::unique_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; 2077 std::unique_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_;
2078
2079 // The format of the texture or renderbuffer backing the offscreen
2080 // framebuffer. Also the format of the texture backing the saved offscreen
2081 // framebuffer.
2050 GLenum offscreen_target_color_format_; 2082 GLenum offscreen_target_color_format_;
2083
2051 GLenum offscreen_target_depth_format_; 2084 GLenum offscreen_target_depth_format_;
2052 GLenum offscreen_target_stencil_format_; 2085 GLenum offscreen_target_stencil_format_;
2053 GLsizei offscreen_target_samples_; 2086 GLsizei offscreen_target_samples_;
2054 GLboolean offscreen_target_buffer_preserved_; 2087 GLboolean offscreen_target_buffer_preserved_;
2055 2088
2056 // The saved copy of the backbuffer after a call to SwapBuffers. 2089 // The saved copy of the backbuffer after a call to SwapBuffers.
2057 std::unique_ptr<BackTexture> offscreen_saved_color_texture_; 2090 std::unique_ptr<BackTexture> offscreen_saved_color_texture_;
2058 2091
2059 // For simplicity, |offscreen_saved_color_texture_| is always bound to 2092 // For simplicity, |offscreen_saved_color_texture_| is always bound to
2060 // |offscreen_saved_frame_buffer_|. 2093 // |offscreen_saved_frame_buffer_|.
(...skipping 23 matching lines...) Expand all
2084 void ReleaseAllBackTextures(bool have_context); 2117 void ReleaseAllBackTextures(bool have_context);
2085 2118
2086 size_t GetSavedBackTextureCountForTest() override; 2119 size_t GetSavedBackTextureCountForTest() override;
2087 size_t GetCreatedBackTextureCountForTest() override; 2120 size_t GetCreatedBackTextureCountForTest() override;
2088 2121
2089 // The copy that is used as the destination for multi-sample resolves. 2122 // The copy that is used as the destination for multi-sample resolves.
2090 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 2123 std::unique_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
2091 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_; 2124 std::unique_ptr<BackTexture> offscreen_resolved_color_texture_;
2092 GLenum offscreen_saved_color_format_; 2125 GLenum offscreen_saved_color_format_;
2093 2126
2127 // Whether the client requested an offscreen buffer with an alpha channel.
2128 bool offscreen_buffer_should_have_alpha_;
2129
2094 std::unique_ptr<QueryManager> query_manager_; 2130 std::unique_ptr<QueryManager> query_manager_;
2095 2131
2096 std::unique_ptr<VertexArrayManager> vertex_array_manager_; 2132 std::unique_ptr<VertexArrayManager> vertex_array_manager_;
2097 2133
2098 std::unique_ptr<ImageManager> image_manager_; 2134 std::unique_ptr<ImageManager> image_manager_;
2099 2135
2100 FenceSyncReleaseCallback fence_sync_release_callback_; 2136 FenceSyncReleaseCallback fence_sync_release_callback_;
2101 WaitFenceSyncCallback wait_fence_sync_callback_; 2137 WaitFenceSyncCallback wait_fence_sync_callback_;
2102 NoParamCallback deschedule_until_finished_callback_; 2138 NoParamCallback deschedule_until_finished_callback_;
2103 NoParamCallback reschedule_after_finished_callback_; 2139 NoParamCallback reschedule_after_finished_callback_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 bool derivatives_explicitly_enabled_; 2194 bool derivatives_explicitly_enabled_;
2159 bool frag_depth_explicitly_enabled_; 2195 bool frag_depth_explicitly_enabled_;
2160 bool draw_buffers_explicitly_enabled_; 2196 bool draw_buffers_explicitly_enabled_;
2161 bool shader_texture_lod_explicitly_enabled_; 2197 bool shader_texture_lod_explicitly_enabled_;
2162 2198
2163 bool compile_shader_always_succeeds_; 2199 bool compile_shader_always_succeeds_;
2164 2200
2165 // An optional behaviour to lose the context and group when OOM. 2201 // An optional behaviour to lose the context and group when OOM.
2166 bool lose_context_when_out_of_memory_; 2202 bool lose_context_when_out_of_memory_;
2167 2203
2204 // Forces the backbuffer to use native GMBs rather than a TEXTURE_2D texture.
2205 bool should_use_native_gmb_for_backbuffer_;
2206
2168 // Log extra info. 2207 // Log extra info.
2169 bool service_logging_; 2208 bool service_logging_;
2170 2209
2171 std::unique_ptr<ApplyFramebufferAttachmentCMAAINTELResourceManager> 2210 std::unique_ptr<ApplyFramebufferAttachmentCMAAINTELResourceManager>
2172 apply_framebuffer_attachment_cmaa_intel_; 2211 apply_framebuffer_attachment_cmaa_intel_;
2173 std::unique_ptr<CopyTexImageResourceManager> copy_tex_image_blit_; 2212 std::unique_ptr<CopyTexImageResourceManager> copy_tex_image_blit_;
2174 std::unique_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; 2213 std::unique_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_;
2175 std::unique_ptr<ClearFramebufferResourceManager> clear_framebuffer_blit_; 2214 std::unique_ptr<ClearFramebufferResourceManager> clear_framebuffer_blit_;
2176 2215
2177 // Cached values of the currently assigned viewport dimensions. 2216 // Cached values of the currently assigned viewport dimensions.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2323 GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) 2362 GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal)
2324 : decoder_(decoder) { 2363 : decoder_(decoder) {
2325 resolve_and_bind_ = ( 2364 resolve_and_bind_ = (
2326 decoder_->offscreen_target_frame_buffer_.get() && 2365 decoder_->offscreen_target_frame_buffer_.get() &&
2327 decoder_->IsOffscreenBufferMultisampled() && 2366 decoder_->IsOffscreenBufferMultisampled() &&
2328 (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || 2367 (!decoder_->framebuffer_state_.bound_read_framebuffer.get() ||
2329 enforce_internal_framebuffer)); 2368 enforce_internal_framebuffer));
2330 if (!resolve_and_bind_) 2369 if (!resolve_and_bind_)
2331 return; 2370 return;
2332 2371
2372 // TODO(erikchen): On old AMD GPUs on macOS, glColorMask doesn't work
2373 // correctly for multisampled renderbuffers and the alpha channel can be
2374 // overwritten. Add a workaround to clear the alpha channel before resolving.
2375 // https://crbug.com/602484.
2333 ScopedGLErrorSuppressor suppressor( 2376 ScopedGLErrorSuppressor suppressor(
2334 "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); 2377 "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState());
2335 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 2378 glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT,
2336 decoder_->offscreen_target_frame_buffer_->id()); 2379 decoder_->offscreen_target_frame_buffer_->id());
2337 GLuint targetid; 2380 GLuint targetid;
2338 if (internal) { 2381 if (internal) {
2339 if (!decoder_->offscreen_resolved_frame_buffer_.get()) { 2382 if (!decoder_->offscreen_resolved_frame_buffer_.get()) {
2340 decoder_->offscreen_resolved_frame_buffer_.reset( 2383 decoder_->offscreen_resolved_frame_buffer_.reset(
2341 new BackFramebuffer(decoder_)); 2384 new BackFramebuffer(decoder_));
2342 decoder_->offscreen_resolved_frame_buffer_->Create(); 2385 decoder_->offscreen_resolved_frame_buffer_->Create();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2421 2464
2422 ScopedFrameBufferReadPixelHelper::~ScopedFrameBufferReadPixelHelper() { 2465 ScopedFrameBufferReadPixelHelper::~ScopedFrameBufferReadPixelHelper() {
2423 fbo_binder_.reset(); 2466 fbo_binder_.reset();
2424 glDeleteTextures(1, &temp_texture_id_); 2467 glDeleteTextures(1, &temp_texture_id_);
2425 glDeleteFramebuffersEXT(1, &temp_fbo_id_); 2468 glDeleteFramebuffersEXT(1, &temp_fbo_id_);
2426 } 2469 }
2427 2470
2428 BackTexture::BackTexture(GLES2DecoderImpl* decoder) 2471 BackTexture::BackTexture(GLES2DecoderImpl* decoder)
2429 : memory_tracker_(decoder->memory_tracker()), 2472 : memory_tracker_(decoder->memory_tracker()),
2430 bytes_allocated_(0), 2473 bytes_allocated_(0),
2431 decoder_(decoder) {} 2474 decoder_(decoder) {
2475 DCHECK(!decoder_->should_use_native_gmb_for_backbuffer_ ||
2476 decoder_->GetContextGroup()->image_factory());
2477 }
2432 2478
2433 BackTexture::~BackTexture() { 2479 BackTexture::~BackTexture() {
2434 // This does not destroy the render texture because that would require that 2480 // This does not destroy the render texture because that would require that
2435 // the associated GL context was current. Just check that it was explicitly 2481 // the associated GL context was current. Just check that it was explicitly
2436 // destroyed. 2482 // destroyed.
2437 DCHECK_EQ(id(), 0u); 2483 DCHECK_EQ(id(), 0u);
2484 DCHECK(!image_.get());
2438 } 2485 }
2439 2486
2440 void BackTexture::Create() { 2487 void BackTexture::Create() {
2441 DCHECK_EQ(id(), 0u); 2488 DCHECK_EQ(id(), 0u);
2442 ScopedGLErrorSuppressor suppressor("BackTexture::Create", 2489 ScopedGLErrorSuppressor suppressor("BackTexture::Create",
2443 decoder_->state_.GetErrorState()); 2490 decoder_->state_.GetErrorState());
2444 GLuint id; 2491 GLuint id;
2445 glGenTextures(1, &id); 2492 glGenTextures(1, &id);
2446 2493
2447 GLenum target = GL_TEXTURE_2D; 2494 GLenum target = Target();
2448 ScopedTextureBinder binder(&decoder_->state_, id, target); 2495 ScopedTextureBinder binder(&decoder_->state_, id, target);
2449 2496
2450 // No client id is necessary because this texture will never be directly 2497 // No client id is necessary because this texture will never be directly
2451 // accessed by a client, only indirectly via a mailbox. 2498 // accessed by a client, only indirectly via a mailbox.
2452 texture_ref_ = TextureRef::Create(decoder_->texture_manager(), 0, id); 2499 texture_ref_ = TextureRef::Create(decoder_->texture_manager(), 0, id);
2453 decoder_->texture_manager()->SetTarget(texture_ref_.get(), target); 2500 decoder_->texture_manager()->SetTarget(texture_ref_.get(), target);
2454 decoder_->texture_manager()->SetParameteri( 2501 decoder_->texture_manager()->SetParameteri(
2455 "BackTexture::Create", 2502 "BackTexture::Create",
2456 decoder_->GetErrorState(), 2503 decoder_->GetErrorState(),
2457 texture_ref_.get(), 2504 texture_ref_.get(),
(...skipping 17 matching lines...) Expand all
2475 texture_ref_.get(), 2522 texture_ref_.get(),
2476 GL_TEXTURE_WRAP_T, 2523 GL_TEXTURE_WRAP_T,
2477 GL_CLAMP_TO_EDGE); 2524 GL_CLAMP_TO_EDGE);
2478 } 2525 }
2479 2526
2480 bool BackTexture::AllocateStorage( 2527 bool BackTexture::AllocateStorage(
2481 const gfx::Size& size, GLenum format, bool zero) { 2528 const gfx::Size& size, GLenum format, bool zero) {
2482 DCHECK_NE(id(), 0u); 2529 DCHECK_NE(id(), 0u);
2483 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", 2530 ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage",
2484 decoder_->state_.GetErrorState()); 2531 decoder_->state_.GetErrorState());
2485 ScopedTextureBinder binder(&decoder_->state_, id(), GL_TEXTURE_2D); 2532 ScopedTextureBinder binder(&decoder_->state_, id(), Target());
2486 uint32_t image_size = 0; 2533 uint32_t image_size = 0;
2487 GLES2Util::ComputeImageDataSizes( 2534 GLES2Util::ComputeImageDataSizes(
2488 size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size, 2535 size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size,
2489 NULL, NULL); 2536 NULL, NULL);
2490 2537
2491 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { 2538 if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) {
2492 return false; 2539 return false;
2493 } 2540 }
2494 2541
2495 std::unique_ptr<char[]> zero_data; 2542 bool success = false;
2496 if (zero) { 2543 size_ = size;
2497 zero_data.reset(new char[image_size]); 2544 if (decoder_->should_use_native_gmb_for_backbuffer_) {
2498 memset(zero_data.get(), 0, image_size); 2545 DestroyNativeGpuMemoryBuffer(true);
2546 success = AllocateNativeGpuMemoryBuffer(size, format, zero);
2547 } else {
2548 std::unique_ptr<char[]> zero_data;
2549 if (zero) {
2550 zero_data.reset(new char[image_size]);
2551 memset(zero_data.get(), 0, image_size);
2552 }
2553
2554 glTexImage2D(Target(),
2555 0, // mip level
2556 format, size.width(), size.height(),
2557 0, // border
2558 format, GL_UNSIGNED_BYTE, zero_data.get());
2559 decoder_->texture_manager()->SetLevelInfo(
2560 texture_ref_.get(), Target(),
2561 0, // level
2562 GL_RGBA, size.width(), size.height(),
2563 1, // depth
2564 0, // border
2565 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(size));
2566 success = glGetError() == GL_NO_ERROR;
2499 } 2567 }
2500 2568
2501 glTexImage2D(GL_TEXTURE_2D,
2502 0, // mip level
2503 format,
2504 size.width(),
2505 size.height(),
2506 0, // border
2507 format,
2508 GL_UNSIGNED_BYTE,
2509 zero_data.get());
2510
2511 size_ = size;
2512 decoder_->texture_manager()->SetLevelInfo(texture_ref_.get(), GL_TEXTURE_2D,
2513 0, // level
2514 GL_RGBA, size_.width(), size_.height(),
2515 1, // depth
2516 0, // border
2517 GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(size_));
2518
2519 bool success = glGetError() == GL_NO_ERROR;
2520 if (success) { 2569 if (success) {
2521 memory_tracker_.TrackMemFree(bytes_allocated_); 2570 memory_tracker_.TrackMemFree(bytes_allocated_);
2522 bytes_allocated_ = image_size; 2571 bytes_allocated_ = image_size;
2523 memory_tracker_.TrackMemAlloc(bytes_allocated_); 2572 memory_tracker_.TrackMemAlloc(bytes_allocated_);
2524 } 2573 }
2525 return success; 2574 return success;
2526 } 2575 }
2527 2576
2528 void BackTexture::Copy(const gfx::Size& size, GLenum format) { 2577 void BackTexture::Copy(const gfx::Size& size, GLenum format) {
2529 DCHECK_NE(id(), 0u); 2578 DCHECK_NE(id(), 0u);
2530 ScopedGLErrorSuppressor suppressor("BackTexture::Copy", 2579 ScopedGLErrorSuppressor suppressor("BackTexture::Copy",
2531 decoder_->state_.GetErrorState()); 2580 decoder_->state_.GetErrorState());
2532 ScopedTextureBinder binder(&decoder_->state_, id(), GL_TEXTURE_2D); 2581 ScopedTextureBinder binder(&decoder_->state_, id(), Target());
2533 glCopyTexImage2D(GL_TEXTURE_2D, 2582 glCopyTexImage2D(Target(),
2534 0, // level 2583 0, // level
2535 format, 2584 format, 0, 0, size.width(), size.height(),
2536 0, 0,
2537 size.width(),
2538 size.height(),
2539 0); // border 2585 0); // border
2540 } 2586 }
2541 2587
2542 void BackTexture::Destroy() { 2588 void BackTexture::Destroy() {
2589 if (image_) {
2590 DCHECK(texture_ref_);
2591 ScopedTextureBinder binder(&decoder_->state_, id(), Target());
2592 DestroyNativeGpuMemoryBuffer(true);
2593 }
2594
2543 if (texture_ref_) { 2595 if (texture_ref_) {
2544 ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", 2596 ScopedGLErrorSuppressor suppressor("BackTexture::Destroy",
2545 decoder_->state_.GetErrorState()); 2597 decoder_->state_.GetErrorState());
2546 texture_ref_ = nullptr; 2598 texture_ref_ = nullptr;
2547 } 2599 }
2548 memory_tracker_.TrackMemFree(bytes_allocated_); 2600 memory_tracker_.TrackMemFree(bytes_allocated_);
2549 bytes_allocated_ = 0; 2601 bytes_allocated_ = 0;
2550 } 2602 }
2551 2603
2552 void BackTexture::Invalidate() { 2604 void BackTexture::Invalidate() {
2605 if (image_) {
2606 DestroyNativeGpuMemoryBuffer(false);
2607 image_ = nullptr;
2608 }
2553 if (texture_ref_) { 2609 if (texture_ref_) {
2554 texture_ref_->ForceContextLost(); 2610 texture_ref_->ForceContextLost();
2555 texture_ref_ = nullptr; 2611 texture_ref_ = nullptr;
2556 } 2612 }
2557 } 2613 }
2558 2614
2559 BackRenderbuffer::BackRenderbuffer( 2615 GLenum BackTexture::Target() {
2560 RenderbufferManager* renderbuffer_manager, 2616 return decoder_->should_use_native_gmb_for_backbuffer_
2561 MemoryTracker* memory_tracker, 2617 ? decoder_->GetContextGroup()
2562 ContextState* state) 2618 ->image_factory()
2563 : renderbuffer_manager_(renderbuffer_manager), 2619 ->RequiredTextureType()
2564 memory_tracker_(memory_tracker), 2620 : GL_TEXTURE_2D;
2565 state_(state), 2621 }
2622
2623 bool BackTexture::AllocateNativeGpuMemoryBuffer(const gfx::Size& size,
2624 GLenum format,
2625 bool zero) {
2626 gfx::BufferFormat buffer_format = gfx::BufferFormat::RGBA_8888;
2627 scoped_refptr<gl::GLImage> image =
2628 decoder_->GetContextGroup()->image_factory()->CreateAnonymousImage(
2629 size, buffer_format, format);
2630 if (!image || !image->BindTexImage(Target()))
2631 return false;
2632
2633 image_ = image;
2634 decoder_->texture_manager()->SetLevelInfo(
2635 texture_ref_.get(), Target(), 0, image_->GetInternalFormat(),
2636 size.width(), size.height(), 1, 0, image_->GetInternalFormat(),
2637 GL_UNSIGNED_BYTE, gfx::Rect(size));
2638 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0,
2639 image_.get(), Texture::BOUND);
2640
2641 // Ignore the zero flag if the alpha channel needs to be cleared for RGB
2642 // emulation.
2643 bool needs_clear_for_rgb_emulation =
2644 !decoder_->offscreen_buffer_should_have_alpha_ &&
2645 decoder_->ChromiumImageNeedsRGBEmulation();
2646 if (zero || needs_clear_for_rgb_emulation) {
2647 GLuint fbo;
2648 glGenFramebuffersEXT(1, &fbo);
2649 {
2650 ScopedFrameBufferBinder binder(decoder_, fbo);
2651 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, Target(),
2652 id(), 0);
2653 glClearColor(0, 0, 0, decoder_->BackBufferAlphaClearColor());
2654 decoder_->state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2655 decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
2656 glClear(GL_COLOR_BUFFER_BIT);
2657 decoder_->RestoreClearState();
2658 }
2659 glDeleteFramebuffersEXT(1, &fbo);
2660 }
2661 return true;
2662 }
2663
2664 void BackTexture::DestroyNativeGpuMemoryBuffer(bool have_context) {
2665 if (image_) {
2666 ScopedGLErrorSuppressor suppressor(
2667 "BackTexture::DestroyNativeGpuMemoryBuffer",
2668 decoder_->state_.GetErrorState());
2669
2670 image_->ReleaseTexImage(Target());
2671 image_->Destroy(have_context);
2672
2673 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0,
2674 nullptr, Texture::UNBOUND);
2675 image_ = nullptr;
2676 }
2677 }
2678
2679 BackRenderbuffer::BackRenderbuffer(GLES2DecoderImpl* decoder)
2680 : decoder_(decoder),
2681 memory_tracker_(decoder->memory_tracker()),
2566 bytes_allocated_(0), 2682 bytes_allocated_(0),
2567 id_(0) { 2683 id_(0) {}
2568 }
2569 2684
2570 BackRenderbuffer::~BackRenderbuffer() { 2685 BackRenderbuffer::~BackRenderbuffer() {
2571 // This does not destroy the render buffer because that would require that 2686 // This does not destroy the render buffer because that would require that
2572 // the associated GL context was current. Just check that it was explicitly 2687 // the associated GL context was current. Just check that it was explicitly
2573 // destroyed. 2688 // destroyed.
2574 DCHECK_EQ(id_, 0u); 2689 DCHECK_EQ(id_, 0u);
2575 } 2690 }
2576 2691
2577 void BackRenderbuffer::Create() { 2692 void BackRenderbuffer::Create() {
2578 ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", 2693 ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create",
2579 state_->GetErrorState()); 2694 decoder_->state_.GetErrorState());
2580 Destroy(); 2695 Destroy();
2581 glGenRenderbuffersEXT(1, &id_); 2696 glGenRenderbuffersEXT(1, &id_);
2582 } 2697 }
2583 2698
2584 bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info, 2699 bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info,
2585 const gfx::Size& size, 2700 const gfx::Size& size,
2586 GLenum format, 2701 GLenum format,
2587 GLsizei samples) { 2702 GLsizei samples) {
2588 ScopedGLErrorSuppressor suppressor( 2703 ScopedGLErrorSuppressor suppressor("BackRenderbuffer::AllocateStorage",
2589 "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); 2704 decoder_->state_.GetErrorState());
2590 ScopedRenderBufferBinder binder(state_, id_); 2705 ScopedRenderBufferBinder binder(&decoder_->state_, id_);
2591 2706
2592 uint32_t estimated_size = 0; 2707 uint32_t estimated_size = 0;
2593 if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( 2708 if (!decoder_->renderbuffer_manager()->ComputeEstimatedRenderbufferSize(
2594 size.width(), size.height(), samples, format, &estimated_size)) { 2709 size.width(), size.height(), samples, format, &estimated_size)) {
2595 return false; 2710 return false;
2596 } 2711 }
2597 2712
2598 if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { 2713 if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) {
2599 return false; 2714 return false;
2600 } 2715 }
2601 2716
2602 if (samples <= 1) { 2717 if (samples <= 1) {
2603 glRenderbufferStorageEXT(GL_RENDERBUFFER, 2718 glRenderbufferStorageEXT(GL_RENDERBUFFER,
2604 format, 2719 format,
2605 size.width(), 2720 size.width(),
2606 size.height()); 2721 size.height());
2607 } else { 2722 } else {
2608 GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info, 2723 GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info,
2609 GL_RENDERBUFFER, 2724 GL_RENDERBUFFER,
2610 samples, 2725 samples,
2611 format, 2726 format,
2612 size.width(), 2727 size.width(),
2613 size.height()); 2728 size.height());
2614 } 2729 }
2730
2731 bool alpha_channel_needs_clear =
2732 (format == GL_RGBA || format == GL_RGBA8) &&
2733 !decoder_->offscreen_buffer_should_have_alpha_;
2734 if (alpha_channel_needs_clear) {
2735 GLuint fbo;
2736 glGenFramebuffersEXT(1, &fbo);
2737 {
2738 ScopedFrameBufferBinder binder(decoder_, fbo);
2739 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2740 GL_RENDERBUFFER, id_);
2741 glClearColor(0, 0, 0, decoder_->BackBufferAlphaClearColor());
2742 decoder_->state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
2743 decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
2744 glClear(GL_COLOR_BUFFER_BIT);
2745 decoder_->RestoreClearState();
2746 }
2747 glDeleteFramebuffersEXT(1, &fbo);
2748 }
2749
2615 bool success = glGetError() == GL_NO_ERROR; 2750 bool success = glGetError() == GL_NO_ERROR;
2616 if (success) { 2751 if (success) {
2617 // Mark the previously allocated bytes as free. 2752 // Mark the previously allocated bytes as free.
2618 memory_tracker_.TrackMemFree(bytes_allocated_); 2753 memory_tracker_.TrackMemFree(bytes_allocated_);
2619 bytes_allocated_ = estimated_size; 2754 bytes_allocated_ = estimated_size;
2620 // Track the newly allocated bytes. 2755 // Track the newly allocated bytes.
2621 memory_tracker_.TrackMemAlloc(bytes_allocated_); 2756 memory_tracker_.TrackMemAlloc(bytes_allocated_);
2622 } 2757 }
2623 return success; 2758 return success;
2624 } 2759 }
2625 2760
2626 void BackRenderbuffer::Destroy() { 2761 void BackRenderbuffer::Destroy() {
2627 if (id_ != 0) { 2762 if (id_ != 0) {
2628 ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", 2763 ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy",
2629 state_->GetErrorState()); 2764 decoder_->state_.GetErrorState());
2630 glDeleteRenderbuffersEXT(1, &id_); 2765 glDeleteRenderbuffersEXT(1, &id_);
2631 id_ = 0; 2766 id_ = 0;
2632 } 2767 }
2633 memory_tracker_.TrackMemFree(bytes_allocated_); 2768 memory_tracker_.TrackMemFree(bytes_allocated_);
2634 bytes_allocated_ = 0; 2769 bytes_allocated_ = 0;
2635 } 2770 }
2636 2771
2637 void BackRenderbuffer::Invalidate() { 2772 void BackRenderbuffer::Invalidate() {
2638 id_ = 0; 2773 id_ = 0;
2639 } 2774 }
(...skipping 16 matching lines...) Expand all
2656 Destroy(); 2791 Destroy();
2657 glGenFramebuffersEXT(1, &id_); 2792 glGenFramebuffersEXT(1, &id_);
2658 } 2793 }
2659 2794
2660 void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { 2795 void BackFramebuffer::AttachRenderTexture(BackTexture* texture) {
2661 DCHECK_NE(id_, 0u); 2796 DCHECK_NE(id_, 0u);
2662 ScopedGLErrorSuppressor suppressor( 2797 ScopedGLErrorSuppressor suppressor(
2663 "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); 2798 "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState());
2664 ScopedFrameBufferBinder binder(decoder_, id_); 2799 ScopedFrameBufferBinder binder(decoder_, id_);
2665 GLuint attach_id = texture ? texture->id() : 0; 2800 GLuint attach_id = texture ? texture->id() : 0;
2666 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, 2801 glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2667 GL_COLOR_ATTACHMENT0, 2802 texture->Target(), attach_id, 0);
2668 GL_TEXTURE_2D,
2669 attach_id,
2670 0);
2671 } 2803 }
2672 2804
2673 void BackFramebuffer::AttachRenderBuffer(GLenum target, 2805 void BackFramebuffer::AttachRenderBuffer(GLenum target,
2674 BackRenderbuffer* render_buffer) { 2806 BackRenderbuffer* render_buffer) {
2675 DCHECK_NE(id_, 0u); 2807 DCHECK_NE(id_, 0u);
2676 ScopedGLErrorSuppressor suppressor( 2808 ScopedGLErrorSuppressor suppressor(
2677 "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); 2809 "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState());
2678 ScopedFrameBufferBinder binder(decoder_, id_); 2810 ScopedFrameBufferBinder binder(decoder_, id_);
2679 GLuint attach_id = render_buffer ? render_buffer->id() : 0; 2811 GLuint attach_id = render_buffer ? render_buffer->id() : 0;
2680 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, 2812 glFramebufferRenderbufferEXT(GL_FRAMEBUFFER,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 attrib_0_buffer_matches_value_(true), 2852 attrib_0_buffer_matches_value_(true),
2721 attrib_0_size_(0), 2853 attrib_0_size_(0),
2722 fixed_attrib_buffer_id_(0), 2854 fixed_attrib_buffer_id_(0),
2723 fixed_attrib_buffer_size_(0), 2855 fixed_attrib_buffer_size_(0),
2724 offscreen_target_color_format_(0), 2856 offscreen_target_color_format_(0),
2725 offscreen_target_depth_format_(0), 2857 offscreen_target_depth_format_(0),
2726 offscreen_target_stencil_format_(0), 2858 offscreen_target_stencil_format_(0),
2727 offscreen_target_samples_(0), 2859 offscreen_target_samples_(0),
2728 offscreen_target_buffer_preserved_(true), 2860 offscreen_target_buffer_preserved_(true),
2729 offscreen_saved_color_format_(0), 2861 offscreen_saved_color_format_(0),
2862 offscreen_buffer_should_have_alpha_(false),
2730 back_buffer_color_format_(0), 2863 back_buffer_color_format_(0),
2731 back_buffer_has_depth_(false), 2864 back_buffer_has_depth_(false),
2732 back_buffer_has_stencil_(false), 2865 back_buffer_has_stencil_(false),
2733 back_buffer_read_buffer_(GL_BACK), 2866 back_buffer_read_buffer_(GL_BACK),
2734 back_buffer_draw_buffer_(GL_BACK), 2867 back_buffer_draw_buffer_(GL_BACK),
2735 surfaceless_(false), 2868 surfaceless_(false),
2736 backbuffer_needs_clear_bits_(0), 2869 backbuffer_needs_clear_bits_(0),
2737 swaps_since_resize_(0), 2870 swaps_since_resize_(0),
2738 current_decoder_error_(error::kNoError), 2871 current_decoder_error_(error::kNoError),
2739 validators_(group_->feature_info()->validators()), 2872 validators_(group_->feature_info()->validators()),
2740 feature_info_(group_->feature_info()), 2873 feature_info_(group_->feature_info()),
2741 frame_number_(0), 2874 frame_number_(0),
2742 has_robustness_extension_(false), 2875 has_robustness_extension_(false),
2743 context_lost_reason_(error::kUnknown), 2876 context_lost_reason_(error::kUnknown),
2744 context_was_lost_(false), 2877 context_was_lost_(false),
2745 reset_by_robustness_extension_(false), 2878 reset_by_robustness_extension_(false),
2746 supports_post_sub_buffer_(false), 2879 supports_post_sub_buffer_(false),
2747 supports_commit_overlay_planes_(false), 2880 supports_commit_overlay_planes_(false),
2748 supports_async_swap_(false), 2881 supports_async_swap_(false),
2749 context_type_(CONTEXT_TYPE_OPENGLES2), 2882 context_type_(CONTEXT_TYPE_OPENGLES2),
2750 derivatives_explicitly_enabled_(false), 2883 derivatives_explicitly_enabled_(false),
2751 frag_depth_explicitly_enabled_(false), 2884 frag_depth_explicitly_enabled_(false),
2752 draw_buffers_explicitly_enabled_(false), 2885 draw_buffers_explicitly_enabled_(false),
2753 shader_texture_lod_explicitly_enabled_(false), 2886 shader_texture_lod_explicitly_enabled_(false),
2754 compile_shader_always_succeeds_(false), 2887 compile_shader_always_succeeds_(false),
2755 lose_context_when_out_of_memory_(false), 2888 lose_context_when_out_of_memory_(false),
2889 should_use_native_gmb_for_backbuffer_(false),
2756 service_logging_( 2890 service_logging_(
2757 group_->gpu_preferences().enable_gpu_service_logging_gpu), 2891 group_->gpu_preferences().enable_gpu_service_logging_gpu),
2758 viewport_max_width_(0), 2892 viewport_max_width_(0),
2759 viewport_max_height_(0), 2893 viewport_max_height_(0),
2760 texture_state_(group_->feature_info()->workarounds()), 2894 texture_state_(group_->feature_info()->workarounds()),
2761 gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( 2895 gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(
2762 TRACE_DISABLED_BY_DEFAULT("gpu_decoder"))), 2896 TRACE_DISABLED_BY_DEFAULT("gpu_decoder"))),
2763 gpu_trace_level_(2), 2897 gpu_trace_level_(2),
2764 gpu_trace_commands_(false), 2898 gpu_trace_commands_(false),
2765 gpu_debug_commands_(false), 2899 gpu_debug_commands_(false),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 if (feature_info_->workarounds().disable_timestamp_queries) { 2945 if (feature_info_->workarounds().disable_timestamp_queries) {
2812 // Forcing time elapsed query for any GPU Timing Client forces it for all 2946 // Forcing time elapsed query for any GPU Timing Client forces it for all
2813 // clients in the context. 2947 // clients in the context.
2814 GetGLContext()->CreateGPUTimingClient()->ForceTimeElapsedQuery(); 2948 GetGLContext()->CreateGPUTimingClient()->ForceTimeElapsedQuery();
2815 } 2949 }
2816 2950
2817 // Save the loseContextWhenOutOfMemory context creation attribute. 2951 // Save the loseContextWhenOutOfMemory context creation attribute.
2818 lose_context_when_out_of_memory_ = 2952 lose_context_when_out_of_memory_ =
2819 attrib_helper.lose_context_when_out_of_memory; 2953 attrib_helper.lose_context_when_out_of_memory;
2820 2954
2955 should_use_native_gmb_for_backbuffer_ =
2956 attrib_helper.should_use_native_gmb_for_backbuffer;
2957 if (should_use_native_gmb_for_backbuffer_) {
2958 gpu::ImageFactory* image_factory = group_->image_factory();
2959 bool supported = false;
2960 if (image_factory) {
2961 switch (image_factory->RequiredTextureType()) {
2962 case GL_TEXTURE_RECTANGLE_ARB:
2963 supported = feature_info_->feature_flags().arb_texture_rectangle;
2964 break;
2965 case GL_TEXTURE_2D:
2966 supported = true;
2967 break;
2968 default:
2969 break;
2970 }
2971 }
2972
2973 if (!supported) {
2974 group_ = NULL; // Must not destroy ContextGroup if it is not initialized.
2975 Destroy(true);
2976 return false;
2977 }
2978 }
2979
2821 // If the failIfMajorPerformanceCaveat context creation attribute was true 2980 // If the failIfMajorPerformanceCaveat context creation attribute was true
2822 // and we are using a software renderer, fail. 2981 // and we are using a software renderer, fail.
2823 if (attrib_helper.fail_if_major_perf_caveat && 2982 if (attrib_helper.fail_if_major_perf_caveat &&
2824 feature_info_->feature_flags().is_swiftshader) { 2983 feature_info_->feature_flags().is_swiftshader) {
2825 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. 2984 group_ = NULL; // Must not destroy ContextGroup if it is not initialized.
2826 Destroy(true); 2985 Destroy(true);
2827 return false; 2986 return false;
2828 } 2987 }
2829 2988
2830 if (!group_->Initialize(this, attrib_helper.context_type, 2989 if (!group_->Initialize(this, attrib_helper.context_type,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
2929 state_.texture_units[tt].bound_texture_2d = ref; 3088 state_.texture_units[tt].bound_texture_2d = ref;
2930 glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); 3089 glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0);
2931 } 3090 }
2932 glActiveTexture(GL_TEXTURE0); 3091 glActiveTexture(GL_TEXTURE0);
2933 CHECK_GL_ERROR(); 3092 CHECK_GL_ERROR();
2934 3093
2935 // cache ALPHA_BITS result for re-use with clear behaviour 3094 // cache ALPHA_BITS result for re-use with clear behaviour
2936 GLint alpha_bits = 0; 3095 GLint alpha_bits = 0;
2937 3096
2938 if (offscreen) { 3097 if (offscreen) {
3098 offscreen_buffer_should_have_alpha_ = attrib_helper.alpha_size > 0;
3099
3100 // Whether the offscreen buffer texture should have an alpha channel. Does
3101 // not include logic from workarounds.
3102 bool offscreen_buffer_texture_needs_alpha =
3103 offscreen_buffer_should_have_alpha_ ||
3104 (ChromiumImageNeedsRGBEmulation() &&
3105 attrib_helper.should_use_native_gmb_for_backbuffer);
3106
2939 if (attrib_helper.samples > 0 && attrib_helper.sample_buffers > 0 && 3107 if (attrib_helper.samples > 0 && attrib_helper.sample_buffers > 0 &&
2940 features().chromium_framebuffer_multisample) { 3108 features().chromium_framebuffer_multisample) {
2941 // Per ext_framebuffer_multisample spec, need max bound on sample count. 3109 // Per ext_framebuffer_multisample spec, need max bound on sample count.
2942 // max_sample_count must be initialized to a sane value. If 3110 // max_sample_count must be initialized to a sane value. If
2943 // glGetIntegerv() throws a GL error, it leaves its argument unchanged. 3111 // glGetIntegerv() throws a GL error, it leaves its argument unchanged.
2944 GLint max_sample_count = 1; 3112 GLint max_sample_count = 1;
2945 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); 3113 glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count);
2946 offscreen_target_samples_ = std::min(attrib_helper.samples, 3114 offscreen_target_samples_ = std::min(attrib_helper.samples,
2947 max_sample_count); 3115 max_sample_count);
2948 } else { 3116 } else {
2949 offscreen_target_samples_ = 1; 3117 offscreen_target_samples_ = 1;
2950 } 3118 }
2951 offscreen_target_buffer_preserved_ = attrib_helper.buffer_preserved; 3119 offscreen_target_buffer_preserved_ = attrib_helper.buffer_preserved;
2952 3120
2953 if (gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2) { 3121 if (gl::GetGLImplementation() == gl::kGLImplementationEGLGLES2) {
2954 const bool rgb8_supported = 3122 const bool rgb8_supported =
2955 context_->HasExtension("GL_OES_rgb8_rgba8"); 3123 context_->HasExtension("GL_OES_rgb8_rgba8");
2956 // The only available default render buffer formats in GLES2 have very 3124 // The only available default render buffer formats in GLES2 have very
2957 // little precision. Don't enable multisampling unless 8-bit render 3125 // little precision. Don't enable multisampling unless 8-bit render
2958 // buffer formats are available--instead fall back to 8-bit textures. 3126 // buffer formats are available--instead fall back to 8-bit textures.
2959 if (rgb8_supported && offscreen_target_samples_ > 1) { 3127 if (rgb8_supported && offscreen_target_samples_ > 1) {
2960 offscreen_target_color_format_ = attrib_helper.alpha_size > 0 ? 3128 offscreen_target_color_format_ =
2961 GL_RGBA8 : GL_RGB8; 3129 offscreen_buffer_texture_needs_alpha ? GL_RGBA8 : GL_RGB8;
2962 } else { 3130 } else {
2963 offscreen_target_samples_ = 1; 3131 offscreen_target_samples_ = 1;
2964 offscreen_target_color_format_ = 3132 offscreen_target_color_format_ =
2965 attrib_helper.alpha_size > 0 || workarounds().disable_gl_rgb_format 3133 offscreen_buffer_texture_needs_alpha ||
3134 workarounds().disable_gl_rgb_format
2966 ? GL_RGBA 3135 ? GL_RGBA
2967 : GL_RGB; 3136 : GL_RGB;
2968 } 3137 }
2969 3138
2970 // ANGLE only supports packed depth/stencil formats, so use it if it is 3139 // ANGLE only supports packed depth/stencil formats, so use it if it is
2971 // available. 3140 // available.
2972 const bool depth24_stencil8_supported = 3141 const bool depth24_stencil8_supported =
2973 feature_info_->feature_flags().packed_depth24_stencil8; 3142 feature_info_->feature_flags().packed_depth24_stencil8;
2974 VLOG(1) << "GL_OES_packed_depth_stencil " 3143 VLOG(1) << "GL_OES_packed_depth_stencil "
2975 << (depth24_stencil8_supported ? "" : "not ") << "supported."; 3144 << (depth24_stencil8_supported ? "" : "not ") << "supported.";
2976 if ((attrib_helper.depth_size > 0 || attrib_helper.stencil_size > 0) && 3145 if ((attrib_helper.depth_size > 0 || attrib_helper.stencil_size > 0) &&
2977 depth24_stencil8_supported) { 3146 depth24_stencil8_supported) {
2978 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; 3147 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8;
2979 offscreen_target_stencil_format_ = 0; 3148 offscreen_target_stencil_format_ = 0;
2980 } else { 3149 } else {
2981 // It may be the case that this depth/stencil combination is not 3150 // It may be the case that this depth/stencil combination is not
2982 // supported, but this will be checked later by CheckFramebufferStatus. 3151 // supported, but this will be checked later by CheckFramebufferStatus.
2983 offscreen_target_depth_format_ = attrib_helper.depth_size > 0 ? 3152 offscreen_target_depth_format_ = attrib_helper.depth_size > 0 ?
2984 GL_DEPTH_COMPONENT16 : 0; 3153 GL_DEPTH_COMPONENT16 : 0;
2985 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ? 3154 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ?
2986 GL_STENCIL_INDEX8 : 0; 3155 GL_STENCIL_INDEX8 : 0;
2987 } 3156 }
2988 } else { 3157 } else {
2989 offscreen_target_color_format_ = 3158 offscreen_target_color_format_ =
2990 attrib_helper.alpha_size > 0 || workarounds().disable_gl_rgb_format 3159 offscreen_buffer_texture_needs_alpha ||
3160 workarounds().disable_gl_rgb_format
2991 ? GL_RGBA 3161 ? GL_RGBA
2992 : GL_RGB; 3162 : GL_RGB;
2993 3163
2994 // If depth is requested at all, use the packed depth stencil format if 3164 // If depth is requested at all, use the packed depth stencil format if
2995 // it's available, as some desktop GL drivers don't support any non-packed 3165 // it's available, as some desktop GL drivers don't support any non-packed
2996 // formats for depth attachments. 3166 // formats for depth attachments.
2997 const bool depth24_stencil8_supported = 3167 const bool depth24_stencil8_supported =
2998 feature_info_->feature_flags().packed_depth24_stencil8; 3168 feature_info_->feature_flags().packed_depth24_stencil8;
2999 VLOG(1) << "GL_EXT_packed_depth_stencil " 3169 VLOG(1) << "GL_EXT_packed_depth_stencil "
3000 << (depth24_stencil8_supported ? "" : "not ") << "supported."; 3170 << (depth24_stencil8_supported ? "" : "not ") << "supported.";
3001 3171
3002 if ((attrib_helper.depth_size > 0 || attrib_helper.stencil_size > 0) && 3172 if ((attrib_helper.depth_size > 0 || attrib_helper.stencil_size > 0) &&
3003 depth24_stencil8_supported) { 3173 depth24_stencil8_supported) {
3004 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; 3174 offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8;
3005 offscreen_target_stencil_format_ = 0; 3175 offscreen_target_stencil_format_ = 0;
3006 } else { 3176 } else {
3007 offscreen_target_depth_format_ = attrib_helper.depth_size > 0 ? 3177 offscreen_target_depth_format_ = attrib_helper.depth_size > 0 ?
3008 GL_DEPTH_COMPONENT : 0; 3178 GL_DEPTH_COMPONENT : 0;
3009 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ? 3179 offscreen_target_stencil_format_ = attrib_helper.stencil_size > 0 ?
3010 GL_STENCIL_INDEX : 0; 3180 GL_STENCIL_INDEX : 0;
3011 } 3181 }
3012 } 3182 }
3013 3183
3014 offscreen_saved_color_format_ = 3184 offscreen_saved_color_format_ = offscreen_buffer_texture_needs_alpha ||
3015 attrib_helper.alpha_size > 0 || workarounds().disable_gl_rgb_format 3185 workarounds().disable_gl_rgb_format
3016 ? GL_RGBA 3186 ? GL_RGBA
3017 : GL_RGB; 3187 : GL_RGB;
3018 3188
3019 // Create the target frame buffer. This is the one that the client renders 3189 // Create the target frame buffer. This is the one that the client renders
3020 // directly to. 3190 // directly to.
3021 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); 3191 offscreen_target_frame_buffer_.reset(new BackFramebuffer(this));
3022 offscreen_target_frame_buffer_->Create(); 3192 offscreen_target_frame_buffer_->Create();
3023 // Due to GLES2 format limitations, either the color texture (for 3193 // Due to GLES2 format limitations, either the color texture (for
3024 // non-multisampling) or the color render buffer (for multisampling) will be 3194 // non-multisampling) or the color render buffer (for multisampling) will be
3025 // attached to the offscreen frame buffer. The render buffer has more 3195 // attached to the offscreen frame buffer. The render buffer has more
3026 // limited formats available to it, but the texture can't do multisampling. 3196 // limited formats available to it, but the texture can't do multisampling.
3027 if (IsOffscreenBufferMultisampled()) { 3197 if (IsOffscreenBufferMultisampled()) {
3028 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( 3198 offscreen_target_color_render_buffer_.reset(new BackRenderbuffer(this));
3029 renderbuffer_manager(), memory_tracker(), &state_));
3030 offscreen_target_color_render_buffer_->Create(); 3199 offscreen_target_color_render_buffer_->Create();
3031 } else { 3200 } else {
3032 offscreen_target_color_texture_.reset(new BackTexture(this)); 3201 offscreen_target_color_texture_.reset(new BackTexture(this));
3033 offscreen_target_color_texture_->Create(); 3202 offscreen_target_color_texture_->Create();
3034 } 3203 }
3035 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( 3204 offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer(this));
3036 renderbuffer_manager(), memory_tracker(), &state_));
3037 offscreen_target_depth_render_buffer_->Create(); 3205 offscreen_target_depth_render_buffer_->Create();
3038 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( 3206 offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer(this));
3039 renderbuffer_manager(), memory_tracker(), &state_));
3040 offscreen_target_stencil_render_buffer_->Create(); 3207 offscreen_target_stencil_render_buffer_->Create();
3041 3208
3042 // Create the saved offscreen texture. The target frame buffer is copied 3209 // Create the saved offscreen texture. The target frame buffer is copied
3043 // here when SwapBuffers is called. 3210 // here when SwapBuffers is called.
3044 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); 3211 offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this));
3045 offscreen_saved_frame_buffer_->Create(); 3212 offscreen_saved_frame_buffer_->Create();
3046 // 3213 //
3047 offscreen_saved_color_texture_.reset(new BackTexture(this)); 3214 offscreen_saved_color_texture_.reset(new BackTexture(this));
3048 offscreen_saved_color_texture_->Create(); 3215 offscreen_saved_color_texture_->Create();
3049 3216
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; 3509 feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture;
3343 caps.texture_format_etc1_npot = 3510 caps.texture_format_etc1_npot =
3344 caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; 3511 caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only;
3345 caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; 3512 caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle;
3346 caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; 3513 caps.texture_usage = feature_info_->feature_flags().angle_texture_usage;
3347 caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; 3514 caps.texture_storage = feature_info_->feature_flags().ext_texture_storage;
3348 caps.discard_framebuffer = 3515 caps.discard_framebuffer =
3349 feature_info_->feature_flags().ext_discard_framebuffer; 3516 feature_info_->feature_flags().ext_discard_framebuffer;
3350 caps.sync_query = feature_info_->feature_flags().chromium_sync_query; 3517 caps.sync_query = feature_info_->feature_flags().chromium_sync_query;
3351 3518
3519 caps.chromium_image_rgb_emulation = ChromiumImageNeedsRGBEmulation();
3352 #if defined(OS_MACOSX) 3520 #if defined(OS_MACOSX)
3353 // This is unconditionally true on mac, no need to test for it at runtime. 3521 // This is unconditionally true on mac, no need to test for it at runtime.
3354 caps.iosurface = true; 3522 caps.iosurface = true;
3355 caps.chromium_image_rgb_emulation = true;
3356 #endif 3523 #endif
3357 3524
3358 caps.post_sub_buffer = supports_post_sub_buffer_; 3525 caps.post_sub_buffer = supports_post_sub_buffer_;
3359 caps.commit_overlay_planes = supports_commit_overlay_planes_; 3526 caps.commit_overlay_planes = supports_commit_overlay_planes_;
3360 caps.image = true; 3527 caps.image = true;
3361 caps.surfaceless = surfaceless_; 3528 caps.surfaceless = surfaceless_;
3362 bool is_offscreen = !!offscreen_target_frame_buffer_.get(); 3529 bool is_offscreen = !!offscreen_target_frame_buffer_.get();
3363 caps.flips_vertically = !is_offscreen && surface_->FlipsVertically(); 3530 caps.flips_vertically = !is_offscreen && surface_->FlipsVertically();
3364 caps.msaa_is_slow = feature_info_->workarounds().msaa_is_slow; 3531 caps.msaa_is_slow = feature_info_->workarounds().msaa_is_slow;
3365 3532
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
3908 bool GLES2DecoderImpl::CheckFramebufferValid( 4075 bool GLES2DecoderImpl::CheckFramebufferValid(
3909 Framebuffer* framebuffer, 4076 Framebuffer* framebuffer,
3910 GLenum target, 4077 GLenum target,
3911 bool clear_uncleared_images, 4078 bool clear_uncleared_images,
3912 GLenum gl_error, 4079 GLenum gl_error,
3913 const char* func_name) { 4080 const char* func_name) {
3914 if (!framebuffer) { 4081 if (!framebuffer) {
3915 if (surfaceless_) 4082 if (surfaceless_)
3916 return false; 4083 return false;
3917 if (backbuffer_needs_clear_bits_ && clear_uncleared_images) { 4084 if (backbuffer_needs_clear_bits_ && clear_uncleared_images) {
3918 glClearColor(0, 0, 0, BackBufferHasAlpha() ? 0 : 1.f); 4085 glClearColor(0, 0, 0, BackBufferAlphaClearColor());
3919 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 4086 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
3920 glClearStencil(0); 4087 glClearStencil(0);
3921 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); 4088 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask);
3922 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); 4089 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask);
3923 glClearDepth(1.0f); 4090 glClearDepth(1.0f);
3924 state_.SetDeviceDepthMask(GL_TRUE); 4091 state_.SetDeviceDepthMask(GL_TRUE);
3925 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); 4092 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
3926 bool reset_draw_buffer = false; 4093 bool reset_draw_buffer = false;
3927 if ((backbuffer_needs_clear_bits_ & GL_COLOR_BUFFER_BIT) != 0 && 4094 if ((backbuffer_needs_clear_bits_ & GL_COLOR_BUFFER_BIT) != 0 &&
3928 back_buffer_draw_buffer_ == GL_NONE) { 4095 back_buffer_draw_buffer_ == GL_NONE) {
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
4575 if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { 4742 if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) {
4576 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 4743 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
4577 << "to allocate storage due to excessive dimensions."; 4744 << "to allocate storage due to excessive dimensions.";
4578 return false; 4745 return false;
4579 } 4746 }
4580 4747
4581 // Reallocate the offscreen target buffers. 4748 // Reallocate the offscreen target buffers.
4582 DCHECK(offscreen_target_color_format_); 4749 DCHECK(offscreen_target_color_format_);
4583 if (IsOffscreenBufferMultisampled()) { 4750 if (IsOffscreenBufferMultisampled()) {
4584 if (!offscreen_target_color_render_buffer_->AllocateStorage( 4751 if (!offscreen_target_color_render_buffer_->AllocateStorage(
4585 feature_info_.get(), 4752 feature_info_.get(), offscreen_size_,
4586 offscreen_size_, 4753 offscreen_target_color_format_, offscreen_target_samples_)) {
4587 offscreen_target_color_format_,
4588 offscreen_target_samples_)) {
4589 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 4754 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
4590 << "to allocate storage for offscreen target color buffer."; 4755 << "to allocate storage for offscreen target color buffer.";
4591 return false; 4756 return false;
4592 } 4757 }
4593 } else { 4758 } else {
4594 if (!offscreen_target_color_texture_->AllocateStorage( 4759 if (!offscreen_target_color_texture_->AllocateStorage(
4595 offscreen_size_, offscreen_target_color_format_, false)) { 4760 offscreen_size_, offscreen_target_color_format_, false)) {
4596 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 4761 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
4597 << "to allocate storage for offscreen target color texture."; 4762 << "to allocate storage for offscreen target color texture.";
4598 return false; 4763 return false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
4648 if (offscreen_target_frame_buffer_->CheckStatus() != 4813 if (offscreen_target_frame_buffer_->CheckStatus() !=
4649 GL_FRAMEBUFFER_COMPLETE) { 4814 GL_FRAMEBUFFER_COMPLETE) {
4650 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " 4815 LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed "
4651 << "because offscreen FBO was incomplete."; 4816 << "because offscreen FBO was incomplete.";
4652 return false; 4817 return false;
4653 } 4818 }
4654 4819
4655 // Clear the target frame buffer. 4820 // Clear the target frame buffer.
4656 { 4821 {
4657 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); 4822 ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id());
4658 glClearColor(0, 0, 0, BackBufferHasAlpha() ? 0 : 1.f); 4823 glClearColor(0, 0, 0, BackBufferAlphaClearColor());
4659 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 4824 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
4660 glClearStencil(0); 4825 glClearStencil(0);
4661 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); 4826 state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask);
4662 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); 4827 state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask);
4663 glClearDepth(0); 4828 glClearDepth(0);
4664 state_.SetDeviceDepthMask(GL_TRUE); 4829 state_.SetDeviceDepthMask(GL_TRUE);
4665 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); 4830 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
4666 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); 4831 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
4667 RestoreClearState(); 4832 RestoreClearState();
4668 } 4833 }
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
5031 } 5196 }
5032 5197
5033 void GLES2DecoderImpl::DoBindBufferRange(GLenum target, GLuint index, 5198 void GLES2DecoderImpl::DoBindBufferRange(GLenum target, GLuint index,
5034 GLuint client_id, 5199 GLuint client_id,
5035 GLintptr offset, 5200 GLintptr offset,
5036 GLsizeiptr size) { 5201 GLsizeiptr size) {
5037 BindIndexedBufferImpl(target, index, client_id, offset, size, 5202 BindIndexedBufferImpl(target, index, client_id, offset, size,
5038 kBindBufferRange, "glBindBufferRange"); 5203 kBindBufferRange, "glBindBufferRange");
5039 } 5204 }
5040 5205
5041 bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { 5206 bool GLES2DecoderImpl::BoundFramebufferAllowsChangesToAlphaChannel() {
5042 Framebuffer* framebuffer = 5207 Framebuffer* framebuffer =
5043 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); 5208 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT);
5044 if (framebuffer) 5209 if (framebuffer)
5045 return framebuffer->HasAlphaMRT(); 5210 return framebuffer->HasAlphaMRT();
5046 return BackBufferHasAlpha(); 5211 if (back_buffer_draw_buffer_ == GL_NONE)
5212 return false;
5213 if (offscreen_target_frame_buffer_.get()) {
5214 GLenum format = offscreen_target_color_format_;
5215 return (format == GL_RGBA || format == GL_RGBA8) &&
5216 offscreen_buffer_should_have_alpha_;
5217 }
5218 return (back_buffer_color_format_ == GL_RGBA ||
5219 back_buffer_color_format_ == GL_RGBA8);
5047 } 5220 }
5048 5221
5049 bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { 5222 bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() {
5050 Framebuffer* framebuffer = 5223 Framebuffer* framebuffer =
5051 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); 5224 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT);
5052 if (framebuffer) { 5225 if (framebuffer) {
5053 return framebuffer->HasDepthAttachment(); 5226 return framebuffer->HasDepthAttachment();
5054 } 5227 }
5055 if (offscreen_target_frame_buffer_.get()) { 5228 if (offscreen_target_frame_buffer_.get()) {
5056 return offscreen_target_depth_format_ != 0; 5229 return offscreen_target_depth_format_ != 0;
5057 } 5230 }
5058 return back_buffer_has_depth_; 5231 return back_buffer_has_depth_;
5059 } 5232 }
5060 5233
5061 bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { 5234 bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() {
5062 Framebuffer* framebuffer = 5235 Framebuffer* framebuffer =
5063 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); 5236 GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT);
5064 if (framebuffer) { 5237 if (framebuffer) {
5065 return framebuffer->HasStencilAttachment(); 5238 return framebuffer->HasStencilAttachment();
5066 } 5239 }
5067 if (offscreen_target_frame_buffer_.get()) { 5240 if (offscreen_target_frame_buffer_.get()) {
5068 return offscreen_target_stencil_format_ != 0 || 5241 return offscreen_target_stencil_format_ != 0 ||
5069 offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; 5242 offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8;
5070 } 5243 }
5071 return back_buffer_has_stencil_; 5244 return back_buffer_has_stencil_;
5072 } 5245 }
5073 5246
5074 void GLES2DecoderImpl::ApplyDirtyState() { 5247 void GLES2DecoderImpl::ApplyDirtyState() {
5075 if (framebuffer_state_.clear_state_dirty) { 5248 if (framebuffer_state_.clear_state_dirty) {
5076 bool have_alpha = BoundFramebufferHasColorAttachmentWithAlpha(); 5249 bool allows_alpha_change = BoundFramebufferAllowsChangesToAlphaChannel();
5077 state_.SetDeviceColorMask(state_.color_mask_red, 5250 state_.SetDeviceColorMask(state_.color_mask_red, state_.color_mask_green,
5078 state_.color_mask_green,
5079 state_.color_mask_blue, 5251 state_.color_mask_blue,
5080 state_.color_mask_alpha && have_alpha); 5252 state_.color_mask_alpha && allows_alpha_change);
5081 5253
5082 bool have_depth = BoundFramebufferHasDepthAttachment(); 5254 bool have_depth = BoundFramebufferHasDepthAttachment();
5083 state_.SetDeviceDepthMask(state_.depth_mask && have_depth); 5255 state_.SetDeviceDepthMask(state_.depth_mask && have_depth);
5084 5256
5085 bool have_stencil = BoundFramebufferHasStencilAttachment(); 5257 bool have_stencil = BoundFramebufferHasStencilAttachment();
5086 state_.SetDeviceStencilMaskSeparate( 5258 state_.SetDeviceStencilMaskSeparate(
5087 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); 5259 GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0);
5088 state_.SetDeviceStencilMaskSeparate( 5260 state_.SetDeviceStencilMaskSeparate(
5089 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); 5261 GL_BACK, have_stencil ? state_.stencil_back_writemask : 0);
5090 5262
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
5861 framebuffer->HasSameInternalFormatsMRT()) { 6033 framebuffer->HasSameInternalFormatsMRT()) {
5862 if (feature_info_->gl_version_info().is_desktop_core_profile) { 6034 if (feature_info_->gl_version_info().is_desktop_core_profile) {
5863 glGetFramebufferAttachmentParameterivEXT( 6035 glGetFramebufferAttachmentParameterivEXT(
5864 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, 6036 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
5865 GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &v); 6037 GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &v);
5866 } else { 6038 } else {
5867 glGetIntegerv(GL_ALPHA_BITS, &v); 6039 glGetIntegerv(GL_ALPHA_BITS, &v);
5868 } 6040 }
5869 } 6041 }
5870 } else { 6042 } else {
5871 v = (BackBufferHasAlpha() ? 8 : 0); 6043 v = (ClientExposedBackBufferHasAlpha() ? 8 : 0);
5872 } 6044 }
5873 params[0] = v; 6045 params[0] = v;
5874 } 6046 }
5875 return true; 6047 return true;
5876 case GL_DEPTH_BITS: 6048 case GL_DEPTH_BITS:
5877 *num_written = 1; 6049 *num_written = 1;
5878 if (params) { 6050 if (params) {
5879 GLint v = 0; 6051 GLint v = 0;
5880 if (feature_info_->gl_version_info().is_desktop_core_profile) { 6052 if (feature_info_->gl_version_info().is_desktop_core_profile) {
5881 Framebuffer* framebuffer = 6053 Framebuffer* framebuffer =
(...skipping 7340 matching lines...) Expand 10 before | Expand all | Expand 10 after
13222 MarkContextLost(error::kUnknown); 13394 MarkContextLost(error::kUnknown);
13223 group_->LoseContexts(error::kUnknown); 13395 group_->LoseContexts(error::kUnknown);
13224 return; 13396 return;
13225 } 13397 }
13226 13398
13227 // Clear the offscreen color texture. 13399 // Clear the offscreen color texture.
13228 // TODO(piman): Is this still necessary? 13400 // TODO(piman): Is this still necessary?
13229 { 13401 {
13230 ScopedFrameBufferBinder binder(this, 13402 ScopedFrameBufferBinder binder(this,
13231 offscreen_saved_frame_buffer_->id()); 13403 offscreen_saved_frame_buffer_->id());
13232 glClearColor(0, 0, 0, 0); 13404 glClearColor(0, 0, 0, BackBufferAlphaClearColor());
13233 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 13405 state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
13234 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); 13406 state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false);
13235 glClear(GL_COLOR_BUFFER_BIT); 13407 glClear(GL_COLOR_BUFFER_BIT);
13236 RestoreClearState(); 13408 RestoreClearState();
13237 } 13409 }
13238 } 13410 }
13239 } 13411 }
13240 13412
13241 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) 13413 if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0)
13242 return; 13414 return;
(...skipping 3464 matching lines...) Expand 10 before | Expand all | Expand 10 after
16707 // The workaround only works if the source texture consists of the channels 16879 // The workaround only works if the source texture consists of the channels
16708 // kRGB or kRGBA. 16880 // kRGB or kRGBA.
16709 if (channels_exist != GLES2Util::kRGBA && channels_exist != GLES2Util::kRGB) 16881 if (channels_exist != GLES2Util::kRGBA && channels_exist != GLES2Util::kRGB)
16710 return false; 16882 return false;
16711 16883
16712 *source_texture_target = texture->texture()->target(); 16884 *source_texture_target = texture->texture()->target();
16713 *source_texture_service_id = texture->service_id(); 16885 *source_texture_service_id = texture->service_id();
16714 return true; 16886 return true;
16715 } 16887 }
16716 16888
16889 bool GLES2DecoderImpl::ChromiumImageNeedsRGBEmulation() {
16890 gpu::ImageFactory* factory = GetContextGroup()->image_factory();
16891 return factory ? !factory->SupportsFormatRGB() : false;
16892 }
16893
16717 error::Error GLES2DecoderImpl::HandleBindFragmentInputLocationCHROMIUMBucket( 16894 error::Error GLES2DecoderImpl::HandleBindFragmentInputLocationCHROMIUMBucket(
16718 uint32_t immediate_data_size, 16895 uint32_t immediate_data_size,
16719 const void* cmd_data) { 16896 const void* cmd_data) {
16720 const gles2::cmds::BindFragmentInputLocationCHROMIUMBucket& c = 16897 const gles2::cmds::BindFragmentInputLocationCHROMIUMBucket& c =
16721 *static_cast<const gles2::cmds::BindFragmentInputLocationCHROMIUMBucket*>( 16898 *static_cast<const gles2::cmds::BindFragmentInputLocationCHROMIUMBucket*>(
16722 cmd_data); 16899 cmd_data);
16723 if (!features().chromium_path_rendering) { 16900 if (!features().chromium_path_rendering) {
16724 return error::kUnknownCommand; 16901 return error::kUnknownCommand;
16725 } 16902 }
16726 16903
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
16870 } 17047 }
16871 17048
16872 // Include the auto-generated part of this file. We split this because it means 17049 // Include the auto-generated part of this file. We split this because it means
16873 // we can easily edit the non-auto generated parts right here in this file 17050 // we can easily edit the non-auto generated parts right here in this file
16874 // instead of having to edit some template or the code generator. 17051 // instead of having to edit some template or the code generator.
16875 #include "base/macros.h" 17052 #include "base/macros.h"
16876 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 17053 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
16877 17054
16878 } // namespace gles2 17055 } // namespace gles2
16879 } // namespace gpu 17056 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/feature_info.h ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698