| 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/threading/worker_pool.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/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
| 17 #include "ui/gfx/vsync_provider.h" | 17 #include "ui/gfx/vsync_provider.h" |
| 18 #include "ui/ozone/platform/headless/headless_window.h" | 18 #include "ui/ozone/platform/headless/headless_window.h" |
| 19 #include "ui/ozone/platform/headless/headless_window_manager.h" | 19 #include "ui/ozone/platform/headless/headless_window_manager.h" |
| 20 #include "ui/ozone/public/native_pixmap.h" | 20 #include "ui/ozone/public/native_pixmap.h" |
| 21 #include "ui/ozone/public/surface_ozone_canvas.h" | 21 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 22 | 22 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 46 sk_sp<SkSurface> GetSurface() override { return surface_; } | 46 sk_sp<SkSurface> GetSurface() override { return surface_; } |
| 47 void PresentCanvas(const gfx::Rect& damage) override { | 47 void PresentCanvas(const gfx::Rect& damage) override { |
| 48 if (location_.empty()) | 48 if (location_.empty()) |
| 49 return; | 49 return; |
| 50 SkBitmap bitmap; | 50 SkBitmap bitmap; |
| 51 bitmap.setInfo(surface_->getCanvas()->imageInfo()); | 51 bitmap.setInfo(surface_->getCanvas()->imageInfo()); |
| 52 | 52 |
| 53 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. | 53 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. |
| 54 // See crbug.com/361605 for details. | 54 // See crbug.com/361605 for details. |
| 55 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { | 55 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { |
| 56 base::WorkerPool::PostTask( | 56 base::PostTaskWithTraits( |
| 57 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); | 57 FROM_HERE, base::TaskTraits() |
| 58 .WithShutdownBehavior( |
| 59 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) |
| 60 .MayBlock(), |
| 61 base::Bind(&WriteDataToFile, location_, bitmap)); |
| 58 } | 62 } |
| 59 } | 63 } |
| 60 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { | 64 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { |
| 61 return nullptr; | 65 return nullptr; |
| 62 } | 66 } |
| 63 | 67 |
| 64 private: | 68 private: |
| 65 base::FilePath location_; | 69 base::FilePath location_; |
| 66 sk_sp<SkSurface> surface_; | 70 sk_sp<SkSurface> surface_; |
| 67 }; | 71 }; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 123 |
| 120 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( | 124 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( |
| 121 gfx::AcceleratedWidget widget, | 125 gfx::AcceleratedWidget widget, |
| 122 gfx::Size size, | 126 gfx::Size size, |
| 123 gfx::BufferFormat format, | 127 gfx::BufferFormat format, |
| 124 gfx::BufferUsage usage) { | 128 gfx::BufferUsage usage) { |
| 125 return new TestPixmap(format); | 129 return new TestPixmap(format); |
| 126 } | 130 } |
| 127 | 131 |
| 128 } // namespace ui | 132 } // namespace ui |
| OLD | NEW |