Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: ui/ozone/platform/test/test_window_manager.cc

Issue 419993003: Adds a do-nothing ozone platform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adds a do-nothing ozone platform when --ozone-dump-file is not specified (rebased) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/platform/test/test_window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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) {
82 return windows_.Add(window); 87 return windows_.Add(window);
83 } 88 }
(...skipping 14 matching lines...) Expand all
98 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path())); 103 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path()));
99 } 104 }
100 105
101 bool TestWindowManager::LoadEGLGLES2Bindings( 106 bool TestWindowManager::LoadEGLGLES2Bindings(
102 AddGLLibraryCallback add_gl_library, 107 AddGLLibraryCallback add_gl_library,
103 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { 108 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
104 return false; 109 return false;
105 } 110 }
106 111
107 } // namespace ui 112 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/test/test_window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698