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
3 // found in the LICENSE file.
5 #include "ui/gfx/ozone/impl/file_surface_factory_ozone.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/SkBitmapDevice.h"
13 #include "third_party/skia/include/core/SkDevice.h"
14 #include "ui/gfx/codec/png_codec.h"
18 void WriteDataToFile(const base::FilePath& location,
19 const SkBitmap& bitmap) {
20 std::vector<unsigned char> png_data;
21 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
22 file_util::WriteFile(location,
23 (char*)vector_as_array(&png_data),
31 FileSurfaceFactoryOzone::FileSurfaceFactoryOzone(
32 const base::FilePath& dump_location)
33 : location_(dump_location) {
34 CHECK(!base::DirectoryExists(location_))
35 << "Location cannot be a directory (" << location_.value() << ")";
36 CHECK(!base::PathExists(location_) || base::PathIsWritable(location_));
39 FileSurfaceFactoryOzone::~FileSurfaceFactoryOzone() {}
41 SurfaceFactoryOzone::HardwareState
42 FileSurfaceFactoryOzone::InitializeHardware() {
46 void FileSurfaceFactoryOzone::ShutdownHardware() {
49 AcceleratedWidget FileSurfaceFactoryOzone::GetAcceleratedWidget() {
53 AcceleratedWidget FileSurfaceFactoryOzone::RealizeAcceleratedWidget(
54 AcceleratedWidget widget) {
58 bool FileSurfaceFactoryOzone::LoadEGLGLES2Bindings(
59 AddGLLibraryCallback add_gl_library,
60 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
64 bool FileSurfaceFactoryOzone::AttemptToResizeAcceleratedWidget(
65 AcceleratedWidget widget,
67 device_ = skia::AdoptRef(new SkBitmapDevice(SkBitmap::kARGB_8888_Config,
70 canvas_ = skia::AdoptRef(new SkCanvas(device_.get()));
74 bool FileSurfaceFactoryOzone::SchedulePageFlip(AcceleratedWidget widget) {
76 bitmap.setConfig(SkBitmap::kARGB_8888_Config,
80 if (canvas_->readPixels(&bitmap, 0, 0)) {
81 base::WorkerPool::PostTask(FROM_HERE,
82 base::Bind(&WriteDataToFile, location_, bitmap),
88 SkCanvas* FileSurfaceFactoryOzone::GetCanvasForWidget(AcceleratedWidget w) {
92 VSyncProvider* FileSurfaceFactoryOzone::GetVSyncProvider(AcceleratedWidget w) {