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/gpu_export.h"
15 #include "ui/gl/gl_bindings.h"
23 class ScopedSafeSharedMemory;
25 struct AsyncTexImage2DParams {
28 GLenum internal_format;
36 struct AsyncTexSubImage2DParams {
47 struct AsyncMemoryParams {
48 base::SharedMemory* shared_memory;
50 uint32 shm_data_offset;
54 class AsyncPixelTransferUploadStats
55 : public base::RefCountedThreadSafe<AsyncPixelTransferUploadStats> {
57 AsyncPixelTransferUploadStats();
59 void AddUpload(base::TimeDelta transfer_time);
60 int GetStats(base::TimeDelta* total_texture_upload_time);
63 friend class base::RefCountedThreadSafe<AsyncPixelTransferUploadStats>;
65 ~AsyncPixelTransferUploadStats();
67 int texture_upload_count_;
68 base::TimeDelta total_texture_upload_time_;
71 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferUploadStats);
74 class GPU_EXPORT AsyncPixelTransferDelegate {
76 virtual ~AsyncPixelTransferDelegate();
78 // The callback occurs on the caller thread, once the texture is
79 // safe/ready to be used.
80 virtual void AsyncTexImage2D(
81 const AsyncTexImage2DParams& tex_params,
82 const AsyncMemoryParams& mem_params,
83 const base::Closure& bind_callback) = 0;
85 virtual void AsyncTexSubImage2D(
86 const AsyncTexSubImage2DParams& tex_params,
87 const AsyncMemoryParams& mem_params) = 0;
89 // Returns true if there is a transfer in progress.
90 virtual bool TransferIsInProgress() = 0;
92 // Block until the specified transfer completes.
93 virtual void WaitForTransferCompletion() = 0;
95 // Gets the address of the data from shared memory.
96 static void* GetAddress(const AsyncMemoryParams& mem_params);
98 // Sometimes the |safe_shared_memory| is duplicate to prevent use after free.
99 static void* GetAddress(ScopedSafeSharedMemory* safe_shared_memory,
100 const AsyncMemoryParams& mem_params);
103 AsyncPixelTransferDelegate();
106 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferDelegate);
111 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_DELEGATE_H_