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/test/test_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/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
12 #include "third_party/skia/include/core/SkCanvas.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
13 #include "third_party/skia/include/core/SkSurface.h" | 13 #include "third_party/skia/include/core/SkSurface.h" |
14 #include "ui/gfx/codec/png_codec.h" | 14 #include "ui/gfx/codec/png_codec.h" |
15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
16 #include "ui/gfx/vsync_provider.h" | 16 #include "ui/gfx/vsync_provider.h" |
17 #include "ui/ozone/platform/test/test_window.h" | 17 #include "ui/ozone/platform/headless/headless_window.h" |
18 #include "ui/ozone/platform/test/test_window_manager.h" | 18 #include "ui/ozone/platform/headless/headless_window_manager.h" |
19 #include "ui/ozone/public/surface_ozone_canvas.h" | 19 #include "ui/ozone/public/surface_ozone_canvas.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { | 25 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { |
26 DCHECK(!location.empty()); | 26 DCHECK(!location.empty()); |
27 std::vector<unsigned char> png_data; | 27 std::vector<unsigned char> png_data; |
28 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); | 28 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); |
29 base::WriteFile(location, | 29 base::WriteFile(location, |
30 reinterpret_cast<const char*>(vector_as_array(&png_data)), | 30 reinterpret_cast<const char*>(vector_as_array(&png_data)), |
31 png_data.size()); | 31 png_data.size()); |
32 } | 32 } |
33 | 33 |
34 class FileSurface : public SurfaceOzoneCanvas { | 34 class FileSurface : public SurfaceOzoneCanvas { |
Sami
2015/10/26 16:47:07
Could you add a TODO here about figuring out what
altimin
2015/10/26 17:24:21
Done.
| |
35 public: | 35 public: |
36 FileSurface(const base::FilePath& location) : location_(location) {} | 36 FileSurface(const base::FilePath& location) : location_(location) {} |
37 ~FileSurface() override {} | 37 ~FileSurface() override {} |
38 | 38 |
39 // SurfaceOzoneCanvas overrides: | 39 // SurfaceOzoneCanvas overrides: |
40 void ResizeCanvas(const gfx::Size& viewport_size) override { | 40 void ResizeCanvas(const gfx::Size& viewport_size) override { |
41 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul( | 41 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul( |
42 viewport_size.width(), viewport_size.height()))); | 42 viewport_size.width(), viewport_size.height()))); |
43 } | 43 } |
44 skia::RefPtr<SkSurface> GetSurface() override { return surface_; } | 44 skia::RefPtr<SkSurface> GetSurface() override { return surface_; } |
(...skipping 14 matching lines...) Expand all Loading... | |
59 return nullptr; | 59 return nullptr; |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 base::FilePath location_; | 63 base::FilePath location_; |
64 skia::RefPtr<SkSurface> surface_; | 64 skia::RefPtr<SkSurface> surface_; |
65 }; | 65 }; |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 TestSurfaceFactory::TestSurfaceFactory() : TestSurfaceFactory(nullptr) {} | 69 HeadlessSurfaceFactory::HeadlessSurfaceFactory() |
70 : HeadlessSurfaceFactory(nullptr) {} | |
70 | 71 |
71 TestSurfaceFactory::TestSurfaceFactory(TestWindowManager* window_manager) | 72 HeadlessSurfaceFactory::HeadlessSurfaceFactory( |
73 HeadlessWindowManager* window_manager) | |
72 : window_manager_(window_manager) {} | 74 : window_manager_(window_manager) {} |
73 | 75 |
74 TestSurfaceFactory::~TestSurfaceFactory() {} | 76 HeadlessSurfaceFactory::~HeadlessSurfaceFactory() {} |
75 | 77 |
76 scoped_ptr<SurfaceOzoneCanvas> TestSurfaceFactory::CreateCanvasForWidget( | 78 scoped_ptr<SurfaceOzoneCanvas> HeadlessSurfaceFactory::CreateCanvasForWidget( |
77 gfx::AcceleratedWidget widget) { | 79 gfx::AcceleratedWidget widget) { |
78 TestWindow* window = window_manager_->GetWindow(widget); | 80 HeadlessWindow* window = window_manager_->GetWindow(widget); |
79 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); | 81 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); |
80 } | 82 } |
81 | 83 |
82 bool TestSurfaceFactory::LoadEGLGLES2Bindings( | 84 bool HeadlessSurfaceFactory::LoadEGLGLES2Bindings( |
83 AddGLLibraryCallback add_gl_library, | 85 AddGLLibraryCallback add_gl_library, |
84 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 86 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
85 return false; | 87 return false; |
86 } | 88 } |
87 | 89 |
88 } // namespace ui | 90 } // namespace ui |
OLD | NEW |