Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / async_pixel_transfer_manager.h
blob1a818f3c1ad80a18a4da5ad42e6c9711c76ddfff
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_
8 #include <set>
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 {
20 template <>
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
27 #endif // COMPILER
29 namespace gfx {
30 class GLContext;
33 namespace gpu {
34 class AsyncPixelTransferDelegate;
35 class AsyncMemoryParams;
36 struct AsyncTexImage2DParams;
38 class AsyncPixelTransferCompletionObserver
39 : public base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver> {
40 public:
41 AsyncPixelTransferCompletionObserver();
43 virtual void DidComplete(const AsyncMemoryParams& mem_params) = 0;
45 protected:
46 virtual ~AsyncPixelTransferCompletionObserver();
48 private:
49 friend class base::RefCountedThreadSafe<AsyncPixelTransferCompletionObserver>;
51 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferCompletionObserver);
54 class GPU_EXPORT AsyncPixelTransferManager
55 : public gles2::TextureManager::DestructionObserver {
56 public:
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 // Wait for all AsyncTex(Sub)Image2D uploads to finish before returning.
82 virtual void WaitAllAsyncTexImage2D() = 0;
84 AsyncPixelTransferDelegate* CreatePixelTransferDelegate(
85 gles2::TextureRef* ref,
86 const AsyncTexImage2DParams& define_params);
88 AsyncPixelTransferDelegate* GetPixelTransferDelegate(
89 gles2::TextureRef* ref);
91 void ClearPixelTransferDelegateForTest(gles2::TextureRef* ref);
93 bool AsyncTransferIsInProgress(gles2::TextureRef* ref);
95 // gles2::TextureRef::DestructionObserver implementation:
96 virtual void OnTextureManagerDestroying(gles2::TextureManager* manager)
97 OVERRIDE;
98 virtual void OnTextureRefDestroying(gles2::TextureRef* texture) OVERRIDE;
100 protected:
101 AsyncPixelTransferManager();
103 private:
104 gles2::TextureManager* manager_;
106 typedef base::hash_map<gles2::TextureRef*,
107 linked_ptr<AsyncPixelTransferDelegate> >
108 TextureToDelegateMap;
109 TextureToDelegateMap delegate_map_;
111 // A factory method called by CreatePixelTransferDelegate that is overriden
112 // by each implementation.
113 virtual AsyncPixelTransferDelegate* CreatePixelTransferDelegateImpl(
114 gles2::TextureRef* ref,
115 const AsyncTexImage2DParams& define_params) = 0;
117 DISALLOW_COPY_AND_ASSIGN(AsyncPixelTransferManager);
120 } // namespace gpu
122 #endif // GPU_COMMAND_BUFFER_SERVICE_ASYNC_PIXEL_TRANSFER_MANAGER_H_