| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 } | 32 } |
| 33 | 33 |
| 34 // TODO(altimin): Find a proper way to capture rendering output. | 34 // TODO(altimin): Find a proper way to capture rendering output. |
| 35 class FileSurface : public SurfaceOzoneCanvas { | 35 class FileSurface : public SurfaceOzoneCanvas { |
| 36 public: | 36 public: |
| 37 FileSurface(const base::FilePath& location) : location_(location) {} | 37 FileSurface(const base::FilePath& location) : location_(location) {} |
| 38 ~FileSurface() override {} | 38 ~FileSurface() override {} |
| 39 | 39 |
| 40 // SurfaceOzoneCanvas overrides: | 40 // SurfaceOzoneCanvas overrides: |
| 41 void ResizeCanvas(const gfx::Size& viewport_size) override { | 41 void ResizeCanvas(const gfx::Size& viewport_size) override { |
| 42 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul( | 42 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( |
| 43 viewport_size.width(), viewport_size.height()))); | 43 viewport_size.width(), viewport_size.height())); |
| 44 } | 44 } |
| 45 skia::RefPtr<SkSurface> GetSurface() override { return surface_; } | 45 sk_sp<SkSurface> GetSurface() override { return surface_; } |
| 46 void PresentCanvas(const gfx::Rect& damage) override { | 46 void PresentCanvas(const gfx::Rect& damage) override { |
| 47 if (location_.empty()) | 47 if (location_.empty()) |
| 48 return; | 48 return; |
| 49 SkBitmap bitmap; | 49 SkBitmap bitmap; |
| 50 bitmap.setInfo(surface_->getCanvas()->imageInfo()); | 50 bitmap.setInfo(surface_->getCanvas()->imageInfo()); |
| 51 | 51 |
| 52 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. | 52 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. |
| 53 // See crbug.com/361605 for details. | 53 // See crbug.com/361605 for details. |
| 54 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { | 54 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { |
| 55 base::WorkerPool::PostTask( | 55 base::WorkerPool::PostTask( |
| 56 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); | 56 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { | 59 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override { |
| 60 return nullptr; | 60 return nullptr; |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 base::FilePath location_; | 64 base::FilePath location_; |
| 65 skia::RefPtr<SkSurface> surface_; | 65 sk_sp<SkSurface> surface_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 class TestPixmap : public ui::NativePixmap { | 68 class TestPixmap : public ui::NativePixmap { |
| 69 public: | 69 public: |
| 70 TestPixmap(gfx::BufferFormat format) : format_(format) {} | 70 TestPixmap(gfx::BufferFormat format) : format_(format) {} |
| 71 | 71 |
| 72 void* GetEGLClientBuffer() const override { return nullptr; } | 72 void* GetEGLClientBuffer() const override { return nullptr; } |
| 73 int GetDmaBufFd() const override { return -1; } | 73 int GetDmaBufFd() const override { return -1; } |
| 74 int GetDmaBufPitch() const override { return 0; } | 74 int GetDmaBufPitch() const override { return 0; } |
| 75 gfx::BufferFormat GetBufferFormat() const override { return format_; } | 75 gfx::BufferFormat GetBufferFormat() const override { return format_; } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( | 121 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( |
| 122 gfx::AcceleratedWidget widget, | 122 gfx::AcceleratedWidget widget, |
| 123 gfx::Size size, | 123 gfx::Size size, |
| 124 gfx::BufferFormat format, | 124 gfx::BufferFormat format, |
| 125 gfx::BufferUsage usage) { | 125 gfx::BufferUsage usage) { |
| 126 return new TestPixmap(format); | 126 return new TestPixmap(format); |
| 127 } | 127 } |
| 128 | 128 |
| 129 } // namespace ui | 129 } // namespace ui |
| OLD | NEW |