| 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/threading/worker_pool.h" | 12 #include "base/threading/worker_pool.h" |
| 12 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "third_party/skia/include/core/SkSurface.h" | 14 #include "third_party/skia/include/core/SkSurface.h" |
| 14 #include "ui/gfx/codec/png_codec.h" | 15 #include "ui/gfx/codec/png_codec.h" |
| 15 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 16 #include "ui/gfx/vsync_provider.h" | 17 #include "ui/gfx/vsync_provider.h" |
| 17 #include "ui/ozone/platform/headless/headless_window.h" | 18 #include "ui/ozone/platform/headless/headless_window.h" |
| 18 #include "ui/ozone/platform/headless/headless_window_manager.h" | 19 #include "ui/ozone/platform/headless/headless_window_manager.h" |
| 19 #include "ui/ozone/public/native_pixmap.h" | 20 #include "ui/ozone/public/native_pixmap.h" |
| 20 #include "ui/ozone/public/surface_ozone_canvas.h" | 21 #include "ui/ozone/public/surface_ozone_canvas.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 SkBitmap bitmap; | 50 SkBitmap bitmap; |
| 50 bitmap.setInfo(surface_->getCanvas()->imageInfo()); | 51 bitmap.setInfo(surface_->getCanvas()->imageInfo()); |
| 51 | 52 |
| 52 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. | 53 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. |
| 53 // See crbug.com/361605 for details. | 54 // See crbug.com/361605 for details. |
| 54 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { | 55 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { |
| 55 base::WorkerPool::PostTask( | 56 base::WorkerPool::PostTask( |
| 56 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); | 57 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); |
| 57 } | 58 } |
| 58 } | 59 } |
| 59 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { | 60 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { |
| 60 return nullptr; | 61 return nullptr; |
| 61 } | 62 } |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 base::FilePath location_; | 65 base::FilePath location_; |
| 65 sk_sp<SkSurface> surface_; | 66 sk_sp<SkSurface> surface_; |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 class TestPixmap : public ui::NativePixmap { | 69 class TestPixmap : public ui::NativePixmap { |
| 69 public: | 70 public: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 99 | 100 |
| 100 HeadlessSurfaceFactory::HeadlessSurfaceFactory() | 101 HeadlessSurfaceFactory::HeadlessSurfaceFactory() |
| 101 : HeadlessSurfaceFactory(nullptr) {} | 102 : HeadlessSurfaceFactory(nullptr) {} |
| 102 | 103 |
| 103 HeadlessSurfaceFactory::HeadlessSurfaceFactory( | 104 HeadlessSurfaceFactory::HeadlessSurfaceFactory( |
| 104 HeadlessWindowManager* window_manager) | 105 HeadlessWindowManager* window_manager) |
| 105 : window_manager_(window_manager) {} | 106 : window_manager_(window_manager) {} |
| 106 | 107 |
| 107 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} | 108 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} |
| 108 | 109 |
| 109 scoped_ptr<SurfaceOzoneCanvas> HeadlessSurfaceFactory::CreateCanvasForWidget( | 110 std::unique_ptr<SurfaceOzoneCanvas> |
| 110 gfx::AcceleratedWidget widget) { | 111 HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { |
| 111 HeadlessWindow* window = window_manager_->GetWindow(widget); | 112 HeadlessWindow* window = window_manager_->GetWindow(widget); |
| 112 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); | 113 return base::WrapUnique<SurfaceOzoneCanvas>(new FileSurface(window->path())); |
| 113 } | 114 } |
| 114 | 115 |
| 115 bool HeadlessSurfaceFactory::LoadEGLGLES2Bindings( | 116 bool HeadlessSurfaceFactory::LoadEGLGLES2Bindings( |
| 116 AddGLLibraryCallback add_gl_library, | 117 AddGLLibraryCallback add_gl_library, |
| 117 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 118 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 118 return false; | 119 return false; |
| 119 } | 120 } |
| 120 | 121 |
| 121 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( | 122 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( |
| 122 gfx::AcceleratedWidget widget, | 123 gfx::AcceleratedWidget widget, |
| 123 gfx::Size size, | 124 gfx::Size size, |
| 124 gfx::BufferFormat format, | 125 gfx::BufferFormat format, |
| 125 gfx::BufferUsage usage) { | 126 gfx::BufferUsage usage) { |
| 126 return new TestPixmap(format); | 127 return new TestPixmap(format); |
| 127 } | 128 } |
| 128 | 129 |
| 129 } // namespace ui | 130 } // namespace ui |
| OLD | NEW |