| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 explicit Texture(GLES2DecoderImpl* decoder); | 237 explicit Texture(GLES2DecoderImpl* decoder); |
| 238 ~Texture(); | 238 ~Texture(); |
| 239 | 239 |
| 240 // Create a new render texture. | 240 // Create a new render texture. |
| 241 void Create(); | 241 void Create(); |
| 242 | 242 |
| 243 // Set the initial size and format of a render texture or resize it. | 243 // Set the initial size and format of a render texture or resize it. |
| 244 bool AllocateStorage(const gfx::Size& size, GLenum format); | 244 bool AllocateStorage(const gfx::Size& size, GLenum format); |
| 245 | 245 |
| 246 // Copy the contents of the currently bound frame buffer. | 246 // Copy the contents of the currently bound frame buffer. |
| 247 void Copy(const gfx::Size& size); | 247 void Copy(const gfx::Size& size, GLenum format); |
| 248 | 248 |
| 249 // Destroy the render texture. This must be explicitly called before | 249 // Destroy the render texture. This must be explicitly called before |
| 250 // destroying this object. | 250 // destroying this object. |
| 251 void Destroy(); | 251 void Destroy(); |
| 252 | 252 |
| 253 // Invalidate the texture. This can be used when a context is lost and it is | 253 // Invalidate the texture. This can be used when a context is lost and it is |
| 254 // not possible to make it current in order to free the resource. | 254 // not possible to make it current in order to free the resource. |
| 255 void Invalidate(); | 255 void Invalidate(); |
| 256 | 256 |
| 257 GLuint id() const { | 257 GLuint id() const { |
| 258 return id_; | 258 return id_; |
| 259 } | 259 } |
| 260 | 260 |
| 261 gfx::Size size() const { | 261 gfx::Size size() const { |
| 262 return size_; | 262 return size_; |
| 263 } | 263 } |
| 264 | 264 |
| 265 private: | 265 private: |
| 266 GLES2DecoderImpl* decoder_; | 266 GLES2DecoderImpl* decoder_; |
| 267 GLuint id_; | 267 GLuint id_; |
| 268 GLenum format_; | |
| 269 gfx::Size size_; | 268 gfx::Size size_; |
| 270 DISALLOW_COPY_AND_ASSIGN(Texture); | 269 DISALLOW_COPY_AND_ASSIGN(Texture); |
| 271 }; | 270 }; |
| 272 | 271 |
| 273 // Encapsulates an OpenGL render buffer of any format. | 272 // Encapsulates an OpenGL render buffer of any format. |
| 274 class RenderBuffer { | 273 class RenderBuffer { |
| 275 public: | 274 public: |
| 276 explicit RenderBuffer(GLES2DecoderImpl* decoder); | 275 explicit RenderBuffer(GLES2DecoderImpl* decoder); |
| 277 ~RenderBuffer(); | 276 ~RenderBuffer(); |
| 278 | 277 |
| (...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1644 | 1643 |
| 1645 ScopedGLErrorSuppressor suppressor(decoder_); | 1644 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1646 decoder_->RestoreCurrentFramebufferBindings(); | 1645 decoder_->RestoreCurrentFramebufferBindings(); |
| 1647 if (decoder_->enable_scissor_test_) { | 1646 if (decoder_->enable_scissor_test_) { |
| 1648 glEnable(GL_SCISSOR_TEST); | 1647 glEnable(GL_SCISSOR_TEST); |
| 1649 } | 1648 } |
| 1650 } | 1649 } |
| 1651 | 1650 |
| 1652 Texture::Texture(GLES2DecoderImpl* decoder) | 1651 Texture::Texture(GLES2DecoderImpl* decoder) |
| 1653 : decoder_(decoder), | 1652 : decoder_(decoder), |
| 1654 id_(0), | 1653 id_(0) { |
| 1655 format_(0) { | |
| 1656 } | 1654 } |
| 1657 | 1655 |
| 1658 Texture::~Texture() { | 1656 Texture::~Texture() { |
| 1659 // This does not destroy the render texture because that would require that | 1657 // This does not destroy the render texture because that would require that |
| 1660 // the associated GL context was current. Just check that it was explicitly | 1658 // the associated GL context was current. Just check that it was explicitly |
| 1661 // destroyed. | 1659 // destroyed. |
| 1662 DCHECK_EQ(id_, 0u); | 1660 DCHECK_EQ(id_, 0u); |
| 1663 } | 1661 } |
| 1664 | 1662 |
| 1665 void Texture::Create() { | 1663 void Texture::Create() { |
| 1666 ScopedGLErrorSuppressor suppressor(decoder_); | 1664 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1667 Destroy(); | 1665 Destroy(); |
| 1668 glGenTextures(1, &id_); | 1666 glGenTextures(1, &id_); |
| 1667 ScopedTexture2DBinder binder(decoder_, id_); |
| 1668 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1669 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1670 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1671 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1669 } | 1672 } |
| 1670 | 1673 |
| 1671 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { | 1674 bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
| 1672 DCHECK_NE(id_, 0u); | 1675 DCHECK_NE(id_, 0u); |
| 1673 ScopedGLErrorSuppressor suppressor(decoder_); | 1676 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1674 ScopedTexture2DBinder binder(decoder_, id_); | 1677 ScopedTexture2DBinder binder(decoder_, id_); |
| 1675 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
| 1676 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
| 1677 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | |
| 1678 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | |
| 1679 | 1678 |
| 1680 glTexImage2D(GL_TEXTURE_2D, | 1679 glTexImage2D(GL_TEXTURE_2D, |
| 1681 0, // mip level | 1680 0, // mip level |
| 1682 format, | 1681 format, |
| 1683 size.width(), | 1682 size.width(), |
| 1684 size.height(), | 1683 size.height(), |
| 1685 0, // border | 1684 0, // border |
| 1686 format, | 1685 format, |
| 1687 GL_UNSIGNED_BYTE, | 1686 GL_UNSIGNED_BYTE, |
| 1688 NULL); | 1687 NULL); |
| 1689 | 1688 |
| 1690 size_ = size; | 1689 size_ = size; |
| 1691 format_ = format; | |
| 1692 | 1690 |
| 1693 return glGetError() == GL_NO_ERROR; | 1691 return glGetError() == GL_NO_ERROR; |
| 1694 } | 1692 } |
| 1695 | 1693 |
| 1696 void Texture::Copy(const gfx::Size& size) { | 1694 void Texture::Copy(const gfx::Size& size, GLenum format) { |
| 1697 DCHECK_NE(id_, 0u); | 1695 DCHECK_NE(id_, 0u); |
| 1698 ScopedGLErrorSuppressor suppressor(decoder_); | 1696 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1699 ScopedTexture2DBinder binder(decoder_, id_); | 1697 ScopedTexture2DBinder binder(decoder_, id_); |
| 1700 glCopyTexImage2D(GL_TEXTURE_2D, | 1698 glCopyTexImage2D(GL_TEXTURE_2D, |
| 1701 0, // level | 1699 0, // level |
| 1702 format_, | 1700 format, |
| 1703 0, 0, | 1701 0, 0, |
| 1704 size.width(), | 1702 size.width(), |
| 1705 size.height(), | 1703 size.height(), |
| 1706 0); // border | 1704 0); // border |
| 1707 } | 1705 } |
| 1708 | 1706 |
| 1709 void Texture::Destroy() { | 1707 void Texture::Destroy() { |
| 1710 if (id_ != 0) { | 1708 if (id_ != 0) { |
| 1711 ScopedGLErrorSuppressor suppressor(decoder_); | 1709 ScopedGLErrorSuppressor suppressor(decoder_); |
| 1712 glDeleteTextures(1, &id_); | 1710 glDeleteTextures(1, &id_); |
| (...skipping 4972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6685 swap_buffers_callback_->Run(); | 6683 swap_buffers_callback_->Run(); |
| 6686 } | 6684 } |
| 6687 return error::kNoError; | 6685 return error::kNoError; |
| 6688 } else { | 6686 } else { |
| 6689 ScopedFrameBufferBinder binder(this, | 6687 ScopedFrameBufferBinder binder(this, |
| 6690 offscreen_target_frame_buffer_->id()); | 6688 offscreen_target_frame_buffer_->id()); |
| 6691 | 6689 |
| 6692 if (parent_) { | 6690 if (parent_) { |
| 6693 // Copy the target frame buffer to the saved offscreen texture. | 6691 // Copy the target frame buffer to the saved offscreen texture. |
| 6694 offscreen_saved_color_texture_->Copy( | 6692 offscreen_saved_color_texture_->Copy( |
| 6695 offscreen_saved_color_texture_->size()); | 6693 offscreen_saved_color_texture_->size(), |
| 6694 offscreen_saved_color_format_); |
| 6696 | 6695 |
| 6697 // Ensure the side effects of the copy are visible to the parent | 6696 // Ensure the side effects of the copy are visible to the parent |
| 6698 // context. There is no need to do this for ANGLE because it uses a | 6697 // context. There is no need to do this for ANGLE because it uses a |
| 6699 // single D3D device for all contexts. | 6698 // single D3D device for all contexts. |
| 6700 if (!IsAngle()) | 6699 if (!IsAngle()) |
| 6701 glFlush(); | 6700 glFlush(); |
| 6702 } | 6701 } |
| 6703 | 6702 |
| 6704 // Run the callback with |binder| in scope, so that the callback can call | 6703 // Run the callback with |binder| in scope, so that the callback can call |
| 6705 // ReadPixels or CopyTexImage2D. | 6704 // ReadPixels or CopyTexImage2D. |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6936 return error::kNoError; | 6935 return error::kNoError; |
| 6937 } | 6936 } |
| 6938 | 6937 |
| 6939 // Include the auto-generated part of this file. We split this because it means | 6938 // Include the auto-generated part of this file. We split this because it means |
| 6940 // we can easily edit the non-auto generated parts right here in this file | 6939 // we can easily edit the non-auto generated parts right here in this file |
| 6941 // instead of having to edit some template or the code generator. | 6940 // instead of having to edit some template or the code generator. |
| 6942 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 6941 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 6943 | 6942 |
| 6944 } // namespace gles2 | 6943 } // namespace gles2 |
| 6945 } // namespace gpu | 6944 } // namespace gpu |
| OLD | NEW |