OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <vector> | 10 #include <vector> |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 GLuint bound_renderbuffer_; | 872 GLuint bound_renderbuffer_; |
873 | 873 |
874 #if defined(UNIT_TEST) | 874 #if defined(UNIT_TEST) |
875 #elif defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) | 875 #elif defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) |
876 #elif defined(OS_WIN) | 876 #elif defined(OS_WIN) |
877 static int pixel_format_; | 877 static int pixel_format_; |
878 HDC gl_device_context_; | 878 HDC gl_device_context_; |
879 HGLRC gl_context_; | 879 HGLRC gl_context_; |
880 HPBUFFERARB pbuffer_; | 880 HPBUFFERARB pbuffer_; |
881 #elif defined(OS_MACOSX) | 881 #elif defined(OS_MACOSX) |
| 882 CGLContextObj gl_context_; |
| 883 CGLPBufferObj pbuffer_; |
882 AcceleratedSurface surface_; | 884 AcceleratedSurface surface_; |
883 #endif | 885 #endif |
884 | 886 |
885 bool anti_aliased_; | 887 bool anti_aliased_; |
886 | 888 |
887 // The offscreen frame buffer that the client renders to. | 889 // The offscreen frame buffer that the client renders to. |
888 scoped_ptr<FrameBuffer> offscreen_target_frame_buffer_; | 890 scoped_ptr<FrameBuffer> offscreen_target_frame_buffer_; |
889 scoped_ptr<Texture> offscreen_target_color_texture_; | 891 scoped_ptr<Texture> offscreen_target_color_texture_; |
890 scoped_ptr<RenderBuffer> offscreen_target_depth_stencil_render_buffer_; | 892 scoped_ptr<RenderBuffer> offscreen_target_depth_stencil_render_buffer_; |
891 | 893 |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 black_2d_texture_id_(0), | 1152 black_2d_texture_id_(0), |
1151 black_cube_texture_id_(0), | 1153 black_cube_texture_id_(0), |
1152 bound_framebuffer_(0), | 1154 bound_framebuffer_(0), |
1153 bound_renderbuffer_(0), | 1155 bound_renderbuffer_(0), |
1154 #if defined(UNIT_TEST) | 1156 #if defined(UNIT_TEST) |
1155 #elif defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) | 1157 #elif defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) |
1156 #elif defined(OS_WIN) | 1158 #elif defined(OS_WIN) |
1157 gl_device_context_(NULL), | 1159 gl_device_context_(NULL), |
1158 gl_context_(NULL), | 1160 gl_context_(NULL), |
1159 pbuffer_(NULL), | 1161 pbuffer_(NULL), |
| 1162 #elif defined(OS_MAC) |
| 1163 gl_context_(NULL), |
| 1164 pbuffer_(NULL), |
1160 #endif | 1165 #endif |
1161 anti_aliased_(false) { | 1166 anti_aliased_(false) { |
1162 } | 1167 } |
1163 | 1168 |
1164 bool GLES2DecoderImpl::Initialize(GLES2Decoder* parent, | 1169 bool GLES2DecoderImpl::Initialize(GLES2Decoder* parent, |
1165 const gfx::Size& size, | 1170 const gfx::Size& size, |
1166 uint32 parent_client_texture_id) { | 1171 uint32 parent_client_texture_id) { |
1167 // Keep only a weak pointer to the parent so we don't unmap its client | 1172 // Keep only a weak pointer to the parent so we don't unmap its client |
1168 // frame buffer is after it has been destroyed. | 1173 // frame buffer is after it has been destroyed. |
1169 if (parent) | 1174 if (parent) |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1530 if (::wglGetCurrentDC() == gl_device_context_ && | 1535 if (::wglGetCurrentDC() == gl_device_context_ && |
1531 ::wglGetCurrentContext() == gl_context_) { | 1536 ::wglGetCurrentContext() == gl_context_) { |
1532 return true; | 1537 return true; |
1533 } | 1538 } |
1534 if (!::wglMakeCurrent(gl_device_context_, gl_context_)) { | 1539 if (!::wglMakeCurrent(gl_device_context_, gl_context_)) { |
1535 DLOG(ERROR) << "Unable to make gl context current."; | 1540 DLOG(ERROR) << "Unable to make gl context current."; |
1536 return false; | 1541 return false; |
1537 } | 1542 } |
1538 return true; | 1543 return true; |
1539 #elif defined(OS_LINUX) | 1544 #elif defined(OS_LINUX) |
| 1545 // TODO(apatrick): offscreen rendering not yet supported on this platform. |
1540 return window()->MakeCurrent(); | 1546 return window()->MakeCurrent(); |
1541 #elif defined(OS_MACOSX) | 1547 #elif defined(OS_MACOSX) |
1542 return surface_.MakeCurrent(); | 1548 if (gl_context_) { |
| 1549 if (CGLGetCurrentContext() != gl_context_) { |
| 1550 if (CGLSetCurrentContext(gl_context_) != kCGLNoError) { |
| 1551 DLOG(ERROR) << "Unable to make gl context current."; |
| 1552 return false; |
| 1553 } |
| 1554 } |
| 1555 return true; |
| 1556 } else { |
| 1557 return surface_.MakeCurrent(); |
| 1558 } |
1543 #else | 1559 #else |
1544 NOTREACHED(); | 1560 NOTREACHED(); |
1545 return false; | 1561 return false; |
1546 #endif | 1562 #endif |
1547 } | 1563 } |
1548 | 1564 |
1549 uint32 GLES2DecoderImpl::GetServiceIdForTesting(uint32 client_id) { | 1565 uint32 GLES2DecoderImpl::GetServiceIdForTesting(uint32 client_id) { |
1550 #if defined(UNIT_TEST) | 1566 #if defined(UNIT_TEST) |
1551 GLuint service_id; | 1567 GLuint service_id; |
1552 bool result = id_manager()->GetServiceId(client_id, &service_id); | 1568 bool result = id_manager()->GetServiceId(client_id, &service_id); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1657 // TODO(apatrick): offscreen rendering not yet supported on this platform. | 1673 // TODO(apatrick): offscreen rendering not yet supported on this platform. |
1658 DCHECK(!offscreen); | 1674 DCHECK(!offscreen); |
1659 | 1675 |
1660 // TODO(apatrick): parent contexts not yet supported on this platform. | 1676 // TODO(apatrick): parent contexts not yet supported on this platform. |
1661 DCHECK(!parent_); | 1677 DCHECK(!parent_); |
1662 | 1678 |
1663 DCHECK(window()); | 1679 DCHECK(window()); |
1664 if (!window()->Initialize()) | 1680 if (!window()->Initialize()) |
1665 return false; | 1681 return false; |
1666 #elif defined(OS_MACOSX) | 1682 #elif defined(OS_MACOSX) |
1667 // TODO(apatrick): offscreen rendering not yet supported on this platform. | |
1668 DCHECK(!offscreen); | |
1669 | |
1670 // TODO(apatrick): parent contexts not yet supported on this platform. | 1683 // TODO(apatrick): parent contexts not yet supported on this platform. |
1671 DCHECK(!parent_); | 1684 DCHECK(!parent_); |
1672 | 1685 |
1673 return surface_.Initialize(); | 1686 if (offscreen) { |
| 1687 // Create a 1x1 pbuffer and associated context to bootstrap things |
| 1688 static const CGLPixelFormatAttribute attribs[] = { |
| 1689 (CGLPixelFormatAttribute) kCGLPFAPBuffer, |
| 1690 (CGLPixelFormatAttribute) 0 |
| 1691 }; |
| 1692 CGLPixelFormatObj pixel_format; |
| 1693 GLint num_pixel_formats; |
| 1694 if (CGLChoosePixelFormat(attribs, |
| 1695 &pixel_format, |
| 1696 &num_pixel_formats) != kCGLNoError) { |
| 1697 DLOG(ERROR) << "Error choosing pixel format."; |
| 1698 DestroyPlatformSpecific(); |
| 1699 return false; |
| 1700 } |
| 1701 if (!pixel_format) { |
| 1702 return false; |
| 1703 } |
| 1704 CGLError res = CGLCreateContext(pixel_format, 0, &gl_context_); |
| 1705 CGLDestroyPixelFormat(pixel_format); |
| 1706 if (res != kCGLNoError) { |
| 1707 DLOG(ERROR) << "Error creating context."; |
| 1708 DestroyPlatformSpecific(); |
| 1709 return false; |
| 1710 } |
| 1711 if (CGLCreatePBuffer(1, 1, |
| 1712 GL_TEXTURE_2D, GL_RGBA, |
| 1713 0, &pbuffer_) != kCGLNoError) { |
| 1714 DLOG(ERROR) << "Error creating pbuffer."; |
| 1715 DestroyPlatformSpecific(); |
| 1716 return false; |
| 1717 } |
| 1718 if (CGLSetPBuffer(gl_context_, pbuffer_, 0, 0, 0) != kCGLNoError) { |
| 1719 DLOG(ERROR) << "Error attaching pbuffer to context."; |
| 1720 DestroyPlatformSpecific(); |
| 1721 return false; |
| 1722 } |
| 1723 return true; |
| 1724 } else { |
| 1725 return surface_.Initialize(); |
| 1726 } |
1674 #endif | 1727 #endif |
1675 | 1728 |
1676 return true; | 1729 return true; |
1677 } | 1730 } |
1678 | 1731 |
1679 bool GLES2DecoderImpl::InitGlew() { | 1732 bool GLES2DecoderImpl::InitGlew() { |
1680 #if !defined(UNIT_TEST) && !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) | 1733 #if !defined(UNIT_TEST) && !defined(GLES2_GPU_SERVICE_BACKEND_NATIVE_GLES2) |
1681 DLOG(INFO) << "Initializing GL and GLEW for GLES2Decoder."; | 1734 DLOG(INFO) << "Initializing GL and GLEW for GLES2Decoder."; |
1682 | 1735 |
1683 GLenum glew_error = glewInit(); | 1736 GLenum glew_error = glewInit(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1746 else | 1799 else |
1747 ::wglReleasePbufferDCARB(pbuffer_, gl_device_context_); | 1800 ::wglReleasePbufferDCARB(pbuffer_, gl_device_context_); |
1748 | 1801 |
1749 gl_device_context_ = NULL; | 1802 gl_device_context_ = NULL; |
1750 } | 1803 } |
1751 | 1804 |
1752 if (pbuffer_) { | 1805 if (pbuffer_) { |
1753 ::wglDestroyPbufferARB(pbuffer_); | 1806 ::wglDestroyPbufferARB(pbuffer_); |
1754 pbuffer_ = NULL; | 1807 pbuffer_ = NULL; |
1755 } | 1808 } |
| 1809 #elif defined(OS_MAC) |
| 1810 if (gl_context_) { |
| 1811 CGLDestroyContext(gl_context_); |
| 1812 gl_context_ = NULL; |
| 1813 } |
| 1814 |
| 1815 if (pbuffer_) { |
| 1816 CGLDestroyPBuffer(pbuffer_); |
| 1817 pbuffer_ = NULL; |
| 1818 } |
1756 #endif | 1819 #endif |
1757 } | 1820 } |
1758 | 1821 |
1759 bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { | 1822 bool GLES2DecoderImpl::UpdateOffscreenFrameBufferSize() { |
1760 if (current_size_ != pending_size_) | 1823 if (current_size_ != pending_size_) |
1761 return true; | 1824 return true; |
1762 | 1825 |
1763 // Reallocate the offscreen target buffers. | 1826 // Reallocate the offscreen target buffers. |
1764 if (!offscreen_target_color_texture_->AllocateStorage(pending_size_)) { | 1827 if (!offscreen_target_color_texture_->AllocateStorage(pending_size_)) { |
1765 return false; | 1828 return false; |
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3626 return error::kNoError; | 3689 return error::kNoError; |
3627 } | 3690 } |
3628 | 3691 |
3629 // Include the auto-generated part of this file. We split this because it means | 3692 // Include the auto-generated part of this file. We split this because it means |
3630 // we can easily edit the non-auto generated parts right here in this file | 3693 // we can easily edit the non-auto generated parts right here in this file |
3631 // instead of having to edit some template or the code generator. | 3694 // instead of having to edit some template or the code generator. |
3632 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" | 3695 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
3633 | 3696 |
3634 } // namespace gles2 | 3697 } // namespace gles2 |
3635 } // namespace gpu | 3698 } // namespace gpu |
OLD | NEW |