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

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

Issue 1410123003: Rename "test" ozone platform to "headless" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final fix Created 5 years, 1 month 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
« no previous file with comments | « ui/ozone/platform/test/test_surface_factory.h ('k') | ui/ozone/platform/test/test_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #include "ui/ozone/platform/test/test_surface_factory.h"
6
7 #include "base/bind.h"
8 #include "base/files/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/platform/test/test_window.h"
18 #include "ui/ozone/platform/test/test_window_manager.h"
19 #include "ui/ozone/public/surface_ozone_canvas.h"
20
21 namespace ui {
22
23 namespace {
24
25 void WriteDataToFile(const base::FilePath& location, const SkBitmap& bitmap) {
26 DCHECK(!location.empty());
27 std::vector<unsigned char> png_data;
28 gfx::PNGCodec::FastEncodeBGRASkBitmap(bitmap, true, &png_data);
29 base::WriteFile(location,
30 reinterpret_cast<const char*>(vector_as_array(&png_data)),
31 png_data.size());
32 }
33
34 class FileSurface : public SurfaceOzoneCanvas {
35 public:
36 FileSurface(const base::FilePath& location) : location_(location) {}
37 ~FileSurface() override {}
38
39 // SurfaceOzoneCanvas overrides:
40 void ResizeCanvas(const gfx::Size& viewport_size) override {
41 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
42 viewport_size.width(), viewport_size.height())));
43 }
44 skia::RefPtr<SkSurface> GetSurface() override { return surface_; }
45 void PresentCanvas(const gfx::Rect& damage) override {
46 if (location_.empty())
47 return;
48 SkBitmap bitmap;
49 bitmap.setInfo(surface_->getCanvas()->imageInfo());
50
51 // TODO(dnicoara) Use SkImage instead to potentially avoid a copy.
52 // See crbug.com/361605 for details.
53 if (surface_->getCanvas()->readPixels(&bitmap, 0, 0)) {
54 base::WorkerPool::PostTask(
55 FROM_HERE, base::Bind(&WriteDataToFile, location_, bitmap), true);
56 }
57 }
58 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
59 return nullptr;
60 }
61
62 private:
63 base::FilePath location_;
64 skia::RefPtr<SkSurface> surface_;
65 };
66
67 } // namespace
68
69 TestSurfaceFactory::TestSurfaceFactory() : TestSurfaceFactory(nullptr) {}
70
71 TestSurfaceFactory::TestSurfaceFactory(TestWindowManager* window_manager)
72 : window_manager_(window_manager) {}
73
74 TestSurfaceFactory::~TestSurfaceFactory() {}
75
76 scoped_ptr<SurfaceOzoneCanvas> TestSurfaceFactory::CreateCanvasForWidget(
77 gfx::AcceleratedWidget widget) {
78 TestWindow* window = window_manager_->GetWindow(widget);
79 return make_scoped_ptr<SurfaceOzoneCanvas>(new FileSurface(window->path()));
80 }
81
82 bool TestSurfaceFactory::LoadEGLGLES2Bindings(
83 AddGLLibraryCallback add_gl_library,
84 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
85 return false;
86 }
87
88 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/test/test_surface_factory.h ('k') | ui/ozone/platform/test/test_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698