OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/platform/headless/headless_surface_factory.h" | 5 #include "ui/ozone/platform/headless/headless_surface_factory.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/task_scheduler/post_task.h" | 12 #include "base/task_scheduler/post_task.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "third_party/skia/include/core/SkSurface.h" | 14 #include "third_party/skia/include/core/SkSurface.h" |
15 #include "ui/gfx/codec/png_codec.h" | 15 #include "ui/gfx/codec/png_codec.h" |
16 #include "ui/gfx/native_pixmap.h" | 16 #include "ui/gfx/native_pixmap.h" |
17 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
18 #include "ui/gfx/vsync_provider.h" | 18 #include "ui/gfx/vsync_provider.h" |
| 19 #include "ui/ozone/common/gl_ozone_osmesa.h" |
19 #include "ui/ozone/platform/headless/headless_window.h" | 20 #include "ui/ozone/platform/headless/headless_window.h" |
20 #include "ui/ozone/platform/headless/headless_window_manager.h" | 21 #include "ui/ozone/platform/headless/headless_window_manager.h" |
21 #include "ui/ozone/public/surface_ozone_canvas.h" | 22 #include "ui/ozone/public/surface_ozone_canvas.h" |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { | 28 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { |
28 DCHECK(!location.empty()); | 29 DCHECK(!location.empty()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 DISALLOW_COPY_AND_ASSIGN(TestPixmap); | 105 DISALLOW_COPY_AND_ASSIGN(TestPixmap); |
105 }; | 106 }; |
106 | 107 |
107 } // namespace | 108 } // namespace |
108 | 109 |
109 HeadlessSurfaceFactory::HeadlessSurfaceFactory() | 110 HeadlessSurfaceFactory::HeadlessSurfaceFactory() |
110 : HeadlessSurfaceFactory(nullptr) {} | 111 : HeadlessSurfaceFactory(nullptr) {} |
111 | 112 |
112 HeadlessSurfaceFactory::HeadlessSurfaceFactory( | 113 HeadlessSurfaceFactory::HeadlessSurfaceFactory( |
113 HeadlessWindowManager* window_manager) | 114 HeadlessWindowManager* window_manager) |
114 : window_manager_(window_manager) {} | 115 : window_manager_(window_manager), |
| 116 osmesa_implementation_(base::MakeUnique<GLOzoneOSMesa>()) {} |
115 | 117 |
116 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} | 118 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} |
117 | 119 |
| 120 std::vector<gl::GLImplementation> |
| 121 HeadlessSurfaceFactory::GetAllowedGLImplementations() { |
| 122 return std::vector<gl::GLImplementation>{gl::kGLImplementationOSMesaGL}; |
| 123 } |
| 124 |
| 125 GLOzone* HeadlessSurfaceFactory::GetGLOzone( |
| 126 gl::GLImplementation implementation) { |
| 127 switch (implementation) { |
| 128 case gl::kGLImplementationOSMesaGL: |
| 129 return osmesa_implementation_.get(); |
| 130 default: |
| 131 return nullptr; |
| 132 } |
| 133 } |
| 134 |
118 std::unique_ptr<SurfaceOzoneCanvas> | 135 std::unique_ptr<SurfaceOzoneCanvas> |
119 HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { | 136 HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { |
120 HeadlessWindow* window = window_manager_->GetWindow(widget); | 137 HeadlessWindow* window = window_manager_->GetWindow(widget); |
121 return base::WrapUnique<SurfaceOzoneCanvas>(new FileSurface(window->path())); | 138 return base::WrapUnique<SurfaceOzoneCanvas>(new FileSurface(window->path())); |
122 } | 139 } |
123 | 140 |
124 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( | 141 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( |
125 gfx::AcceleratedWidget widget, | 142 gfx::AcceleratedWidget widget, |
126 gfx::Size size, | 143 gfx::Size size, |
127 gfx::BufferFormat format, | 144 gfx::BufferFormat format, |
128 gfx::BufferUsage usage) { | 145 gfx::BufferUsage usage) { |
129 return new TestPixmap(format); | 146 return new TestPixmap(format); |
130 } | 147 } |
131 | 148 |
132 } // namespace ui | 149 } // namespace ui |
OLD | NEW |