• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
6 
7 #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h"
8 
9 namespace gpu {
10 
AsyncPixelTransferCompletionObserver()11 AsyncPixelTransferCompletionObserver::AsyncPixelTransferCompletionObserver() {}
12 
~AsyncPixelTransferCompletionObserver()13 AsyncPixelTransferCompletionObserver::~AsyncPixelTransferCompletionObserver() {}
14 
AsyncPixelTransferManager()15 AsyncPixelTransferManager::AsyncPixelTransferManager() {}
16 
~AsyncPixelTransferManager()17 AsyncPixelTransferManager::~AsyncPixelTransferManager() {
18   if (manager_)
19     manager_->RemoveObserver(this);
20 }
21 
Initialize(gles2::TextureManager * manager)22 void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) {
23   manager_ = manager;
24   manager_->AddObserver(this);
25 }
26 
27 AsyncPixelTransferDelegate*
CreatePixelTransferDelegate(gles2::TextureRef * ref,const AsyncTexImage2DParams & define_params)28 AsyncPixelTransferManager::CreatePixelTransferDelegate(
29     gles2::TextureRef* ref,
30     const AsyncTexImage2DParams& define_params) {
31   DCHECK(!GetPixelTransferDelegate(ref));
32   AsyncPixelTransferDelegate* delegate =
33       CreatePixelTransferDelegateImpl(ref, define_params);
34   delegate_map_[ref] = make_linked_ptr(delegate);
35   return delegate;
36 }
37 
38 AsyncPixelTransferDelegate*
GetPixelTransferDelegate(gles2::TextureRef * ref)39 AsyncPixelTransferManager::GetPixelTransferDelegate(
40     gles2::TextureRef* ref) {
41   TextureToDelegateMap::iterator it = delegate_map_.find(ref);
42   if (it == delegate_map_.end()) {
43     return NULL;
44   } else {
45     return it->second.get();
46   }
47 }
48 
ClearPixelTransferDelegateForTest(gles2::TextureRef * ref)49 void AsyncPixelTransferManager::ClearPixelTransferDelegateForTest(
50     gles2::TextureRef* ref) {
51   TextureToDelegateMap::iterator it = delegate_map_.find(ref);
52   if (it != delegate_map_.end())
53     delegate_map_.erase(it);
54 }
55 
AsyncTransferIsInProgress(gles2::TextureRef * ref)56 bool AsyncPixelTransferManager::AsyncTransferIsInProgress(
57     gles2::TextureRef* ref) {
58   AsyncPixelTransferDelegate* delegate = GetPixelTransferDelegate(ref);
59   return delegate && delegate->TransferIsInProgress();
60 }
61 
OnTextureManagerDestroying(gles2::TextureManager * manager)62 void AsyncPixelTransferManager::OnTextureManagerDestroying(
63     gles2::TextureManager* manager) {
64   // TextureManager should outlive AsyncPixelTransferManager.
65   NOTREACHED();
66   manager_ = NULL;
67 }
68 
OnTextureRefDestroying(gles2::TextureRef * texture)69 void AsyncPixelTransferManager::OnTextureRefDestroying(
70     gles2::TextureRef* texture) {
71   TextureToDelegateMap::iterator it = delegate_map_.find(texture);
72   if (it != delegate_map_.end())
73     delegate_map_.erase(it);
74 }
75 
76 }  // namespace gpu
77