Home | History | Annotate | Download | only in service
      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 
     11 AsyncPixelTransferCompletionObserver::AsyncPixelTransferCompletionObserver() {}
     12 
     13 AsyncPixelTransferCompletionObserver::~AsyncPixelTransferCompletionObserver() {}
     14 
     15 AsyncPixelTransferManager::AsyncPixelTransferManager() {}
     16 
     17 AsyncPixelTransferManager::~AsyncPixelTransferManager() {
     18   if (manager_)
     19     manager_->RemoveObserver(this);
     20 
     21   for (TextureToDelegateMap::iterator ref = delegate_map_.begin();
     22        ref != delegate_map_.end();
     23        ref++) {
     24     ref->first->RemoveObserver();
     25   }
     26 }
     27 
     28 void AsyncPixelTransferManager::Initialize(gles2::TextureManager* manager) {
     29   manager_ = manager;
     30   manager_->AddObserver(this);
     31 }
     32 
     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);
     41   ref->AddObserver();
     42   return delegate;
     43 }
     44 
     45 AsyncPixelTransferDelegate*
     46 AsyncPixelTransferManager::GetPixelTransferDelegate(
     47     gles2::TextureRef* ref) {
     48   TextureToDelegateMap::iterator it = delegate_map_.find(ref);
     49   if (it == delegate_map_.end()) {
     50     return NULL;
     51   } else {
     52     return it->second.get();
     53   }
     54 }
     55 
     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();
     62   }
     63 }
     64 
     65 bool AsyncPixelTransferManager::AsyncTransferIsInProgress(
     66     gles2::TextureRef* ref) {
     67   AsyncPixelTransferDelegate* delegate = GetPixelTransferDelegate(ref);
     68   return delegate && delegate->TransferIsInProgress();
     69 }
     70 
     71 void AsyncPixelTransferManager::OnTextureManagerDestroying(
     72     gles2::TextureManager* manager) {
     73   // TextureManager should outlive AsyncPixelTransferManager.
     74   NOTREACHED();
     75   manager_ = NULL;
     76 }
     77 
     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();
     84   }
     85 }
     86 
     87 }  // namespace gpu
     88