1// Copyright 2014 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#ifndef CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
6#define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
7
8#include <IOSurface/IOSurfaceAPI.h>
9
10#include "base/containers/hash_tables.h"
11#include "base/mac/scoped_cftyperef.h"
12#include "base/memory/ref_counted.h"
13#include "ui/gfx/geometry/size.h"
14#include "ui/gfx/gpu_memory_buffer.h"
15
16namespace gfx {
17class GLImage;
18}
19
20namespace content {
21
22class GpuMemoryBufferFactoryIOSurface {
23 public:
24  GpuMemoryBufferFactoryIOSurface();
25  ~GpuMemoryBufferFactoryIOSurface();
26
27  // Creates a IOSurface backed GPU memory buffer with |size| and
28  // |internalformat|. A valid handle is returned on success.
29  gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
30      const gfx::GpuMemoryBufferId& id,
31      const gfx::Size& size,
32      unsigned internalformat);
33
34  // Destroy a previously created GPU memory buffer.
35  void DestroyGpuMemoryBuffer(const gfx::GpuMemoryBufferId& id);
36
37  // Creates a GLImage instance for a GPU memory buffer.
38  scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
39      const gfx::GpuMemoryBufferId& id,
40      const gfx::Size& size,
41      unsigned internalformat);
42
43 private:
44  typedef std::pair<int, int> IOSurfaceMapKey;
45  typedef base::hash_map<IOSurfaceMapKey, base::ScopedCFTypeRef<IOSurfaceRef>>
46      IOSurfaceMap;
47  IOSurfaceMap io_surfaces_;
48};
49
50}  // namespace content
51
52#endif  // CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
53