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

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

Issue 11428140: gpu: Add async pixel transfer interface, stub and tests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase. Fix lint. Created 8 years 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 <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "gpu/command_buffer/service/renderbuffer_manager.h" 49 #include "gpu/command_buffer/service/renderbuffer_manager.h"
50 #include "gpu/command_buffer/service/shader_manager.h" 50 #include "gpu/command_buffer/service/shader_manager.h"
51 #include "gpu/command_buffer/service/shader_translator.h" 51 #include "gpu/command_buffer/service/shader_translator.h"
52 #include "gpu/command_buffer/service/shader_translator_cache.h" 52 #include "gpu/command_buffer/service/shader_translator_cache.h"
53 #include "gpu/command_buffer/service/stream_texture.h" 53 #include "gpu/command_buffer/service/stream_texture.h"
54 #include "gpu/command_buffer/service/stream_texture_manager.h" 54 #include "gpu/command_buffer/service/stream_texture_manager.h"
55 #include "gpu/command_buffer/service/texture_definition.h" 55 #include "gpu/command_buffer/service/texture_definition.h"
56 #include "gpu/command_buffer/service/texture_manager.h" 56 #include "gpu/command_buffer/service/texture_manager.h"
57 #include "gpu/command_buffer/service/vertex_attrib_manager.h" 57 #include "gpu/command_buffer/service/vertex_attrib_manager.h"
58 #include "gpu/command_buffer/service/vertex_array_manager.h" 58 #include "gpu/command_buffer/service/vertex_array_manager.h"
59 #include "ui/gl/async_pixel_transfer_delegate.h"
59 #include "ui/gl/gl_image.h" 60 #include "ui/gl/gl_image.h"
60 #include "ui/gl/gl_implementation.h" 61 #include "ui/gl/gl_implementation.h"
61 #include "ui/gl/gl_surface.h" 62 #include "ui/gl/gl_surface.h"
62 #if defined(OS_MACOSX) 63 #if defined(OS_MACOSX)
63 #include "ui/surface/io_surface_support_mac.h" 64 #include "ui/surface/io_surface_support_mac.h"
64 #endif 65 #endif
65 66
66 #if !defined(GL_DEPTH24_STENCIL8) 67 #if !defined(GL_DEPTH24_STENCIL8)
67 #define GL_DEPTH24_STENCIL8 0x88F0 68 #define GL_DEPTH24_STENCIL8 0x88F0
68 #endif 69 #endif
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 const char* msg); 544 const char* msg);
544 virtual void SetGLErrorInvalidEnum(const char* function_name, 545 virtual void SetGLErrorInvalidEnum(const char* function_name,
545 GLenum value, 546 GLenum value,
546 const char* label); 547 const char* label);
547 virtual void SetResizeCallback( 548 virtual void SetResizeCallback(
548 const base::Callback<void(gfx::Size)>& callback) OVERRIDE; 549 const base::Callback<void(gfx::Size)>& callback) OVERRIDE;
549 550
550 virtual void SetMsgCallback(const MsgCallback& callback) OVERRIDE; 551 virtual void SetMsgCallback(const MsgCallback& callback) OVERRIDE;
551 552
552 virtual void SetStreamTextureManager(StreamTextureManager* manager) OVERRIDE; 553 virtual void SetStreamTextureManager(StreamTextureManager* manager) OVERRIDE;
554
555 virtual gfx::AsyncPixelTransferDelegate*
556 GetAsyncPixelTransferDelegate() OVERRIDE;
557 virtual void SetAsyncPixelTransferDelegate(
558 gfx::AsyncPixelTransferDelegate* delegate) OVERRIDE;
559
553 virtual bool GetServiceTextureId(uint32 client_texture_id, 560 virtual bool GetServiceTextureId(uint32 client_texture_id,
554 uint32* service_texture_id) OVERRIDE; 561 uint32* service_texture_id) OVERRIDE;
555 562
556 virtual uint32 GetGLError() OVERRIDE; 563 virtual uint32 GetGLError() OVERRIDE;
557 564
558 virtual uint32 GetTextureUploadCount() OVERRIDE; 565 virtual uint32 GetTextureUploadCount() OVERRIDE;
559 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; 566 virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE;
560 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; 567 virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE;
561 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; 568 virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE;
562 569
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 GLenum target, 772 GLenum target,
766 GLint level, 773 GLint level,
767 GLint xoffset, 774 GLint xoffset,
768 GLint yoffset, 775 GLint yoffset,
769 GLsizei width, 776 GLsizei width,
770 GLsizei height, 777 GLsizei height,
771 GLenum format, 778 GLenum format,
772 GLenum type, 779 GLenum type,
773 const void * data); 780 const void * data);
774 781
782 // Extra validation for async tex(Sub)Image2D.
783 bool ValidateAsyncTransfer(
784 const char* function_name,
785 TextureManager::TextureInfo* info,
786 GLenum target,
787 GLint level,
788 const void * data);
789
775 // Wrapper for TexImageIOSurface2DCHROMIUM. 790 // Wrapper for TexImageIOSurface2DCHROMIUM.
776 void DoTexImageIOSurface2DCHROMIUM( 791 void DoTexImageIOSurface2DCHROMIUM(
777 GLenum target, 792 GLenum target,
778 GLsizei width, 793 GLsizei width,
779 GLsizei height, 794 GLsizei height,
780 GLuint io_surface_id, 795 GLuint io_surface_id,
781 GLuint plane); 796 GLuint plane);
782 797
783 void DoCopyTextureCHROMIUM( 798 void DoCopyTextureCHROMIUM(
784 GLenum target, 799 GLenum target,
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1589 1604
1590 scoped_ptr<QueryManager> query_manager_; 1605 scoped_ptr<QueryManager> query_manager_;
1591 1606
1592 scoped_ptr<VertexArrayManager> vertex_array_manager_; 1607 scoped_ptr<VertexArrayManager> vertex_array_manager_;
1593 1608
1594 base::Callback<void(gfx::Size)> resize_callback_; 1609 base::Callback<void(gfx::Size)> resize_callback_;
1595 1610
1596 MsgCallback msg_callback_; 1611 MsgCallback msg_callback_;
1597 1612
1598 StreamTextureManager* stream_texture_manager_; 1613 StreamTextureManager* stream_texture_manager_;
1614 scoped_ptr<gfx::AsyncPixelTransferDelegate> async_pixel_transfer_delegate_;
1599 1615
1600 // The format of the back buffer_ 1616 // The format of the back buffer_
1601 GLenum back_buffer_color_format_; 1617 GLenum back_buffer_color_format_;
1602 bool back_buffer_has_depth_; 1618 bool back_buffer_has_depth_;
1603 bool back_buffer_has_stencil_; 1619 bool back_buffer_has_stencil_;
1604 1620
1605 // Backbuffer attachments that are currently undefined. 1621 // Backbuffer attachments that are currently undefined.
1606 uint32 backbuffer_needs_clear_bits_; 1622 uint32 backbuffer_needs_clear_bits_;
1607 1623
1608 bool teximage2d_faster_than_texsubimage2d_; 1624 bool teximage2d_faster_than_texsubimage2d_;
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 DoBindFramebuffer(GL_FRAMEBUFFER, 0); 2385 DoBindFramebuffer(GL_FRAMEBUFFER, 0);
2370 DoBindRenderbuffer(GL_RENDERBUFFER, 0); 2386 DoBindRenderbuffer(GL_RENDERBUFFER, 0);
2371 2387
2372 // AMD and Intel drivers on Mac OS apparently get gl_PointCoord 2388 // AMD and Intel drivers on Mac OS apparently get gl_PointCoord
2373 // backward from the spec and this setting makes them work 2389 // backward from the spec and this setting makes them work
2374 // correctly. rdar://problem/11883495 2390 // correctly. rdar://problem/11883495
2375 if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { 2391 if (feature_info_->workarounds().reverse_point_sprite_coord_origin) {
2376 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); 2392 glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
2377 } 2393 }
2378 2394
2395 // Create a delegate to perform async pixel transfers.
2396 async_pixel_transfer_delegate_ = gfx::AsyncPixelTransferDelegate::Create();
2397
2379 return true; 2398 return true;
2380 } 2399 }
2381 2400
2382 void GLES2DecoderImpl::UpdateCapabilities() { 2401 void GLES2DecoderImpl::UpdateCapabilities() {
2383 util_.set_num_compressed_texture_formats( 2402 util_.set_num_compressed_texture_formats(
2384 validators_->compressed_texture_format.GetValues().size()); 2403 validators_->compressed_texture_format.GetValues().size());
2385 util_.set_num_shader_binary_formats( 2404 util_.set_num_shader_binary_formats(
2386 validators_->shader_binary_format.GetValues().size()); 2405 validators_->shader_binary_format.GetValues().size());
2387 } 2406 }
2388 2407
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2866 } 2885 }
2867 2886
2868 void GLES2DecoderImpl::SetMsgCallback(const MsgCallback& callback) { 2887 void GLES2DecoderImpl::SetMsgCallback(const MsgCallback& callback) {
2869 msg_callback_ = callback; 2888 msg_callback_ = callback;
2870 } 2889 }
2871 2890
2872 void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) { 2891 void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) {
2873 stream_texture_manager_ = manager; 2892 stream_texture_manager_ = manager;
2874 } 2893 }
2875 2894
2895 gfx::AsyncPixelTransferDelegate*
2896 GLES2DecoderImpl::GetAsyncPixelTransferDelegate() {
2897 return async_pixel_transfer_delegate_.get();
2898 }
2899
2900 void GLES2DecoderImpl::SetAsyncPixelTransferDelegate(
2901 gfx::AsyncPixelTransferDelegate* delegate) {
2902 async_pixel_transfer_delegate_ = make_scoped_ptr(delegate);
2903 }
2904
2876 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, 2905 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id,
2877 uint32* service_texture_id) { 2906 uint32* service_texture_id) {
2878 TextureManager::TextureInfo* texture = 2907 TextureManager::TextureInfo* texture =
2879 texture_manager()->GetTextureInfo(client_texture_id); 2908 texture_manager()->GetTextureInfo(client_texture_id);
2880 if (texture) { 2909 if (texture) {
2881 *service_texture_id = texture->service_id(); 2910 *service_texture_id = texture->service_id();
2882 return true; 2911 return true;
2883 } 2912 }
2884 return false; 2913 return false;
2885 } 2914 }
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
3603 if (info->target() != 0 && info->target() != target) { 3632 if (info->target() != 0 && info->target() != target) {
3604 SetGLError(GL_INVALID_OPERATION, 3633 SetGLError(GL_INVALID_OPERATION,
3605 "glBindTexture", "texture bound to more than 1 target."); 3634 "glBindTexture", "texture bound to more than 1 target.");
3606 return; 3635 return;
3607 } 3636 }
3608 if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { 3637 if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) {
3609 SetGLError(GL_INVALID_OPERATION, 3638 SetGLError(GL_INVALID_OPERATION,
3610 "glBindTexture", "illegal target for stream texture."); 3639 "glBindTexture", "illegal target for stream texture.");
3611 return; 3640 return;
3612 } 3641 }
3642
3613 LogClientServiceForInfo(info, client_id, "glBindTexture"); 3643 LogClientServiceForInfo(info, client_id, "glBindTexture");
3614 if (info->target() == 0) { 3644 if (info->target() == 0) {
3615 texture_manager()->SetInfoTarget(info, target); 3645 texture_manager()->SetInfoTarget(info, target);
3616 } 3646 }
3617 glBindTexture(target, info->service_id()); 3647 glBindTexture(target, info->service_id());
3648
3649 // Lazily bind async transfers if they have completed.
3650 // TODO(epenner): Should this be delayed to draw time?
3651 if (info->GetAsyncTransferState()) {
3652 info->BindAsyncTransferToTexture(target);
3653 }
3654
3618 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; 3655 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
3619 unit.bind_target = target; 3656 unit.bind_target = target;
3620 switch (target) { 3657 switch (target) {
3621 case GL_TEXTURE_2D: 3658 case GL_TEXTURE_2D:
3622 unit.bound_texture_2d = info; 3659 unit.bound_texture_2d = info;
3623 break; 3660 break;
3624 case GL_TEXTURE_CUBE_MAP: 3661 case GL_TEXTURE_CUBE_MAP:
3625 unit.bound_texture_cube_map = info; 3662 unit.bound_texture_cube_map = info;
3626 break; 3663 break;
3627 case GL_TEXTURE_EXTERNAL_OES: 3664 case GL_TEXTURE_EXTERNAL_OES:
(...skipping 6017 matching lines...) Expand 10 before | Expand all | Expand 10 after
9645 SetGLError(GL_INVALID_OPERATION, 9682 SetGLError(GL_INVALID_OPERATION,
9646 "glTraceEndCHROMIUM", "no trace begin found"); 9683 "glTraceEndCHROMIUM", "no trace begin found");
9647 return; 9684 return;
9648 } 9685 }
9649 9686
9650 linked_ptr<GPUTrace> trace = gpu_trace_stack_.top(); 9687 linked_ptr<GPUTrace> trace = gpu_trace_stack_.top();
9651 trace->EnableEndTrace(); 9688 trace->EnableEndTrace();
9652 gpu_trace_stack_.pop(); 9689 gpu_trace_stack_.pop();
9653 } 9690 }
9654 9691
9692 bool GLES2DecoderImpl::ValidateAsyncTransfer(
9693 const char* function_name,
9694 TextureManager::TextureInfo* info,
9695 GLenum target,
9696 GLint level,
9697 const void * data) {
9698 // We only support async uploads to 2D textures for now.
9699 if (GL_TEXTURE_2D != target) {
9700 SetGLErrorInvalidEnum(function_name, target, "target");
9701 return false;
9702 }
9703 // We only support uploads to level zero for now.
9704 if (0 != level) {
greggman 2012/12/12 03:51:36 style: the chromium style guide prefers if (var ==
epennerAtGoogle 2012/12/12 04:49:49 Done.
9705 SetGLError(GL_INVALID_VALUE, function_name, "level != 0");
9706 return false;
9707 }
9708 // A transfer buffer must be bound, even for asyncTexImage2D.
9709 if (0 == data) {
greggman 2012/12/12 03:51:36 style: the chromium style guide prefers if (var ==
epennerAtGoogle 2012/12/12 04:49:49 Done.
9710 SetGLError(GL_INVALID_OPERATION, function_name, "buffer == 0");
9711 return false;
9712 }
9713 // We only support one async transfer in progress.
9714 if (!info || info->AsyncTransferIsInProgress()) {
9715 SetGLError(GL_INVALID_OPERATION,
9716 function_name, "transfer already in progress");
9717 return false;
9718 }
9719 return true;
9720 }
9721
9655 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( 9722 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
9656 uint32 immediate_data_size, const gles2::AsyncTexImage2DCHROMIUM& c) { 9723 uint32 immediate_data_size, const gles2::AsyncTexImage2DCHROMIUM& c) {
9657 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); 9724 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM");
9658
9659 // TODO: This is a copy of HandleTexImage2D validation. Merge
9660 // as much of it as possible.
9661 tex_image_2d_failed_ = true;
9662 GLenum target = static_cast<GLenum>(c.target); 9725 GLenum target = static_cast<GLenum>(c.target);
9663 GLint level = static_cast<GLint>(c.level); 9726 GLint level = static_cast<GLint>(c.level);
9664 GLint internal_format = static_cast<GLint>(c.internalformat); 9727 GLint internal_format = static_cast<GLint>(c.internalformat);
9665 GLsizei width = static_cast<GLsizei>(c.width); 9728 GLsizei width = static_cast<GLsizei>(c.width);
9666 GLsizei height = static_cast<GLsizei>(c.height); 9729 GLsizei height = static_cast<GLsizei>(c.height);
9667 GLint border = static_cast<GLint>(c.border); 9730 GLint border = static_cast<GLint>(c.border);
9668 GLenum format = static_cast<GLenum>(c.format); 9731 GLenum format = static_cast<GLenum>(c.format);
9669 GLenum type = static_cast<GLenum>(c.type); 9732 GLenum type = static_cast<GLenum>(c.type);
9670 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); 9733 uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id);
9671 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); 9734 uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset);
9672 uint32 pixels_size; 9735 uint32 pixels_size;
9736
9737 // TODO(epenner): Move this and copies of this memory validation
9738 // into ValidateTexImage2D step.
9673 if (!GLES2Util::ComputeImageDataSizes( 9739 if (!GLES2Util::ComputeImageDataSizes(
9674 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, 9740 width, height, format, type, state_.unpack_alignment, &pixels_size, NULL,
9675 NULL)) { 9741 NULL)) {
9676 return error::kOutOfBounds; 9742 return error::kOutOfBounds;
9677 } 9743 }
9678 const void* pixels = NULL; 9744 const void* pixels = NULL;
9679 if (pixels_shm_id != 0 || pixels_shm_offset != 0) { 9745 if (pixels_shm_id != 0 || pixels_shm_offset != 0) {
9680 pixels = GetSharedMemoryAs<const void*>( 9746 pixels = GetSharedMemoryAs<const void*>(
9681 pixels_shm_id, pixels_shm_offset, pixels_size); 9747 pixels_shm_id, pixels_shm_offset, pixels_size);
9682 if (!pixels) { 9748 if (!pixels) {
9683 return error::kOutOfBounds; 9749 return error::kOutOfBounds;
9684 } 9750 }
9685 } 9751 }
9686 9752
9687 // TODO(epenner): Do this via an async task. 9753 // All the normal glTexSubImage2D validation.
9688 DoTexImage2D( 9754 if (!ValidateTexImage2D("glAsyncTexImage2D", target, level, internal_format,
9689 target, level, internal_format, width, height, border, format, type, 9755 width, height, border, format, type, pixels, pixels_size)) {
9690 pixels, pixels_size); 9756 return error::kNoError;
9757 }
9758
9759 // Extra async validation.
9760 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
9761 if (!ValidateAsyncTransfer("glAsyncTexImage2D", info, target, level, pixels))
9762 return error::kNoError;
9763
9764 // Don't allow async redefinition of a textures.
9765 // TODO(epenner): Is there a better check that the texture has been defined?
9766 if (info->estimated_size() > 0) {
greggman 2012/12/12 03:51:36 Are you sure you need this check? If so I'd consid
epennerAtGoogle 2012/12/12 04:49:49 Done (added IsDefined). Redefining a texture that
9767 SetGLError(GL_INVALID_OPERATION, "glAsyncTexImage2D", "already defined");
9768 return error::kNoError;
9769 }
9770
9771 // Return errors for any cases in DoTexImage2D which aren't handled here.
9772 if (info->IsAttachedToFramebuffer()) {
greggman 2012/12/12 03:51:36 If they are not allowed be bound to a framebuffer
epennerAtGoogle 2012/12/12 04:49:49 Let me do a quick check to see if I can just allow
epennerAtGoogle 2012/12/12 05:17:00 I had to copy a small piece of DoTexImage2D, but j
9773 SetGLError(GL_INVALID_OPERATION, "glAsyncTexImage2D",
9774 "bound to framebuffer");
9775 return error::kNoError;
9776 }
9777 if (type == GL_FLOAT || type == GL_HALF_FLOAT_OES) {
greggman 2012/12/12 03:51:36 Would it would be better to list the valid types r
epennerAtGoogle 2012/12/12 04:49:49 Ditto, maybe I can just allow floats actually.
epennerAtGoogle 2012/12/12 05:17:00 Okay, I allowed floats by adding GetTexInternalFor
9778 SetGLError(GL_INVALID_VALUE, "glAsyncTexImage2D", "type is float");
9779 return error::kNoError;
9780 }
9781 GLenum gl_internal_format = GetTexInternalFormat(internal_format);
9782
9783 // We know the memory/size is safe, so get the real shared memory since
9784 // it might need to be duped to prevent use-after-free of the memory.
9785 Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id);
9786 base::SharedMemory* shared_memory = buffer.shared_memory;
9787 uint32 shm_size = buffer.size;
9788 uint32 shm_data_offset = c.pixels_shm_offset;
9789 uint32 shm_data_size = pixels_size;
9790
9791 DCHECK(!info->GetAsyncTransferState());
greggman 2012/12/12 03:51:36 It seems like this DCHECK is in conflict with the
epennerAtGoogle 2012/12/12 04:49:49 DCHECK is correct. Just being defensive against cr
9792 if (!info->GetAsyncTransferState()) {
9793 // Set up the async state if needed, and make the texture
9794 // immutable so the async state stays valid.
9795 info->SetAsyncTransferState(
9796 async_pixel_transfer_delegate_->
9797 CreatePixelTransferState(info->service_id()));
9798 info->SetImmutable(true);
9799 bool cleared = true;
9800 texture_manager()->SetLevelInfo(
greggman 2012/12/12 03:51:36 I'm confused. You can't call SetLevelInfo until th
epennerAtGoogle 2012/12/12 04:49:49 My understanding was that we want to avoid reading
epennerAtGoogle 2012/12/12 05:53:33 Another possibility would be to not set the level
greggman 2012/12/12 06:58:18 That seems like that would be best.
9801 info, target, level, internal_format,
9802 width, height, 1, border, format, type,
9803 cleared);
9804 }
9805
9806 // Issue the async call and set up the texture.
9807 gfx::AsyncTexImage2DParams tex_params = {target, level, gl_internal_format,
9808 width, height, border, format, type};
9809 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
9810 shm_data_offset, shm_data_size};
9811 async_pixel_transfer_delegate_->AsyncTexImage2D(
9812 info->GetAsyncTransferState(), tex_params, mem_params);
9691 return error::kNoError; 9813 return error::kNoError;
9692 } 9814 }
9693 9815
9694 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( 9816 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM(
9695 uint32 immediate_data_size, const gles2::AsyncTexSubImage2DCHROMIUM& c) { 9817 uint32 immediate_data_size, const gles2::AsyncTexSubImage2DCHROMIUM& c) {
9696 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 9818 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
9697
9698 // TODO: This is a copy of HandleTexSubImage2D validation. Merge
9699 // as much of it as possible.
9700 GLenum target = static_cast<GLenum>(c.target); 9819 GLenum target = static_cast<GLenum>(c.target);
9701 GLint level = static_cast<GLint>(c.level); 9820 GLint level = static_cast<GLint>(c.level);
9702 GLint xoffset = static_cast<GLint>(c.xoffset); 9821 GLint xoffset = static_cast<GLint>(c.xoffset);
9703 GLint yoffset = static_cast<GLint>(c.yoffset); 9822 GLint yoffset = static_cast<GLint>(c.yoffset);
9704 GLsizei width = static_cast<GLsizei>(c.width); 9823 GLsizei width = static_cast<GLsizei>(c.width);
9705 GLsizei height = static_cast<GLsizei>(c.height); 9824 GLsizei height = static_cast<GLsizei>(c.height);
9706 GLenum format = static_cast<GLenum>(c.format); 9825 GLenum format = static_cast<GLenum>(c.format);
9707 GLenum type = static_cast<GLenum>(c.type); 9826 GLenum type = static_cast<GLenum>(c.type);
9827
9828 // TODO(epenner): Move this and copies of this memory validation
9829 // into ValidateTexImage2D step.
9708 uint32 data_size; 9830 uint32 data_size;
9709 if (!GLES2Util::ComputeImageDataSizes( 9831 if (!GLES2Util::ComputeImageDataSizes(
9710 width, height, format, type, state_.unpack_alignment, &data_size, 9832 width, height, format, type, state_.unpack_alignment, &data_size,
9711 NULL, NULL)) { 9833 NULL, NULL)) {
9712 return error::kOutOfBounds; 9834 return error::kOutOfBounds;
9713 } 9835 }
9714 const void* pixels = GetSharedMemoryAs<const void*>( 9836 const void* pixels = GetSharedMemoryAs<const void*>(
9715 c.data_shm_id, c.data_shm_offset, data_size); 9837 c.data_shm_id, c.data_shm_offset, data_size);
9716 if (pixels == NULL) { 9838
9717 return error::kOutOfBounds; 9839 // All the normal glTexSubImage2D validation.
9840 error::Error error = error::kNoError;
9841 if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2D", target, level,
9842 xoffset, yoffset, width, height, format, type, pixels)) {
9843 return error;
9718 } 9844 }
9719 9845
9720 // TODO(epenner): Do this via an async task. 9846 // Extra async validation.
9721 return DoTexSubImage2D( 9847 TextureManager::TextureInfo* info = GetTextureInfoForTarget(target);
9722 target, level, xoffset, yoffset, width, height, format, type, pixels); 9848 if (!ValidateAsyncTransfer(
9849 "glAsyncTexSubImage2D", info, target, level, pixels))
9850 return error::kNoError;
9851
9852 // Guarantee async textures are always 'cleared' as follows:
9853 // - AsyncTexImage2D can not redefine an existing texture
9854 // - AsyncTexImage2D must initialize the entire image via non-null buffer.
9855 // - AsyncTexSubImage2D clears synchronously if not already cleared.
9856 // - Textures become immutable after an async call.
9857 // This way we know in all cases that an async texture is always clear.
9858 if (!info->SafeToRenderFrom()) {
9859 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) {
9860 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big");
greggman 2012/12/12 03:51:36 "glAsyncTexSubImage2D"
epennerAtGoogle 2012/12/12 04:49:49 Done.
9861 return error::kNoError;
9862 }
9863 }
9864
9865 // We know the memory/size is safe, so get the real shared memory since
9866 // it might need to be duped to prevent use-after-free of the memory.
9867 Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id);
9868 base::SharedMemory* shared_memory = buffer.shared_memory;
9869 uint32 shm_size = buffer.size;
9870 uint32 shm_data_offset = c.data_shm_offset;
9871 uint32 shm_data_size = data_size;
9872
9873 if (!info->GetAsyncTransferState()) {
9874 // Set up the async state if needed, and make the texture
9875 // immutable so the async state stays valid.
9876 info->SetAsyncTransferState(
9877 async_pixel_transfer_delegate_->
9878 CreatePixelTransferState(info->service_id()));
9879 info->SetImmutable(true);
9880 }
9881
9882 gfx::AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset,
9883 width, height, format, type};
9884 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
9885 shm_data_offset, shm_data_size};
9886 async_pixel_transfer_delegate_->AsyncTexSubImage2D(
9887 info->GetAsyncTransferState(), tex_params, mem_params);
9888 return error::kNoError;
9723 } 9889 }
9724 9890
9725 // Include the auto-generated part of this file. We split this because it means 9891 // Include the auto-generated part of this file. We split this because it means
9726 // we can easily edit the non-auto generated parts right here in this file 9892 // we can easily edit the non-auto generated parts right here in this file
9727 // instead of having to edit some template or the code generator. 9893 // instead of having to edit some template or the code generator.
9728 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 9894 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
9729 9895
9730 } // namespace gles2 9896 } // namespace gles2
9731 } // namespace gpu 9897 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698