Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_window_manager.h" | 5 #include "ui/ozone/platform/test/test_window_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/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/public/surface_ozone_canvas.h" | 17 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { | 23 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) { |
| 24 DCHECK(!location.empty()); | |
| 24 std::vector<unsigned char> png_data; | 25 std::vector<unsigned char> png_data; |
| 25 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); | 26 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); |
| 26 base::WriteFile(location, | 27 base::WriteFile(location, |
| 27 reinterpret_cast<const char*>(vector_as_array(&png_data)), | 28 reinterpret_cast<const char*>(vector_as_array(&png_data)), |
| 28 png_data.size()); | 29 png_data.size()); |
| 29 } | 30 } |
| 30 | 31 |
| 31 class FileSurface : public SurfaceOzoneCanvas { | 32 class FileSurface : public SurfaceOzoneCanvas { |
| 32 public: | 33 public: |
| 33 FileSurface(const base::FilePath& location) : location_(location) {} | 34 FileSurface(const base::FilePath& location) : location_(location) {} |
| 34 virtual ~FileSurface() {} | 35 virtual ~FileSurface() {} |
| 35 | 36 |
| 36 // SurfaceOzoneCanvas overrides: | 37 // SurfaceOzoneCanvas overrides: |
| 37 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE { | 38 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE { |
| 38 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul( | 39 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul( |
| 39 viewport_size.width(), viewport_size.height()))); | 40 viewport_size.width(), viewport_size.height()))); |
| 40 } | 41 } |
| 41 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { | 42 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE { |
| 42 return skia::SharePtr(surface_->getCanvas()); | 43 return skia::SharePtr(surface_->getCanvas()); |
| 43 } | 44 } |
| 44 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE { | 45 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE { |
| 46 if (location_.empty()) | |
| 47 return; | |
| 45 SkBitmap bitmap; | 48 SkBitmap bitmap; |
| 46 bitmap.setInfo(surface_->getCanvas()->imageInfo()); | 49 bitmap.setInfo(surface_->getCanvas()->imageInfo()); |
| 47 | 50 |
| 48 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. | 51 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy. |
| 49 // See crbug.com/361605 for details. | 52 // See crbug.com/361605 for details. |
| 50 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { | 53 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) { |
| 51 base::WorkerPool::PostTask( | 54 base::WorkerPool::PostTask( |
| 52 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); | 55 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true); |
| 53 } | 56 } |
| 54 } | 57 } |
| 55 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { | 58 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE { |
| 56 return scoped_ptr<gfx::VSyncProvider>(); | 59 return scoped_ptr<gfx::VSyncProvider>(); |
| 57 } | 60 } |
| 58 | 61 |
| 59 private: | 62 private: |
| 60 base::FilePath location_; | 63 base::FilePath location_; |
| 61 skia::RefPtr<SkSurface> surface_; | 64 skia::RefPtr<SkSurface> surface_; |
| 62 }; | 65 }; |
| 63 | 66 |
| 64 } // namespace | 67 } // namespace |
| 65 | 68 |
| 66 TestWindowManager::TestWindowManager(const base::FilePath& dump_location) | 69 TestWindowManager::TestWindowManager(const base::FilePath& dump_location) |
| 67 : location_(dump_location) { | 70 : location_(dump_location) { |
| 68 } | 71 } |
| 69 | 72 |
| 70 TestWindowManager::~TestWindowManager() { | 73 TestWindowManager::~TestWindowManager() { |
| 71 } | 74 } |
| 72 | 75 |
| 73 void TestWindowManager::Initialize() { | 76 void TestWindowManager::Initialize() { |
| 77 if (location_.empty()) | |
| 78 return; | |
| 74 if (!DirectoryExists(location_) && !base::CreateDirectory(location_) && | 79 if (!DirectoryExists(location_) && !base::CreateDirectory(location_) && |
| 75 location_ != base::FilePath("/dev/null")) | 80 location_ != base::FilePath("/dev/null")) |
| 76 PLOG(FATAL) << "unable to create output directory"; | 81 PLOG(FATAL) << "unable to create output directory"; |
| 77 if (!base::PathIsWritable(location_)) | 82 if (!base::PathIsWritable(location_)) |
| 78 PLOG(FATAL) << "unable to write to output location"; | 83 PLOG(FATAL) << "unable to write to output location"; |
| 79 } | 84 } |
| 80 | 85 |
| 81 int32_t TestWindowManager::AddWindow(TestWindow* window) { | 86 int32_t TestWindowManager::AddWindow(TestWindow* window) { |
| 87 if (location_.empty()) | |
| 88 return 1; | |
| 82 return windows_.Add(window); | 89 return windows_.Add(window); |
| 83 } | 90 } |
| 84 | 91 |
| 85 void TestWindowManager::RemoveWindow(int32_t window_id, TestWindow* window) { | 92 void TestWindowManager::RemoveWindow(int32_t window_id, TestWindow* window) { |
| 93 if (location_.empty()) | |
| 94 return; | |
| 86 DCHECK_EQ(window, windows_.Lookup(window_id)); | 95 DCHECK_EQ(window, windows_.Lookup(window_id)); |
| 87 windows_.Remove(window_id); | 96 windows_.Remove(window_id); |
| 88 } | 97 } |
| 89 | 98 |
| 90 base::FilePath TestWindowManager::base_path() const { | 99 base::FilePath TestWindowManager::base_path() const { |
| 91 return location_; | 100 return location_; |
| 92 } | 101 } |
| 93 | 102 |
| 94 scoped_ptr<SurfaceOzoneCanvas> TestWindowManager::CreateCanvasForWidget( | 103 scoped_ptr<SurfaceOzoneCanvas> TestWindowManager::CreateCanvasForWidget( |
| 95 gfx::AcceleratedWidget widget) { | 104 gfx::AcceleratedWidget widget) { |
| 105 if (location_.empty()) { | |
|
dnicoara
2014/07/31 02:51:31
There is no reason to complicate the code with the
spang
2014/07/31 16:04:01
I think we need the one in Initialize() and in Pre
dnicoara
2014/07/31 16:09:23
The one in CreateCanvasForWidget shouldn't be need
varkha
2014/08/07 00:17:10
Acknowledged.
varkha
2014/08/07 00:17:10
Done.
varkha
2014/08/07 00:17:11
Done.
| |
| 106 return make_scoped_ptr<SurfaceOzoneCanvas>( | |
| 107 new FileSurface(base::FilePath())); | |
| 108 } | |
| 96 TestWindow* window = windows_.Lookup(widget); | 109 TestWindow* window = windows_.Lookup(widget); |
| 97 DCHECK(window); | 110 DCHECK(window); |
| 98 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); | 111 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); |
| 99 } | 112 } |
| 100 | 113 |
| 101 bool TestWindowManager::LoadEGLGLES2Bindings( | 114 bool TestWindowManager::LoadEGLGLES2Bindings( |
| 102 AddGLLibraryCallback add_gl_library, | 115 AddGLLibraryCallback add_gl_library, |
| 103 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 116 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 104 return false; | 117 return false; |
| 105 } | 118 } |
| 106 | 119 |
| 107 } // namespace ui | 120 } // namespace ui |
| OLD | NEW |