[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / ozone / platform / test / file_surface_factory.cc
blobab1e67cbaad31323009c504365845ebbb98d86c0
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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/test/file_surface_factory.h"
7 #include "base/bind.h"
8 #include "base/file_util.h"
9 #include "base/location.h"
10 #include "base/stl_util.h"
11 #include "base/threading/worker_pool.h"
12 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkSurface.h"
14 #include "ui/gfx/codec/png_codec.h"
15 #include "ui/gfx/skia_util.h"
16 #include "ui/gfx/vsync_provider.h"
17 #include "ui/ozone/public/surface_ozone_canvas.h"
19 namespace ui {
21 namespace {
23 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) {
24 std::vector<unsigned char> png_data;
25 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
26 base::WriteFile(location,
27 reinterpret_cast<const char*>(vector_as_array(&png_data)),
28 png_data.size());
31 class FileSurface : public SurfaceOzoneCanvas {
32 public:
33 FileSurface(const base::FilePath& location) : location_(location) {}
34 virtual ~FileSurface() {}
36 // SurfaceOzoneCanvas overrides:
37 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE {
38 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
39 viewport_size.width(), viewport_size.height())));
41 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE {
42 return skia::SharePtr(surface_->getCanvas());
44 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE {
45 SkBitmap bitmap;
46 bitmap.setInfo(surface_->getCanvas()->imageInfo());
48 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy.
49 // See crbug.com/361605 for details.
50 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) {
51 base::WorkerPool::PostTask(
52 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
55 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE {
56 return scoped_ptr<gfx::VSyncProvider>();
59 private:
60 base::FilePath location_;
61 skia::RefPtr<SkSurface> surface_;
64 } // namespace
66 FileSurfaceFactory::FileSurfaceFactory(const base::FilePath& dump_location)
67 : location_(dump_location) {
68 CHECK(!base::DirectoryExists(location_)) << "Location cannot be a directory ("
69 << location_.value() << ")";
70 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_));
73 FileSurfaceFactory::~FileSurfaceFactory() {
76 SurfaceFactoryOzone::HardwareState FileSurfaceFactory::InitializeHardware() {
77 return INITIALIZED;
80 void FileSurfaceFactory::ShutdownHardware() {
83 gfx::AcceleratedWidget FileSurfaceFactory::GetAcceleratedWidget() {
84 return 1;
87 scoped_ptr<SurfaceOzoneCanvas> FileSurfaceFactory::CreateCanvasForWidget(
88 gfx::AcceleratedWidget w) {
89 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(location_));
92 bool FileSurfaceFactory::LoadEGLGLES2Bindings(
93 AddGLLibraryCallback add_gl_library,
94 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
95 return false;
98 } // namespace ui