Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / gpu / gpu_memory_buffer_factory_io_surface.h
blob77a2e7f1d275271fdc9e177179679e75f462fa81
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.
5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_
8 #include <IOSurface/IOSurface.h>
10 #include "base/containers/hash_tables.h"
11 #include "base/mac/scoped_cftyperef.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "content/common/gpu/gpu_memory_buffer_factory.h"
15 #include "content/common/mac/io_surface_manager.h"
16 #include "gpu/command_buffer/service/image_factory.h"
17 #include "ui/gfx/geometry/size.h"
18 #include "ui/gfx/gpu_memory_buffer.h"
20 namespace gfx {
21 class GLImage;
24 namespace content {
26 class GpuMemoryBufferFactoryIOSurface : public GpuMemoryBufferFactory,
27 public gpu::ImageFactory {
28 public:
29 GpuMemoryBufferFactoryIOSurface();
30 ~GpuMemoryBufferFactoryIOSurface() override;
32 static bool IsGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
33 gfx::BufferUsage usage);
35 // Overridden from GpuMemoryBufferFactory:
36 void GetSupportedGpuMemoryBufferConfigurations(
37 std::vector<Configuration>* configurations) override;
38 gfx::GpuMemoryBufferHandle CreateGpuMemoryBuffer(
39 gfx::GpuMemoryBufferId id,
40 const gfx::Size& size,
41 gfx::BufferFormat format,
42 gfx::BufferUsage usage,
43 int client_id,
44 gfx::PluginWindowHandle surface_handle) override;
45 void DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
46 int client_id) override;
47 gpu::ImageFactory* AsImageFactory() override;
49 // Overridden from gpu::ImageFactory:
50 scoped_refptr<gfx::GLImage> CreateImageForGpuMemoryBuffer(
51 const gfx::GpuMemoryBufferHandle& handle,
52 const gfx::Size& size,
53 gfx::BufferFormat format,
54 unsigned internalformat,
55 int client_id) override;
57 private:
58 typedef std::pair<IOSurfaceId, int> IOSurfaceMapKey;
59 typedef base::hash_map<IOSurfaceMapKey, base::ScopedCFTypeRef<IOSurfaceRef>>
60 IOSurfaceMap;
61 IOSurfaceMap io_surfaces_;
62 base::Lock io_surfaces_lock_;
64 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferFactoryIOSurface);
67 } // namespace content
69 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_BUFFER_FACTORY_IO_SURFACE_H_