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

Side by Side Diff: ui/ozone/platform/dri/dri_surface.cc

Issue 469343003: [Ozone-GBM] Pumb DriWindowDelegate throughout the platform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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.h" 5 #include "ui/ozone/platform/dri/dri_surface.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkSurface.h" 10 #include "third_party/skia/include/core/SkSurface.h"
11 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/skia_util.h" 12 #include "ui/gfx/skia_util.h"
13 #include "ui/ozone/platform/dri/dri_buffer.h" 13 #include "ui/ozone/platform/dri/dri_buffer.h"
14 #include "ui/ozone/platform/dri/dri_vsync_provider.h" 14 #include "ui/ozone/platform/dri/dri_vsync_provider.h"
15 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h"
15 #include "ui/ozone/platform/dri/dri_wrapper.h" 16 #include "ui/ozone/platform/dri/dri_wrapper.h"
16 #include "ui/ozone/platform/dri/hardware_display_controller.h" 17 #include "ui/ozone/platform/dri/hardware_display_controller.h"
17 18
18 namespace ui { 19 namespace ui {
19 20
20 namespace { 21 namespace {
21 22
22 scoped_refptr<DriBuffer> AllocateBuffer(DriWrapper* dri, 23 scoped_refptr<DriBuffer> AllocateBuffer(DriWrapper* dri,
23 const gfx::Size& size) { 24 const gfx::Size& size) {
24 scoped_refptr<DriBuffer> buffer(new DriBuffer(dri)); 25 scoped_refptr<DriBuffer> buffer(new DriBuffer(dri));
25 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); 26 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
26 27
27 bool initialized = buffer->Initialize(info); 28 bool initialized = buffer->Initialize(info);
28 DCHECK(initialized) << "Failed to create drm buffer."; 29 DCHECK(initialized) << "Failed to create drm buffer.";
29 30
30 return buffer; 31 return buffer;
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 DriSurface::DriSurface( 36 DriSurface::DriSurface(DriWindowDelegate* window_delegate, DriWrapper* dri)
36 DriWrapper* dri, 37 : window_delegate_(window_delegate),
37 const base::WeakPtr<HardwareDisplayController>& controller) 38 dri_(dri),
38 : dri_(dri),
39 buffers_(), 39 buffers_(),
40 front_buffer_(0), 40 front_buffer_(0) {
41 controller_(controller) {
42 } 41 }
43 42
44 DriSurface::~DriSurface() { 43 DriSurface::~DriSurface() {
45 } 44 }
46 45
47 skia::RefPtr<SkCanvas> DriSurface::GetCanvas() { 46 skia::RefPtr<SkCanvas> DriSurface::GetCanvas() {
48 return skia::SharePtr(surface_->getCanvas()); 47 return skia::SharePtr(surface_->getCanvas());
49 } 48 }
50 49
51 void DriSurface::ResizeCanvas(const gfx::Size& viewport_size) { 50 void DriSurface::ResizeCanvas(const gfx::Size& viewport_size) {
52 SkImageInfo info = SkImageInfo::MakeN32( 51 SkImageInfo info = SkImageInfo::MakeN32(
53 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType); 52 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType);
54 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); 53 surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
55 54
56 if (!controller_) 55 HardwareDisplayController* controller = window_delegate_->GetController();
56 if (!controller)
57 return; 57 return;
58 58
59 // For the display buffers use the mode size since a |viewport_size| smaller 59 // For the display buffers use the mode size since a |viewport_size| smaller
60 // than the display size will not scanout. 60 // than the display size will not scanout.
61 gfx::Size mode_size(controller_->get_mode().hdisplay, 61 gfx::Size mode_size(controller->get_mode().hdisplay,
62 controller_->get_mode().vdisplay); 62 controller->get_mode().vdisplay);
63 for (size_t i = 0; i < arraysize(buffers_); ++i) 63 for (size_t i = 0; i < arraysize(buffers_); ++i)
64 buffers_[i] = AllocateBuffer(dri_, mode_size); 64 buffers_[i] = AllocateBuffer(dri_, mode_size);
65 } 65 }
66 66
67 void DriSurface::PresentCanvas(const gfx::Rect& damage) { 67 void DriSurface::PresentCanvas(const gfx::Rect& damage) {
68 DCHECK(base::MessageLoopForUI::IsCurrent()); 68 DCHECK(base::MessageLoopForUI::IsCurrent());
69 DCHECK(buffers_[front_buffer_ ^ 1]); 69 DCHECK(buffers_[front_buffer_ ^ 1]);
70 70
71 if (!controller_) 71 HardwareDisplayController* controller = window_delegate_->GetController();
72 if (!controller)
72 return; 73 return;
73 74
74 controller_->QueueOverlayPlane(OverlayPlane(buffers_[front_buffer_ ^ 1])); 75 controller->QueueOverlayPlane(OverlayPlane(buffers_[front_buffer_ ^ 1]));
75 76
76 UpdateNativeSurface(damage); 77 UpdateNativeSurface(damage);
77 controller_->SchedulePageFlip(); 78 controller->SchedulePageFlip();
78 controller_->WaitForPageFlipEvent(); 79 controller->WaitForPageFlipEvent();
79 80
80 // Update our front buffer pointer. 81 // Update our front buffer pointer.
81 front_buffer_ ^= 1; 82 front_buffer_ ^= 1;
82 } 83 }
83 84
84 scoped_ptr<gfx::VSyncProvider> DriSurface::CreateVSyncProvider() { 85 scoped_ptr<gfx::VSyncProvider> DriSurface::CreateVSyncProvider() {
85 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); 86 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(window_delegate_));
86 } 87 }
87 88
88 void DriSurface::UpdateNativeSurface(const gfx::Rect& damage) { 89 void DriSurface::UpdateNativeSurface(const gfx::Rect& damage) {
89 SkCanvas* canvas = buffers_[front_buffer_ ^ 1]->GetCanvas(); 90 SkCanvas* canvas = buffers_[front_buffer_ ^ 1]->GetCanvas();
90 91
91 // The DriSurface is double buffered, so the current back buffer is 92 // The DriSurface is double buffered, so the current back buffer is
92 // missing the previous update. Expand damage region. 93 // missing the previous update. Expand damage region.
93 SkRect real_damage = RectToSkRect(UnionRects(damage, last_damage_)); 94 SkRect real_damage = RectToSkRect(UnionRects(damage, last_damage_));
94 95
95 // Copy damage region. 96 // Copy damage region.
96 skia::RefPtr<SkImage> image = skia::AdoptRef(surface_->newImageSnapshot()); 97 skia::RefPtr<SkImage> image = skia::AdoptRef(surface_->newImageSnapshot());
97 image->draw(canvas, &real_damage, real_damage, NULL); 98 image->draw(canvas, &real_damage, real_damage, NULL);
98 99
99 last_damage_ = damage; 100 last_damage_ = damage;
100 } 101 }
101 102
102 } // namespace ui 103 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698