1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/callback.h" 10 #include "base/memory/ref_counted.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/synchronization/lock.h" 13 #include "base/time/time.h" 14 #include "gpu/command_buffer/common/buffer.h" 15 #include "gpu/gpu_export.h" 16 #include "ui/gl/gl_bindings.h" 17 18 namespace base { 19 class SharedMemory; 20 } 21 22 namespace gpu { 23 24 struct AsyncTexImage2DParams { 25 GLenum target; 26 GLint level; 27 GLenum internal_format; 28 GLsizei width; 29 GLsizei height; 30 GLint border; 31 GLenum format; 32 GLenum type; 33 }; 34 35 struct AsyncTexSubImage2DParams { 36 GLenum target; 37 GLint level; 38 GLint xoffset; 39 GLint yoffset; 40 GLsizei width; 41 GLsizei height; 42 GLenum format; 43 GLenum type; 44 }; 45 46 class AsyncMemoryParams { 47 public: 48 AsyncMemoryParams(scoped_refptr<Buffer> buffer, 49 uint32 data_offset, 50 uint32 data_size); 51 ~AsyncMemoryParams(); 52 buffer()53 scoped_refptr<Buffer> buffer() const { return buffer_; } data_size()54 uint32 data_size() const { return data_size_; } data_offset()55 uint32 data_offset() const { return data_offset_; } GetDataAddress()56 void* GetDataAddress() const { 57 return buffer_->GetDataAddress(data_offset_, data_size_); 58 } 59 60 private: 61 scoped_refptr<Buffer> buffer_; 62 uint32 data_offset_; 63 uint32 data_size_; 64 }; 65 66 class AsyncPixelTransferUploadStats 67 : public base::RefCountedThreadSafe<AsyncPixelTransferUploadStats> { 68 public: 69 AsyncPixelTransferUploadStats(); 70 71 void AddUpload(base::TimeDelta transfer_time); 72 int GetStats(base::TimeDelta* total_texture_upload_time); 73 74 private: 75 friend class base::RefCountedThreadSafe<AsyncPixelTransferUploadStats>; 76 77 ~AsyncPixelTransferUploadStats(); 78 79 int texture_upload_count_; 80 base::TimeDelta total_texture_upload_time_; 81 base::Lock lock_; 82 83 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferUploadStats); 84 }; 85 86 class GPU_EXPORT AsyncPixelTransferDelegate { 87 public: 88 virtual ~AsyncPixelTransferDelegate(); 89 90 // The callback occurs on the caller thread, once the texture is 91 // safe/ready to be used. 92 virtual void AsyncTexImage2D( 93 const AsyncTexImage2DParams& tex_params, 94 const AsyncMemoryParams& mem_params, 95 const base::Closure& bind_callback) = 0; 96 97 virtual void AsyncTexSubImage2D( 98 const AsyncTexSubImage2DParams& tex_params, 99 const AsyncMemoryParams& mem_params) = 0; 100 101 // Returns true if there is a transfer in progress. 102 virtual bool TransferIsInProgress() = 0; 103 104 // Block until the specified transfer completes. 105 virtual void WaitForTransferCompletion() = 0; 106 107 protected: 108 AsyncPixelTransferDelegate(); 109 110 private: 111 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegate); 112 }; 113 114 } // namespace gpu 115 116 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_ 117 118