OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/dri/dri_surface_factory.h" | 5 #include "ui/ozone/platform/dri/dri_surface_factory.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 SkRect clip; | 39 SkRect clip; |
40 clip.set( | 40 clip.set( |
41 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height()); | 41 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height()); |
42 canvas->clipRect(clip, SkRegion::kReplace_Op); | 42 canvas->clipRect(clip, SkRegion::kReplace_Op); |
43 canvas->drawBitmapRectToRect(image, &damage, damage); | 43 canvas->drawBitmapRectToRect(image, &damage, damage); |
44 } | 44 } |
45 | 45 |
46 class DriSurfaceAdapter : public ui::SurfaceOzoneCanvas { | 46 class DriSurfaceAdapter : public ui::SurfaceOzoneCanvas { |
47 public: | 47 public: |
48 DriSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); | 48 DriSurfaceAdapter(DriWrapper* dri, |
| 49 const base::WeakPtr<HardwareDisplayController>& controller); |
49 virtual ~DriSurfaceAdapter(); | 50 virtual ~DriSurfaceAdapter(); |
50 | 51 |
51 // SurfaceOzoneCanvas: | 52 // SurfaceOzoneCanvas: |
52 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; | 53 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; |
53 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; | 54 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; |
54 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; | 55 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; |
55 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | 56 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
56 | 57 |
57 private: | 58 private: |
58 void UpdateNativeSurface(const gfx::Rect& damage); | 59 void UpdateNativeSurface(const gfx::Rect& damage); |
59 | 60 |
| 61 DriWrapper* dri_; |
| 62 scoped_ptr<DriSurface> native_surface_; |
60 skia::RefPtr<SkSurface> surface_; | 63 skia::RefPtr<SkSurface> surface_; |
61 gfx::Rect last_damage_; | 64 gfx::Rect last_damage_; |
62 base::WeakPtr<HardwareDisplayController> controller_; | 65 base::WeakPtr<HardwareDisplayController> controller_; |
63 | 66 |
64 DISALLOW_COPY_AND_ASSIGN(DriSurfaceAdapter); | 67 DISALLOW_COPY_AND_ASSIGN(DriSurfaceAdapter); |
65 }; | 68 }; |
66 | 69 |
67 DriSurfaceAdapter::DriSurfaceAdapter( | 70 DriSurfaceAdapter::DriSurfaceAdapter( |
| 71 DriWrapper* dri, |
68 const base::WeakPtr<HardwareDisplayController>& controller) | 72 const base::WeakPtr<HardwareDisplayController>& controller) |
69 : controller_(controller) { | 73 : dri_(dri), controller_(controller) { |
70 } | 74 } |
71 | 75 |
72 DriSurfaceAdapter::~DriSurfaceAdapter() { | 76 DriSurfaceAdapter::~DriSurfaceAdapter() { |
73 } | 77 } |
74 | 78 |
75 skia::RefPtr<SkCanvas> DriSurfaceAdapter::GetCanvas() { | 79 skia::RefPtr<SkCanvas> DriSurfaceAdapter::GetCanvas() { |
76 return skia::SharePtr(surface_->getCanvas()); | 80 return skia::SharePtr(surface_->getCanvas()); |
77 } | 81 } |
78 | 82 |
79 void DriSurfaceAdapter::ResizeCanvas(const gfx::Size& viewport_size) { | 83 void DriSurfaceAdapter::ResizeCanvas(const gfx::Size& viewport_size) { |
80 SkImageInfo info = SkImageInfo::MakeN32( | 84 SkImageInfo info = SkImageInfo::MakeN32( |
81 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType); | 85 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType); |
82 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); | 86 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); |
| 87 |
| 88 if (controller_) { |
| 89 // Need to use the mode size rather than |viewport_size| since a display |
| 90 // cannot scanout from a buffer smaller than the mode. |
| 91 native_surface_.reset( |
| 92 new DriSurface(dri_, |
| 93 gfx::Size(controller_->get_mode().hdisplay, |
| 94 controller_->get_mode().vdisplay))); |
| 95 CHECK(native_surface_->Initialize()); |
| 96 } |
83 } | 97 } |
84 | 98 |
85 void DriSurfaceAdapter::PresentCanvas(const gfx::Rect& damage) { | 99 void DriSurfaceAdapter::PresentCanvas(const gfx::Rect& damage) { |
86 CHECK(base::MessageLoopForUI::IsCurrent()); | 100 CHECK(base::MessageLoopForUI::IsCurrent()); |
87 if (!controller_) | 101 if (!controller_) |
88 return; | 102 return; |
89 | 103 |
90 UpdateNativeSurface(damage); | 104 UpdateNativeSurface(damage); |
91 controller_->SchedulePageFlip(std::vector<OzoneOverlayPlane>(), NULL); | 105 controller_->SchedulePageFlip(std::vector<OverlayPlane>( |
| 106 1, OverlayPlane(native_surface_->backbuffer()))); |
92 controller_->WaitForPageFlipEvent(); | 107 controller_->WaitForPageFlipEvent(); |
| 108 native_surface_->SwapBuffers(); |
93 } | 109 } |
94 | 110 |
95 scoped_ptr<gfx::VSyncProvider> DriSurfaceAdapter::CreateVSyncProvider() { | 111 scoped_ptr<gfx::VSyncProvider> DriSurfaceAdapter::CreateVSyncProvider() { |
96 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); | 112 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); |
97 } | 113 } |
98 | 114 |
99 void DriSurfaceAdapter::UpdateNativeSurface(const gfx::Rect& damage) { | 115 void DriSurfaceAdapter::UpdateNativeSurface(const gfx::Rect& damage) { |
100 SkCanvas* canvas = static_cast<DriSurface*>(controller_->surface()) | 116 SkCanvas* canvas = native_surface_->GetDrawableForWidget(); |
101 ->GetDrawableForWidget(); | |
102 | 117 |
103 // The DriSurface is double buffered, so the current back buffer is | 118 // The DriSurface is double buffered, so the current back buffer is |
104 // missing the previous update. Expand damage region. | 119 // missing the previous update. Expand damage region. |
105 SkRect real_damage = RectToSkRect(UnionRects(damage, last_damage_)); | 120 SkRect real_damage = RectToSkRect(UnionRects(damage, last_damage_)); |
106 | 121 |
107 // Copy damage region. | 122 // Copy damage region. |
108 skia::RefPtr<SkImage> image = skia::AdoptRef(surface_->newImageSnapshot()); | 123 skia::RefPtr<SkImage> image = skia::AdoptRef(surface_->newImageSnapshot()); |
109 image->draw(canvas, &real_damage, real_damage, NULL); | 124 image->draw(canvas, &real_damage, real_damage, NULL); |
110 | 125 |
111 last_damage_ = damage; | 126 last_damage_ = damage; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return ++allocated_widgets_; | 183 return ++allocated_widgets_; |
169 } | 184 } |
170 | 185 |
171 scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( | 186 scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( |
172 gfx::AcceleratedWidget w) { | 187 gfx::AcceleratedWidget w) { |
173 CHECK(state_ == INITIALIZED); | 188 CHECK(state_ == INITIALIZED); |
174 // Initial cursor set. | 189 // Initial cursor set. |
175 ResetCursor(w); | 190 ResetCursor(w); |
176 | 191 |
177 return scoped_ptr<ui::SurfaceOzoneCanvas>( | 192 return scoped_ptr<ui::SurfaceOzoneCanvas>( |
178 new DriSurfaceAdapter(screen_manager_->GetDisplayController(w))); | 193 new DriSurfaceAdapter(drm_, screen_manager_->GetDisplayController(w))); |
179 } | 194 } |
180 | 195 |
181 bool DriSurfaceFactory::LoadEGLGLES2Bindings( | 196 bool DriSurfaceFactory::LoadEGLGLES2Bindings( |
182 AddGLLibraryCallback add_gl_library, | 197 AddGLLibraryCallback add_gl_library, |
183 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 198 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
184 return false; | 199 return false; |
185 } | 200 } |
186 | 201 |
187 gfx::Size DriSurfaceFactory::GetWidgetSize(gfx::AcceleratedWidget w) { | 202 gfx::Size DriSurfaceFactory::GetWidgetSize(gfx::AcceleratedWidget w) { |
188 base::WeakPtr<HardwareDisplayController> controller = | 203 base::WeakPtr<HardwareDisplayController> controller = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 cursor_frontbuffer_ ^= 1; | 253 cursor_frontbuffer_ ^= 1; |
239 } | 254 } |
240 } else { | 255 } else { |
241 // No cursor set. | 256 // No cursor set. |
242 if (controller) | 257 if (controller) |
243 controller->UnsetCursor(); | 258 controller->UnsetCursor(); |
244 } | 259 } |
245 } | 260 } |
246 | 261 |
247 } // namespace ui | 262 } // namespace ui |
OLD | NEW |