OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" | 5 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
6 | 6 |
7 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" | 7 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
8 | 8 |
9 namespace gpu { | 9 namespace gpu { |
10 | 10 |
11 AsyncPixelTransferManager::AsyncPixelTransferManager() {} | 11 AsyncPixelTransferManager::AsyncPixelTransferManager() {} |
12 | 12 |
13 AsyncPixelTransferManager::~AsyncPixelTransferManager() { | 13 AsyncPixelTransferManager::~AsyncPixelTransferManager() { |
14 if (manager_) | 14 if (manager_) |
15 manager_->RemoveObserver(this); | 15 manager_->RemoveObserver(this); |
16 } | 16 } |
17 | 17 |
18 void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) { | 18 void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) { |
19 manager_ = manager; | 19 manager_ = manager; |
20 manager_->AddObserver(this); | 20 manager_->AddObserver(this); |
21 } | 21 } |
22 | 22 |
23 AsyncPixelTransferState* AsyncPixelTransferManager::CreatePixelTransferState( | 23 AsyncPixelTransferDelegate* |
| 24 AsyncPixelTransferManager::CreatePixelTransferDelegate( |
24 gles2::TextureRef* ref, | 25 gles2::TextureRef* ref, |
25 const AsyncTexImage2DParams& define_params) { | 26 const AsyncTexImage2DParams& define_params) { |
26 DCHECK(!GetPixelTransferState(ref)); | 27 DCHECK(!GetPixelTransferDelegate(ref)); |
27 AsyncPixelTransferState* state = | 28 AsyncPixelTransferDelegate* delegate = |
28 GetAsyncPixelTransferDelegate()->CreatePixelTransferState( | 29 CreatePixelTransferDelegateImpl(ref, define_params); |
29 ref->texture()->service_id(), define_params); | 30 delegate_map_[ref] = make_linked_ptr(delegate); |
30 state_map_[ref] = state; | 31 return delegate; |
31 return state; | |
32 } | 32 } |
33 | 33 |
34 AsyncPixelTransferState* | 34 AsyncPixelTransferDelegate* |
35 AsyncPixelTransferManager::GetPixelTransferState( | 35 AsyncPixelTransferManager::GetPixelTransferDelegate( |
36 gles2::TextureRef* ref) { | 36 gles2::TextureRef* ref) { |
37 TextureToStateMap::iterator it = state_map_.find(ref); | 37 TextureToDelegateMap::iterator it = delegate_map_.find(ref); |
38 if (it == state_map_.end()) { | 38 if (it == delegate_map_.end()) { |
39 return NULL; | 39 return NULL; |
40 } else { | 40 } else { |
41 return it->second.get(); | 41 return it->second.get(); |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 void AsyncPixelTransferManager::ClearPixelTransferStateForTest( | 45 void AsyncPixelTransferManager::ClearPixelTransferDelegateForTest( |
46 gles2::TextureRef* ref) { | 46 gles2::TextureRef* ref) { |
47 TextureToStateMap::iterator it = state_map_.find(ref); | 47 TextureToDelegateMap::iterator it = delegate_map_.find(ref); |
48 if (it != state_map_.end()) | 48 if (it != delegate_map_.end()) |
49 state_map_.erase(it); | 49 delegate_map_.erase(it); |
50 } | 50 } |
51 | 51 |
52 bool AsyncPixelTransferManager::AsyncTransferIsInProgress( | 52 bool AsyncPixelTransferManager::AsyncTransferIsInProgress( |
53 gles2::TextureRef* ref) { | 53 gles2::TextureRef* ref) { |
54 AsyncPixelTransferState* state = GetPixelTransferState(ref); | 54 AsyncPixelTransferDelegate* delegate = GetPixelTransferDelegate(ref); |
55 return state && state->TransferIsInProgress(); | 55 return delegate && delegate->TransferIsInProgress(); |
56 } | 56 } |
57 | 57 |
58 void AsyncPixelTransferManager::OnTextureManagerDestroying( | 58 void AsyncPixelTransferManager::OnTextureManagerDestroying( |
59 gles2::TextureManager* manager) { | 59 gles2::TextureManager* manager) { |
60 // TextureManager should outlive AsyncPixelTransferManager. | 60 // TextureManager should outlive AsyncPixelTransferManager. |
61 NOTREACHED(); | 61 NOTREACHED(); |
62 manager_ = NULL; | 62 manager_ = NULL; |
63 } | 63 } |
64 | 64 |
65 void AsyncPixelTransferManager::OnTextureRefDestroying( | 65 void AsyncPixelTransferManager::OnTextureRefDestroying( |
66 gles2::TextureRef* texture) { | 66 gles2::TextureRef* texture) { |
67 TextureToStateMap::iterator it = state_map_.find(texture); | 67 TextureToDelegateMap::iterator it = delegate_map_.find(texture); |
68 if (it != state_map_.end()) | 68 if (it != delegate_map_.end()) |
69 state_map_.erase(it); | 69 delegate_map_.erase(it); |
70 } | 70 } |
71 | 71 |
72 } // namespace gpu | 72 } // namespace gpu |
OLD | NEW |