OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_ | |
6 #define GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_ | |
7 | |
8 #include <set> | |
9 | |
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" | |
17 | |
18 namespace gfx { | |
19 class GLContext; | |
20 } | |
21 | |
22 namespace gpu { | |
23 class AsyncPixelTransferDelegate; | |
24 class AsyncMemoryParams; | |
25 struct AsyncTexImage2DParams; | |
26 | |
27 class AsyncPixelTransferCompletionObserver | |
28 : public base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver> { | |
29 public: | |
30 AsyncPixelTransferCompletionObserver(); | |
31 | |
32 virtual void DidComplete(const AsyncMemoryParams& mem_params) = 0; | |
33 | |
34 protected: | |
35 virtual ~AsyncPixelTransferCompletionObserver(); | |
36 | |
37 private: | |
38 friend class base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver>; | |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferCompletionObserver); | |
41 }; | |
42 | |
43 class GPU_EXPORT AsyncPixelTransferManager | |
44 : public gles2::TextureManager::DestructionObserver { | |
45 public: | |
46 static AsyncPixelTransferManager* Create(gfx::GLContext* context); | |
47 | |
48 ~AsyncPixelTransferManager() override; | |
49 | |
50 void Initialize(gles2::TextureManager* texture_manager); | |
51 | |
52 virtual void BindCompletedAsyncTransfers() = 0; | |
53 | |
54 // There's no guarantee that callback will run on the caller thread. | |
55 virtual void AsyncNotifyCompletion( | |
56 const AsyncMemoryParams& mem_params, | |
57 AsyncPixelTransferCompletionObserver* observer) = 0; | |
58 | |
59 virtual uint32 GetTextureUploadCount() = 0; | |
60 virtual base::TimeDelta GetTotalTextureUploadTime() = 0; | |
61 | |
62 // ProcessMorePendingTransfers() will be called at a good time | |
63 // to process a small amount of pending transfer work while | |
64 // NeedsProcessMorePendingTransfers() returns true. Implementations | |
65 // that can't dispatch work to separate threads should use | |
66 // this to avoid blocking the caller thread inappropriately. | |
67 virtual void ProcessMorePendingTransfers() = 0; | |
68 virtual bool NeedsProcessMorePendingTransfers() = 0; | |
69 | |
70 // Wait for all AsyncTex(Sub)Image2D uploads to finish before returning. | |
71 virtual void WaitAllAsyncTexImage2D() = 0; | |
72 | |
73 AsyncPixelTransferDelegate* CreatePixelTransferDelegate( | |
74 gles2::TextureRef* ref, | |
75 const AsyncTexImage2DParams& define_params); | |
76 | |
77 AsyncPixelTransferDelegate* GetPixelTransferDelegate( | |
78 gles2::TextureRef* ref); | |
79 | |
80 void ClearPixelTransferDelegateForTest(gles2::TextureRef* ref); | |
81 | |
82 bool AsyncTransferIsInProgress(gles2::TextureRef* ref); | |
83 | |
84 // gles2::TextureRef::DestructionObserver implementation: | |
85 void OnTextureManagerDestroying(gles2::TextureManager* manager) override; | |
86 void OnTextureRefDestroying(gles2::TextureRef* texture) override; | |
87 | |
88 protected: | |
89 AsyncPixelTransferManager(); | |
90 | |
91 private: | |
92 gles2::TextureManager* manager_; | |
93 | |
94 typedef base::hash_map<gles2::TextureRef*, | |
95 linked_ptr<AsyncPixelTransferDelegate> > | |
96 TextureToDelegateMap; | |
97 TextureToDelegateMap delegate_map_; | |
98 | |
99 // A factory method called by CreatePixelTransferDelegate that is overriden | |
100 // by each implementation. | |
101 virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl( | |
102 gles2::TextureRef* ref, | |
103 const AsyncTexImage2DParams& define_params) = 0; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManager); | |
106 }; | |
107 | |
108 } // namespace gpu | |
109 | |
110 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_ | |
OLD | NEW |