OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/gfx/ozone/impl/file_surface_factory_ozone.h" | 5 #include "ui/gfx/ozone/impl/file_surface_factory.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/SkBitmapDevice.h" | 12 #include "third_party/skia/include/core/SkBitmapDevice.h" |
13 #include "third_party/skia/include/core/SkDevice.h" | 13 #include "third_party/skia/include/core/SkDevice.h" |
14 #include "ui/gfx/codec/png_codec.h" | 14 #include "ui/gfx/codec/png_codec.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 void WriteDataToFile(const base::FilePath& location, | 18 void WriteDataToFile(const base::FilePath& location, |
19 const SkBitmap& bitmap) { | 19 const SkBitmap& bitmap) { |
20 std::vector<unsigned char> png_data; | 20 std::vector<unsigned char> png_data; |
21 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); | 21 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); |
22 file_util::WriteFile(location, | 22 file_util::WriteFile(location, |
23 (char*)vector_as_array(&png_data), | 23 (char*)vector_as_array(&png_data), |
24 png_data.size()); | 24 png_data.size()); |
25 } | 25 } |
26 | 26 |
27 } | 27 } |
28 | 28 |
29 namespace gfx { | 29 namespace gfx { |
30 | 30 |
31 FileSurfaceFactoryOzone::FileSurfaceFactoryOzone( | 31 FileSurfaceFactory::FileSurfaceFactory( |
32 const base::FilePath& dump_location) | 32 const base::FilePath& dump_location) |
33 : location_(dump_location) { | 33 : location_(dump_location) { |
34 CHECK(!base::DirectoryExists(location_)) | 34 CHECK(!base::DirectoryExists(location_)) |
35 << "Location cannot be a directory (" << location_.value() << ")"; | 35 << "Location cannot be a directory (" << location_.value() << ")"; |
36 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_)); | 36 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_)); |
37 } | 37 } |
38 | 38 |
39 FileSurfaceFactoryOzone::~FileSurfaceFactoryOzone() {} | 39 FileSurfaceFactory::~FileSurfaceFactory() {} |
40 | 40 |
41 SurfaceFactoryOzone::HardwareState | 41 SurfaceFactoryOzone::HardwareState |
42 FileSurfaceFactoryOzone::InitializeHardware() { | 42 FileSurfaceFactory::InitializeHardware() { |
43 return INITIALIZED; | 43 return INITIALIZED; |
44 } | 44 } |
45 | 45 |
46 void FileSurfaceFactoryOzone::ShutdownHardware() { | 46 void FileSurfaceFactory::ShutdownHardware() { |
47 } | 47 } |
48 | 48 |
49 AcceleratedWidget FileSurfaceFactoryOzone::GetAcceleratedWidget() { | 49 AcceleratedWidget FileSurfaceFactory::GetAcceleratedWidget() { |
50 return 1; | 50 return 1; |
51 } | 51 } |
52 | 52 |
53 AcceleratedWidget FileSurfaceFactoryOzone::RealizeAcceleratedWidget( | 53 AcceleratedWidget FileSurfaceFactory::RealizeAcceleratedWidget( |
54 AcceleratedWidget widget) { | 54 AcceleratedWidget widget) { |
55 return 1; | 55 return 1; |
56 } | 56 } |
57 | 57 |
58 bool FileSurfaceFactoryOzone::LoadEGLGLES2Bindings( | 58 bool FileSurfaceFactory::LoadEGLGLES2Bindings( |
59 AddGLLibraryCallback add_gl_library, | 59 AddGLLibraryCallback add_gl_library, |
60 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 60 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 bool FileSurfaceFactoryOzone::AttemptToResizeAcceleratedWidget( | 64 bool FileSurfaceFactory::AttemptToResizeAcceleratedWidget( |
65 AcceleratedWidget widget, | 65 AcceleratedWidget widget, |
66 const Rect& bounds) { | 66 const Rect& bounds) { |
67 device_ = skia::AdoptRef(new SkBitmapDevice(SkBitmap::kARGB_8888_Config, | 67 device_ = skia::AdoptRef(new SkBitmapDevice(SkBitmap::kARGB_8888_Config, |
68 bounds.width(), | 68 bounds.width(), |
69 bounds.height())); | 69 bounds.height())); |
70 canvas_ = skia::AdoptRef(new SkCanvas(device_.get())); | 70 canvas_ = skia::AdoptRef(new SkCanvas(device_.get())); |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 bool FileSurfaceFactoryOzone::SchedulePageFlip(AcceleratedWidget widget) { | 74 bool FileSurfaceFactory::SchedulePageFlip(AcceleratedWidget widget) { |
75 SkBitmap bitmap; | 75 SkBitmap bitmap; |
76 bitmap.setConfig(SkBitmap::kARGB_8888_Config, | 76 bitmap.setConfig(SkBitmap::kARGB_8888_Config, |
77 device_->width(), | 77 device_->width(), |
78 device_->height()); | 78 device_->height()); |
79 | 79 |
80 if (canvas_->readPixels(&bitmap, 0, 0)) { | 80 if (canvas_->readPixels(&bitmap, 0, 0)) { |
81 base::WorkerPool::PostTask(FROM_HERE, | 81 base::WorkerPool::PostTask(FROM_HERE, |
82 base::Bind(&WriteDataToFile, location_, bitmap), | 82 base::Bind(&WriteDataToFile, location_, bitmap), |
83 true); | 83 true); |
84 } | 84 } |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 SkCanvas* FileSurfaceFactoryOzone::GetCanvasForWidget(AcceleratedWidget w) { | 88 SkCanvas* FileSurfaceFactory::GetCanvasForWidget(AcceleratedWidget w) { |
89 return canvas_.get(); | 89 return canvas_.get(); |
90 } | 90 } |
91 | 91 |
92 VSyncProvider* FileSurfaceFactoryOzone::GetVSyncProvider(AcceleratedWidget w) { | 92 VSyncProvider* FileSurfaceFactory::GetVSyncProvider(AcceleratedWidget w) { |
93 return NULL; | 93 return NULL; |
94 } | 94 } |
95 | 95 |
96 } // namespace gfx | 96 } // namespace gfx |
OLD | NEW |