Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_io_surface.cc
blobed7836c197d43e5a68fb9a8496caf0fbd71742a5
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 "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
7 #include "base/logging.h"
9 namespace content {
11 GpuMemoryBufferImplIOSurface::GpuMemoryBufferImplIOSurface(
12 gfx::GpuMemoryBufferId id,
13 const gfx::Size& size,
14 Format format,
15 const DestructionCallback& callback,
16 IOSurfaceRef io_surface)
17 : GpuMemoryBufferImpl(id, size, format, callback), io_surface_(io_surface) {
20 GpuMemoryBufferImplIOSurface::~GpuMemoryBufferImplIOSurface() {
23 // static
24 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImplIOSurface::CreateFromHandle(
25 const gfx::GpuMemoryBufferHandle& handle,
26 const gfx::Size& size,
27 Format format,
28 const DestructionCallback& callback) {
29 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(
30 IOSurfaceLookup(handle.io_surface_id));
31 if (!io_surface)
32 return scoped_ptr<GpuMemoryBufferImpl>();
34 return make_scoped_ptr<GpuMemoryBufferImpl>(new GpuMemoryBufferImplIOSurface(
35 handle.id, size, format, callback, io_surface.release()));
38 bool GpuMemoryBufferImplIOSurface::Map(void** data) {
39 DCHECK(!mapped_);
40 IOSurfaceLock(io_surface_, 0, NULL);
41 mapped_ = true;
42 *data = IOSurfaceGetBaseAddress(io_surface_);
43 return true;
46 void GpuMemoryBufferImplIOSurface::Unmap() {
47 DCHECK(mapped_);
48 IOSurfaceUnlock(io_surface_, 0, NULL);
49 mapped_ = false;
52 void GpuMemoryBufferImplIOSurface::GetStride(int* stride) const {
53 *stride = IOSurfaceGetBytesPerRow(io_surface_);
56 gfx::GpuMemoryBufferHandle GpuMemoryBufferImplIOSurface::GetHandle() const {
57 gfx::GpuMemoryBufferHandle handle;
58 handle.type = gfx::IO_SURFACE_BUFFER;
59 handle.id = id_;
60 handle.io_surface_id = IOSurfaceGetID(io_surface_);
61 return handle;
64 } // namespace content