| 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 17 matching lines...) Expand all Loading... |
| 28 DCHECK(!location.empty()); | 28 DCHECK(!location.empty()); |
| 29 std::vector<unsigned char> png_data; | 29 std::vector<unsigned char> png_data; |
| 30 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); | 30 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); |
| 31 base::WriteFile(location, reinterpret_cast<const char*>(png_data.data()), | 31 base::WriteFile(location, reinterpret_cast<const char*>(png_data.data()), |
| 32 png_data.size()); | 32 png_data.size()); |
| 33 } | 33 } |
| 34 | 34 |
| 35 // TODO(altimin): Find a proper way to capture rendering output. | 35 // TODO(altimin): Find a proper way to capture rendering output. |
| 36 class FileSurface : public SurfaceOzoneCanvas { | 36 class FileSurface : public SurfaceOzoneCanvas { |
| 37 public: | 37 public: |
| 38 FileSurface(const base::FilePath& location) : location_(location) {} | 38 explicit FileSurface(const base::FilePath& location) : location_(location) {} |
| 39 ~FileSurface() override {} | 39 ~FileSurface() override {} |
| 40 | 40 |
| 41 // SurfaceOzoneCanvas overrides: | 41 // SurfaceOzoneCanvas overrides: |
| 42 void ResizeCanvas(const gfx::Size& viewport_size) override { | 42 void ResizeCanvas(const gfx::Size& viewport_size) override { |
| 43 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( | 43 surface_ = SkSurface::MakeRaster(SkImageInfo::MakeN32Premul( |
| 44 viewport_size.width(), viewport_size.height())); | 44 viewport_size.width(), viewport_size.height())); |
| 45 } | 45 } |
| 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()) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 61 return nullptr; | 61 return nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 base::FilePath location_; | 65 base::FilePath location_; |
| 66 sk_sp<SkSurface> surface_; | 66 sk_sp<SkSurface> surface_; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class TestPixmap : public ui::NativePixmap { | 69 class TestPixmap : public ui::NativePixmap { |
| 70 public: | 70 public: |
| 71 TestPixmap(gfx::BufferFormat format) : format_(format) {} | 71 explicit TestPixmap(gfx::BufferFormat format) : format_(format) {} |
| 72 | 72 |
| 73 void* GetEGLClientBuffer() const override { return nullptr; } | 73 void* GetEGLClientBuffer() const override { return nullptr; } |
| 74 bool AreDmaBufFdsValid() const override { return false; } | 74 bool AreDmaBufFdsValid() const override { return false; } |
| 75 size_t GetDmaBufFdCount() const override { return 0; } | 75 size_t GetDmaBufFdCount() const override { return 0; } |
| 76 int GetDmaBufFd(size_t plane) const override { return -1; } | 76 int GetDmaBufFd(size_t plane) const override { return -1; } |
| 77 int GetDmaBufPitch(size_t plane) const override { return 0; } | 77 int GetDmaBufPitch(size_t plane) const override { return 0; } |
| 78 int GetDmaBufOffset(size_t plane) const override { return 0; } | 78 int GetDmaBufOffset(size_t plane) const override { return 0; } |
| 79 uint64_t GetDmaBufModifier(size_t plane) const override { return 0; } | 79 uint64_t GetDmaBufModifier(size_t plane) const override { return 0; } |
| 80 gfx::BufferFormat GetBufferFormat() const override { return format_; } | 80 gfx::BufferFormat GetBufferFormat() const override { return format_; } |
| 81 gfx::Size GetBufferSize() const override { return gfx::Size(); } | 81 gfx::Size GetBufferSize() const override { return gfx::Size(); } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 110 : window_manager_(window_manager) {} | 110 : window_manager_(window_manager) {} |
| 111 | 111 |
| 112 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} | 112 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} |
| 113 | 113 |
| 114 std::unique_ptr<SurfaceOzoneCanvas> | 114 std::unique_ptr<SurfaceOzoneCanvas> |
| 115 HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { | 115 HeadlessSurfaceFactory::CreateCanvasForWidget(gfx::AcceleratedWidget widget) { |
| 116 HeadlessWindow* window = window_manager_->GetWindow(widget); | 116 HeadlessWindow* window = window_manager_->GetWindow(widget); |
| 117 return base::WrapUnique<SurfaceOzoneCanvas>(new FileSurface(window->path())); | 117 return base::WrapUnique<SurfaceOzoneCanvas>(new FileSurface(window->path())); |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool HeadlessSurfaceFactory::LoadEGLGLES2Bindings( | |
| 121 AddGLLibraryCallback add_gl_library, | |
| 122 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | |
| 123 return false; | |
| 124 } | |
| 125 | |
| 126 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( | 120 scoped_refptr<NativePixmap> HeadlessSurfaceFactory::CreateNativePixmap( |
| 127 gfx::AcceleratedWidget widget, | 121 gfx::AcceleratedWidget widget, |
| 128 gfx::Size size, | 122 gfx::Size size, |
| 129 gfx::BufferFormat format, | 123 gfx::BufferFormat format, |
| 130 gfx::BufferUsage usage) { | 124 gfx::BufferUsage usage) { |
| 131 return new TestPixmap(format); | 125 return new TestPixmap(format); |
| 132 } | 126 } |
| 133 | 127 |
| 134 } // namespace ui | 128 } // namespace ui |
| OLD | NEW |