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

Side by Side Diff: ui/gfx/ozone/impl/file_surface_factory.cc

Issue 205433002: ozone: Add OzoneSurface object that is owned by compositor, GLSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing InitializeCanvas to FileSurface Created 6 years, 9 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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.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 #include "ui/gfx/ozone/surface_ozone.h"
16 #include "ui/gfx/skia_util.h"
15 #include "ui/gfx/vsync_provider.h" 17 #include "ui/gfx/vsync_provider.h"
16 18
19 namespace gfx {
20
17 namespace { 21 namespace {
18 22
19 void WriteDataToFile(const base::FilePath& location, 23 void WriteDataToFile(const base::FilePath& location,
20 const SkBitmap& bitmap) { 24 const SkBitmap& bitmap) {
21 std::vector<unsigned char> png_data; 25 std::vector<unsigned char> png_data;
22 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data); 26 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
23 base::WriteFile(location, 27 base::WriteFile(location,
24 reinterpret_cast<const char*>(vector_as_array(&png_data)), 28 reinterpret_cast<const char*>(vector_as_array(&png_data)),
25 png_data.size()); 29 png_data.size());
26 } 30 }
27 31
28 } 32 class FileSurface : public SurfaceOzone {
33 public:
34 FileSurface(const base::FilePath& location) : location_(location) {}
35 virtual ~FileSurface() {}
29 36
30 namespace gfx { 37 bool InitializeCanvas() OVERRIDE {
38 return true;
39 }
40
41 bool ResizeCanvas(const Rect& bounds) OVERRIDE {
42 device_ = skia::AdoptRef(new SkBitmapDevice(
43 SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()));
44 canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
45 return true;
46 }
47
48 SkCanvas* GetCanvas() OVERRIDE { return canvas_.get(); }
49
50 bool SwapCanvas() OVERRIDE {
51 SkBitmap bitmap;
52 bitmap.setConfig(
53 SkBitmap::kARGB_8888_Config, device_->width(), device_->height());
54
55 if (canvas_->readPixels(&bitmap, 0, 0)) {
56 base::WorkerPool::PostTask(
57 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
58 }
59 return true;
60 }
61
62 private:
63 base::FilePath location_;
64 skia::RefPtr<SkBitmapDevice> device_;
65 skia::RefPtr<SkCanvas> canvas_;
66 };
67
68 } // namespace
31 69
32 FileSurfaceFactory::FileSurfaceFactory( 70 FileSurfaceFactory::FileSurfaceFactory(
33 const base::FilePath& dump_location) 71 const base::FilePath& dump_location)
34 : location_(dump_location) { 72 : location_(dump_location) {
35 CHECK(!base::DirectoryExists(location_)) 73 CHECK(!base::DirectoryExists(location_))
36 << "Location cannot be a directory (" << location_.value() << ")"; 74 << "Location cannot be a directory (" << location_.value() << ")";
37 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_)); 75 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_));
38 } 76 }
39 77
40 FileSurfaceFactory::~FileSurfaceFactory() {} 78 FileSurfaceFactory::~FileSurfaceFactory() {}
41 79
42 SurfaceFactoryOzone::HardwareState 80 SurfaceFactoryOzone::HardwareState
43 FileSurfaceFactory::InitializeHardware() { 81 FileSurfaceFactory::InitializeHardware() {
44 return INITIALIZED; 82 return INITIALIZED;
45 } 83 }
46 84
47 void FileSurfaceFactory::ShutdownHardware() { 85 void FileSurfaceFactory::ShutdownHardware() {
48 } 86 }
49 87
50 AcceleratedWidget FileSurfaceFactory::GetAcceleratedWidget() { 88 AcceleratedWidget FileSurfaceFactory::GetAcceleratedWidget() {
51 return 1; 89 return 1;
52 } 90 }
53 91
54 AcceleratedWidget FileSurfaceFactory::RealizeAcceleratedWidget( 92 scoped_ptr<SurfaceOzone> FileSurfaceFactory::CreateSurfaceForWidget(
55 AcceleratedWidget widget) { 93 AcceleratedWidget widget) {
56 return 1; 94 return make_scoped_ptr<SurfaceOzone>(new FileSurface(location_));
57 } 95 }
58 96
59 bool FileSurfaceFactory::LoadEGLGLES2Bindings( 97 bool FileSurfaceFactory::LoadEGLGLES2Bindings(
60 AddGLLibraryCallback add_gl_library, 98 AddGLLibraryCallback add_gl_library,
61 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { 99 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
62 return false; 100 return false;
63 } 101 }
64 102
65 bool FileSurfaceFactory::AttemptToResizeAcceleratedWidget(
66 AcceleratedWidget widget,
67 const Rect& bounds) {
68 device_ = skia::AdoptRef(new SkBitmapDevice(SkBitmap::kARGB_8888_Config,
69 bounds.width(),
70 bounds.height()));
71 canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
72 return true;
73 }
74
75 bool FileSurfaceFactory::SchedulePageFlip(AcceleratedWidget widget) {
76 SkBitmap bitmap;
77 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
78 device_->width(),
79 device_->height());
80
81 if (canvas_->readPixels(&bitmap, 0, 0)) {
82 base::WorkerPool::PostTask(FROM_HERE,
83 base::Bind(&WriteDataToFile, location_, bitmap),
84 true);
85 }
86 return true;
87 }
88
89 SkCanvas* FileSurfaceFactory::GetCanvasForWidget(AcceleratedWidget w) {
90 return canvas_.get();
91 }
92
93 scoped_ptr<VSyncProvider> FileSurfaceFactory::CreateVSyncProvider(
94 AcceleratedWidget w) {
95 return scoped_ptr<VSyncProvider>();
96 }
97
98 } // namespace gfx 103 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698