1 // Copyright 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_MANAGER_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_
10 #include "base/basictypes.h"
11 #include "base/callback.h"
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/ref_counted.h"
15 #include "gpu/command_buffer/service/texture_manager.h"
16 #include "gpu/gpu_export.h"
18 #if defined(COMPILER_GCC)
19 namespace BASE_HASH_NAMESPACE {
21 struct hash<gpu::gles2::TextureRef*> {
22 size_t operator()(gpu::gles2::TextureRef* ptr) const {
23 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
26 } // namespace BASE_HASH_NAMESPACE
34 class AsyncPixelTransferDelegate;
35 struct AsyncMemoryParams;
36 struct AsyncTexImage2DParams;
38 class AsyncPixelTransferCompletionObserver
39 : public base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver> {
41 AsyncPixelTransferCompletionObserver();
43 virtual void DidComplete(const AsyncMemoryParams& mem_params) = 0;
46 virtual ~AsyncPixelTransferCompletionObserver();
49 friend class base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver>;
51 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferCompletionObserver);
54 class GPU_EXPORT AsyncPixelTransferManager
55 : public gles2::TextureManager::DestructionObserver {
57 static AsyncPixelTransferManager* Create(gfx::GLContext* context);
59 virtual ~AsyncPixelTransferManager();
61 void Initialize(gles2::TextureManager* texture_manager);
63 virtual void BindCompletedAsyncTransfers() = 0;
65 // There's no guarantee that callback will run on the caller thread.
66 virtual void AsyncNotifyCompletion(
67 const AsyncMemoryParams& mem_params,
68 AsyncPixelTransferCompletionObserver* observer) = 0;
70 virtual uint32 GetTextureUploadCount() = 0;
71 virtual base::TimeDelta GetTotalTextureUploadTime() = 0;
73 // ProcessMorePendingTransfers() will be called at a good time
74 // to process a small amount of pending transfer work while
75 // NeedsProcessMorePendingTransfers() returns true. Implementations
76 // that can't dispatch work to separate threads should use
77 // this to avoid blocking the caller thread inappropriately.
78 virtual void ProcessMorePendingTransfers() = 0;
79 virtual bool NeedsProcessMorePendingTransfers() = 0;
81 AsyncPixelTransferDelegate* CreatePixelTransferDelegate(
82 gles2::TextureRef* ref,
83 const AsyncTexImage2DParams& define_params);
85 AsyncPixelTransferDelegate* GetPixelTransferDelegate(
86 gles2::TextureRef* ref);
88 void ClearPixelTransferDelegateForTest(gles2::TextureRef* ref);
90 bool AsyncTransferIsInProgress(gles2::TextureRef* ref);
92 // gles2::TextureRef::DestructionObserver implementation:
93 virtual void OnTextureManagerDestroying(gles2::TextureManager* manager)
95 virtual void OnTextureRefDestroying(gles2::TextureRef* texture) OVERRIDE;
98 AsyncPixelTransferManager();
101 gles2::TextureManager* manager_;
103 typedef base::hash_map<gles2::TextureRef*,
104 linked_ptr<AsyncPixelTransferDelegate> >
105 TextureToDelegateMap;
106 TextureToDelegateMap delegate_map_;
108 // A factory method called by CreatePixelTransferDelegate that is overriden
109 // by each implementation.
110 virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
111 gles2::TextureRef* ref,
112 const AsyncTexImage2DParams& define_params) = 0;
114 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManager);
119 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_