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

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Created 7 years, 8 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 "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h"
6 6
7 #include <GLES2/gl2.h> 7 #include <GLES2/gl2.h>
8 #ifndef GL_GLEXT_PROTOTYPES 8 #ifndef GL_GLEXT_PROTOTYPES
9 #define GL_GLEXT_PROTOTYPES 1 9 #define GL_GLEXT_PROTOTYPES 1
10 #endif 10 #endif
(...skipping 15 matching lines...) Expand all
26 #include "base/metrics/histogram.h" 26 #include "base/metrics/histogram.h"
27 #include "base/synchronization/lock.h" 27 #include "base/synchronization/lock.h"
28 #include "gpu/command_buffer/client/gles2_implementation.h" 28 #include "gpu/command_buffer/client/gles2_implementation.h"
29 #include "gpu/command_buffer/client/gles2_lib.h" 29 #include "gpu/command_buffer/client/gles2_lib.h"
30 #include "gpu/command_buffer/client/transfer_buffer.h" 30 #include "gpu/command_buffer/client/transfer_buffer.h"
31 #include "gpu/command_buffer/common/constants.h" 31 #include "gpu/command_buffer/common/constants.h"
32 #include "gpu/command_buffer/service/command_buffer_service.h" 32 #include "gpu/command_buffer/service/command_buffer_service.h"
33 #include "gpu/command_buffer/service/context_group.h" 33 #include "gpu/command_buffer/service/context_group.h"
34 #include "gpu/command_buffer/service/gl_context_virtual.h" 34 #include "gpu/command_buffer/service/gl_context_virtual.h"
35 #include "gpu/command_buffer/service/gpu_scheduler.h" 35 #include "gpu/command_buffer/service/gpu_scheduler.h"
36 #include "gpu/command_buffer/service/image_manager.h"
36 #include "gpu/command_buffer/service/transfer_buffer_manager.h" 37 #include "gpu/command_buffer/service/transfer_buffer_manager.h"
37 #include "ui/gl/gl_context.h" 38 #include "ui/gl/gl_context.h"
39 #include "ui/gl/gl_image.h"
38 #include "ui/gl/gl_share_group.h" 40 #include "ui/gl/gl_share_group.h"
39 #include "ui/gl/gl_surface.h" 41 #include "ui/gl/gl_surface.h"
40 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" 42 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h"
41 43
42 using gpu::Buffer; 44 using gpu::Buffer;
43 using gpu::CommandBuffer; 45 using gpu::CommandBuffer;
44 using gpu::CommandBufferService; 46 using gpu::CommandBufferService;
45 using gpu::gles2::GLES2CmdHelper; 47 using gpu::gles2::GLES2CmdHelper;
46 using gpu::gles2::GLES2Implementation; 48 using gpu::gles2::GLES2Implementation;
47 using gpu::GpuScheduler; 49 using gpu::GpuScheduler;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 Error GetError(); 138 Error GetError();
137 139
138 // Return true if GPU process reported GLInProcessContext lost or there was a 140 // Return true if GPU process reported GLInProcessContext lost or there was a
139 // problem communicating with the GPU process. 141 // problem communicating with the GPU process.
140 bool IsCommandBufferContextLost(); 142 bool IsCommandBufferContextLost();
141 143
142 CommandBufferService* GetCommandBufferService(); 144 CommandBufferService* GetCommandBufferService();
143 145
144 ::gpu::gles2::GLES2Decoder* GetDecoder(); 146 ::gpu::gles2::GLES2Decoder* GetDecoder();
145 147
148 ::gpu::gles2::ImageManager* GetImageManager();
149
146 private: 150 private:
147 explicit GLInProcessContext(bool share_resources); 151 explicit GLInProcessContext(bool share_resources);
148 152
149 bool Initialize(bool is_offscreen, 153 bool Initialize(bool is_offscreen,
150 gfx::AcceleratedWidget window, 154 gfx::AcceleratedWidget window,
151 const gfx::Size& size, 155 const gfx::Size& size,
152 const char* allowed_extensions, 156 const char* allowed_extensions,
153 const int32* attrib_list, 157 const int32* attrib_list,
154 gfx::GpuPreference gpu_preference); 158 gfx::GpuPreference gpu_preference);
155 void Destroy(); 159 void Destroy();
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 382
379 // TODO(gman): Remove This 383 // TODO(gman): Remove This
380 void GLInProcessContext::DisableShaderTranslation() { 384 void GLInProcessContext::DisableShaderTranslation() {
381 NOTREACHED(); 385 NOTREACHED();
382 } 386 }
383 387
384 GLES2Implementation* GLInProcessContext::GetImplementation() { 388 GLES2Implementation* GLInProcessContext::GetImplementation() {
385 return gles2_implementation_.get(); 389 return gles2_implementation_.get();
386 } 390 }
387 391
392 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() {
393 return decoder_->GetContextGroup()->image_manager();
394 }
395
388 GLInProcessContext::GLInProcessContext(bool share_resources) 396 GLInProcessContext::GLInProcessContext(bool share_resources)
389 : last_error_(SUCCESS), 397 : last_error_(SUCCESS),
390 share_resources_(share_resources), 398 share_resources_(share_resources),
391 context_lost_(false) { 399 context_lost_(false) {
392 } 400 }
393 401
394 bool GLInProcessContext::Initialize( 402 bool GLInProcessContext::Initialize(
395 bool is_offscreen, 403 bool is_offscreen,
396 gfx::AcceleratedWidget window, 404 gfx::AcceleratedWidget window,
397 const gfx::Size& size, 405 const gfx::Size& size,
(...skipping 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() { 1645 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() {
1638 ClearContext(); 1646 ClearContext();
1639 GLuint o; 1647 GLuint o;
1640 gl_->GenTextures(1, &o); 1648 gl_->GenTextures(1, &o);
1641 return o; 1649 return o;
1642 } 1650 }
1643 1651
1644 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer( 1652 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer(
1645 WebGLId buffer) { 1653 WebGLId buffer) {
1646 ClearContext(); 1654 ClearContext();
1655 // It is safe to call this method even though the buffer being deleted
1656 // isn't a GPU memory buffer as it eventually translates to a
1657 // hash_map::erase() which doesn't throw an exception if the key
1658 // isn't in the hash_map
1659 DeleteImageForGpuMemoryBuffer(buffer);
1647 gl_->DeleteBuffers(1, &buffer); 1660 gl_->DeleteBuffers(1, &buffer);
1648 } 1661 }
1649 1662
1650 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( 1663 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer(
1651 WebGLId framebuffer) { 1664 WebGLId framebuffer) {
1652 ClearContext(); 1665 ClearContext();
1653 gl_->DeleteFramebuffers(1, &framebuffer); 1666 gl_->DeleteFramebuffers(1, &framebuffer);
1654 } 1667 }
1655 1668
1656 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( 1669 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 } 1783 }
1771 1784
1772 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { 1785 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() {
1773 // TODO(kbr): improve the precision here. 1786 // TODO(kbr): improve the precision here.
1774 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; 1787 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB;
1775 if (context_lost_callback_) { 1788 if (context_lost_callback_) {
1776 context_lost_callback_->onContextLost(); 1789 context_lost_callback_->onContextLost();
1777 } 1790 }
1778 } 1791 }
1779 1792
1793 void WebGraphicsContext3DInProcessCommandBufferImpl::
1794 CreateImageForGpuMemoryBuffer(WGC3Dsizei width, WGC3Dsizei height) {
1795 gl_->Flush();
1796 gfx::GpuMemoryBufferHandle buffer =
1797 const_cast<GLubyte*>(
1798 gl_->GetString(GL_BOUND_GPU_MEMORY_BUFFER_CHROMIUM_POINTER));
1799 DCHECK(buffer);
1800
1801 scoped_refptr<gfx::GLImage> gl_image =
1802 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(
1803 buffer, gfx::Size(width, height));
1804
1805 GLint buffer_id = 0;
1806 gl_->GetIntegerv(GL_BOUND_GPU_MEMORY_BUFFER_CHROMIUM, &buffer_id);
1807 DCHECK(buffer_id != 0);
1808 context_->GetImageManager()->AddImage(gl_image, buffer_id);
1809 }
1810
1811 void WebGraphicsContext3DInProcessCommandBufferImpl::
1812 DeleteImageForGpuMemoryBuffer() {
1813 gl_->Flush();
1814 GLint buffer_id = 0;
1815 gl_->GetIntegerv(GL_BOUND_GPU_MEMORY_BUFFER_CHROMIUM, &buffer_id);
1816 DCHECK(buffer_id != 0);
1817 context_->GetImageManager()->RemoveImage(buffer_id);
1818 }
1819
1820 void WebGraphicsContext3DInProcessCommandBufferImpl::
1821 DeleteImageForGpuMemoryBuffer(WebGLId buffer_id) {
1822 gl_->Flush();
1823 context_->GetImageManager()->RemoveImage(buffer_id);
1824 }
1825
1826 void WebGraphicsContext3DInProcessCommandBufferImpl::imageBufferDataCHROMIUM(
1827 WGC3Denum target, WGC3Dsizei width, WGC3Dsizei height) {
1828 ClearContext();
1829 gl_->ImageBufferDataCHROMIUM(target, width, height);
1830 if (width == 0 && height == 0) {
1831 DeleteImageForGpuMemoryBuffer();
1832 } else {
1833 CreateImageForGpuMemoryBuffer(width, height);
1834 }
1835 }
1836
1780 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, 1837 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM,
1781 WebGLId, WGC3Dint, const WGC3Dchar*) 1838 WebGLId, WGC3Dint, const WGC3Dchar*)
1782 1839
1783 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) 1840 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM)
1784 1841
1785 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) 1842 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*)
1786 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, 1843 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM,
1787 WGC3Denum, const WGC3Dbyte*) 1844 WGC3Denum, const WGC3Dbyte*)
1788 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, 1845 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM,
1789 WGC3Denum, const WGC3Dbyte*) 1846 WGC3Denum, const WGC3Dbyte*)
1790 1847
1791 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, 1848 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT,
1792 WGC3Dsizei, const WGC3Denum*) 1849 WGC3Dsizei, const WGC3Denum*)
1793 1850
1794 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, 1851 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM,
1795 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, 1852 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint,
1796 WGC3Denum, WGC3Denum, const void*) 1853 WGC3Denum, WGC3Denum, const void*)
1797 1854
1798 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, 1855 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM,
1799 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, 1856 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei,
1800 WGC3Denum, WGC3Denum, const void*) 1857 WGC3Denum, WGC3Denum, const void*)
1801 1858
1802 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, 1859 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM,
1803 WGC3Denum) 1860 WGC3Denum)
1804 1861
1805 } // namespace gpu 1862 } // namespace gpu
1806 } // namespace webkit 1863 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698