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 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
7 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
11 AsyncPixelTransferCompletionObserver::AsyncPixelTransferCompletionObserver() {}
13 AsyncPixelTransferCompletionObserver::~AsyncPixelTransferCompletionObserver() {}
15 AsyncPixelTransferManager::AsyncPixelTransferManager() {}
17 AsyncPixelTransferManager::~AsyncPixelTransferManager() {
19 manager_
->RemoveObserver(this);
21 for (TextureToDelegateMap::iterator ref
= delegate_map_
.begin();
22 ref
!= delegate_map_
.end();
24 ref
->first
->RemoveObserver();
28 void AsyncPixelTransferManager::Initialize(gles2::TextureManager
* manager
) {
30 manager_
->AddObserver(this);
33 AsyncPixelTransferDelegate
*
34 AsyncPixelTransferManager::CreatePixelTransferDelegate(
35 gles2::TextureRef
* ref
,
36 const AsyncTexImage2DParams
& define_params
) {
37 DCHECK(!GetPixelTransferDelegate(ref
));
38 AsyncPixelTransferDelegate
* delegate
=
39 CreatePixelTransferDelegateImpl(ref
, define_params
);
40 delegate_map_
[ref
] = make_linked_ptr(delegate
);
45 AsyncPixelTransferDelegate
*
46 AsyncPixelTransferManager::GetPixelTransferDelegate(
47 gles2::TextureRef
* ref
) {
48 TextureToDelegateMap::iterator it
= delegate_map_
.find(ref
);
49 if (it
== delegate_map_
.end()) {
52 return it
->second
.get();
56 void AsyncPixelTransferManager::ClearPixelTransferDelegateForTest(
57 gles2::TextureRef
* ref
) {
58 TextureToDelegateMap::iterator it
= delegate_map_
.find(ref
);
59 if (it
!= delegate_map_
.end()) {
60 delegate_map_
.erase(it
);
61 ref
->RemoveObserver();
65 bool AsyncPixelTransferManager::AsyncTransferIsInProgress(
66 gles2::TextureRef
* ref
) {
67 AsyncPixelTransferDelegate
* delegate
= GetPixelTransferDelegate(ref
);
68 return delegate
&& delegate
->TransferIsInProgress();
71 void AsyncPixelTransferManager::OnTextureManagerDestroying(
72 gles2::TextureManager
* manager
) {
73 // TextureManager should outlive AsyncPixelTransferManager.
78 void AsyncPixelTransferManager::OnTextureRefDestroying(
79 gles2::TextureRef
* texture
) {
80 TextureToDelegateMap::iterator it
= delegate_map_
.find(texture
);
81 if (it
!= delegate_map_
.end()) {
82 delegate_map_
.erase(it
);
83 texture
->RemoveObserver();