1 // Copyright (c) 2012 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/image_manager.h"
7 #include "ui/gl/gl_image.h"
12 ImageManager::ImageManager() : release_after_use_(false) {
15 ImageManager::~ImageManager() {
18 void ImageManager::RegisterGpuMemoryBuffer(int32 id
,
19 gfx::GpuMemoryBufferHandle buffer
,
22 unsigned internalformat
) {
24 DVLOG(0) << "Cannot register GPU memory buffer with non-positive ID.";
28 if (LookupImage(id
)) {
29 DVLOG(0) << "GPU memory buffer ID already in use.";
33 scoped_refptr
<gfx::GLImage
> gl_image
=
34 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer
,
35 gfx::Size(width
, height
),
40 if (release_after_use_
)
41 gl_image
->SetReleaseAfterUse();
43 AddImage(gl_image
.get(), id
);
46 void ImageManager::UnregisterGpuMemoryBuffer(int32 id
) {
50 void ImageManager::AddImage(gfx::GLImage
* image
, int32 service_id
) {
51 gl_images_
[service_id
] = image
;
54 void ImageManager::RemoveImage(int32 service_id
) {
55 gl_images_
.erase(service_id
);
58 gfx::GLImage
* ImageManager::LookupImage(int32 service_id
) {
59 GLImageMap::const_iterator iter
= gl_images_
.find(service_id
);
60 if (iter
!= gl_images_
.end())
61 return iter
->second
.get();
66 void ImageManager::SetReleaseAfterUse() {
67 release_after_use_
= true;