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.
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_
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"
24 struct AsyncTexImage2DParams {
27 GLenum internal_format;
35 struct AsyncTexSubImage2DParams {
46 class AsyncMemoryParams {
48 AsyncMemoryParams(scoped_refptr<Buffer> buffer,
53 scoped_refptr<Buffer> buffer() const { return buffer_; }
54 uint32 data_size() const { return data_size_; }
55 uint32 data_offset() const { return data_offset_; }
56 void* GetDataAddress() const {
57 return buffer_->GetDataAddress(data_offset_, data_size_);
61 scoped_refptr<Buffer> buffer_;
66 class AsyncPixelTransferUploadStats
67 : public base::RefCountedThreadSafe<AsyncPixelTransferUploadStats> {
69 AsyncPixelTransferUploadStats();
71 void AddUpload(base::TimeDelta transfer_time);
72 int GetStats(base::TimeDelta* total_texture_upload_time);
75 friend class base::RefCountedThreadSafe<AsyncPixelTransferUploadStats>;
77 ~AsyncPixelTransferUploadStats();
79 int texture_upload_count_;
80 base::TimeDelta total_texture_upload_time_;
83 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferUploadStats);
86 class GPU_EXPORT AsyncPixelTransferDelegate {
88 virtual ~AsyncPixelTransferDelegate();
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;
97 virtual void AsyncTexSubImage2D(
98 const AsyncTexSubImage2DParams& tex_params,
99 const AsyncMemoryParams& mem_params) = 0;
101 // Returns true if there is a transfer in progress.
102 virtual bool TransferIsInProgress() = 0;
104 // Block until the specified transfer completes.
105 virtual void WaitForTransferCompletion() = 0;
108 AsyncPixelTransferDelegate();
111 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegate);
116 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_