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

Side by Side Diff: ui/ozone/platform/cast/surface_factory_cast.cc

Issue 1478753003: [Chromecast] Support software rendering when disable-gpu used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use disable-gpu to enable software canvas Created 5 years 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/ozone/platform/cast/surface_factory_cast.h" 5 #include "ui/ozone/platform/cast/surface_factory_cast.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <EGL/egl.h> 8 #include <EGL/egl.h>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
11 #include "chromecast/public/cast_egl_platform.h" 11 #include "chromecast/public/cast_egl_platform.h"
12 #include "chromecast/public/graphics_types.h" 12 #include "chromecast/public/graphics_types.h"
13 #include "third_party/skia/include/core/SkSurface.h"
13 #include "ui/gfx/geometry/quad_f.h" 14 #include "ui/gfx/geometry/quad_f.h"
15 #include "ui/gfx/vsync_provider.h"
14 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" 16 #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h"
15 #include "ui/ozone/public/native_pixmap.h" 17 #include "ui/ozone/public/native_pixmap.h"
18 #include "ui/ozone/public/surface_ozone_canvas.h"
16 19
17 using chromecast::CastEglPlatform; 20 using chromecast::CastEglPlatform;
18 21
19 namespace ui { 22 namespace ui {
20 23
21 namespace { 24 namespace {
22 25
23 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType); 26 typedef EGLDisplay (*EGLGetDisplayFn)(NativeDisplayType);
24 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay); 27 typedef EGLBoolean (*EGLTerminateFn)(EGLDisplay);
25 28
26 chromecast::Size FromGfxSize(const gfx::Size& size) { 29 chromecast::Size FromGfxSize(const gfx::Size& size) {
27 return chromecast::Size(size.width(), size.height()); 30 return chromecast::Size(size.width(), size.height());
28 } 31 }
29 32
30 // Initial display size to create, needed before first window is created. 33 // Initial display size to create, needed before first window is created.
31 gfx::Size GetInitialDisplaySize() { 34 gfx::Size GetInitialDisplaySize() {
32 return gfx::Size(1280, 720); 35 return gfx::Size(1280, 720);
33 } 36 }
34 37
35 // Hard lower bound on display resolution 38 // Hard lower bound on display resolution
36 gfx::Size GetMinDisplaySize() { 39 gfx::Size GetMinDisplaySize() {
37 return gfx::Size(1280, 720); 40 return gfx::Size(1280, 720);
38 } 41 }
39 42
43 class DummySurface : public SurfaceOzoneCanvas {
44 public:
45 DummySurface() {}
46 ~DummySurface() override {}
47
48 // SurfaceOzoneCanvas implementation:
49 skia::RefPtr<SkSurface> GetSurface() override { return surface_; }
50
51 void ResizeCanvas(const gfx::Size& viewport_size) override {
52 surface_ = skia::AdoptRef(SkSurface::NewRaster(SkImageInfo::MakeN32Premul(
53 viewport_size.width(), viewport_size.height())));
54 }
55
56 void PresentCanvas(const gfx::Rect& damage) override {}
57
58 scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() override {
59 return nullptr;
60 }
61
62 private:
slan 2015/12/08 22:40:25 nit: DISALLOW....
halliwell 2015/12/08 23:27:56 Done.
63 skia::RefPtr<SkSurface> surface_;
64 };
65
40 } // namespace 66 } // namespace
41 67
68 SurfaceFactoryCast::SurfaceFactoryCast()
derekjchow1 2015/12/08 22:03:15 Can this call the constructor on line 76 and pass
slan 2015/12/08 22:40:25 +1, now valid in chrome to forward.
halliwell 2015/12/08 23:27:56 Done.
69 : state_(kUninitialized),
70 display_type_(0),
71 have_display_type_(false),
72 window_(0),
73 display_size_(GetInitialDisplaySize()),
74 new_display_size_(GetInitialDisplaySize()) {}
75
42 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform) 76 SurfaceFactoryCast::SurfaceFactoryCast(scoped_ptr<CastEglPlatform> egl_platform)
43 : state_(kUninitialized), 77 : state_(kUninitialized),
44 display_type_(0), 78 display_type_(0),
45 have_display_type_(false), 79 have_display_type_(false),
46 window_(0), 80 window_(0),
47 display_size_(GetInitialDisplaySize()), 81 display_size_(GetInitialDisplaySize()),
48 new_display_size_(GetInitialDisplaySize()), 82 new_display_size_(GetInitialDisplaySize()),
49 egl_platform_(egl_platform.Pass()) { 83 egl_platform_(egl_platform.Pass()) {
50 } 84 }
51 85
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (state_ != kInitialized) 124 if (state_ != kInitialized)
91 return; 125 return;
92 126
93 DestroyDisplayTypeAndWindow(); 127 DestroyDisplayTypeAndWindow();
94 128
95 egl_platform_->ShutdownHardware(); 129 egl_platform_->ShutdownHardware();
96 130
97 state_ = kUninitialized; 131 state_ = kUninitialized;
98 } 132 }
99 133
134 scoped_ptr<SurfaceOzoneCanvas> SurfaceFactoryCast::CreateCanvasForWidget(
135 gfx::AcceleratedWidget w) {
136 // Software canvas support only in headless mode
137 if (egl_platform_)
138 return nullptr;
139 return make_scoped_ptr<SurfaceOzoneCanvas>(new DummySurface());
140 }
141
100 intptr_t SurfaceFactoryCast::GetNativeDisplay() { 142 intptr_t SurfaceFactoryCast::GetNativeDisplay() {
101 CreateDisplayTypeAndWindowIfNeeded(); 143 CreateDisplayTypeAndWindowIfNeeded();
102 return reinterpret_cast<intptr_t>(display_type_); 144 return reinterpret_cast<intptr_t>(display_type_);
103 } 145 }
104 146
105 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { 147 void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() {
106 if (state_ == kUninitialized) { 148 if (state_ == kUninitialized) {
107 InitializeHardware(); 149 InitializeHardware();
108 } 150 }
109 if (new_display_size_ != display_size_) { 151 if (new_display_size_ != display_size_) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return false; 281 return false;
240 } 282 }
241 283
242 set_gl_get_proc_address.Run(gl_proc); 284 set_gl_get_proc_address.Run(gl_proc);
243 add_gl_library.Run(lib_egl); 285 add_gl_library.Run(lib_egl);
244 add_gl_library.Run(lib_gles2); 286 add_gl_library.Run(lib_gles2);
245 return true; 287 return true;
246 } 288 }
247 289
248 } // namespace ui 290 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698