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

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

Issue 403043004: [Ozone-DRI] Remove unneeded wrappers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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
« no previous file with comments | « ui/ozone/platform/dri/dri_surface.h ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <errno.h>
8 #include <sys/mman.h>
9 #include <sys/types.h>
10 #include <xf86drm.h>
11
12 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
13 #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"
14 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/skia_util.h" 12 #include "ui/gfx/skia_util.h"
16 #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"
17 #include "ui/ozone/platform/dri/dri_wrapper.h" 15 #include "ui/ozone/platform/dri/dri_wrapper.h"
16 #include "ui/ozone/platform/dri/hardware_display_controller.h"
18 17
19 namespace ui { 18 namespace ui {
20 19
20 namespace {
21
22 scoped_refptr<DriBuffer> AllocateBuffer(DriWrapper* dri,
23 const gfx::Size& size) {
24 scoped_refptr<DriBuffer> buffer(new DriBuffer(dri));
25 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
26 CHECK(buffer->Initialize(info)) << "Failed to create drm buffer.";
27
28 return buffer;
29 }
30
31 } // namespace
32
21 DriSurface::DriSurface( 33 DriSurface::DriSurface(
22 DriWrapper* dri, const gfx::Size& size) 34 DriWrapper* dri,
35 const base::WeakPtr<HardwareDisplayController>& controller)
23 : dri_(dri), 36 : dri_(dri),
24 bitmaps_(), 37 buffers_(),
25 front_buffer_(0), 38 front_buffer_(0),
26 size_(size) { 39 controller_(controller) {
27 } 40 }
28 41
29 DriSurface::~DriSurface() { 42 DriSurface::~DriSurface() {
30 } 43 }
31 44
32 bool DriSurface::Initialize() { 45 skia::RefPtr<SkCanvas> DriSurface::GetCanvas() {
33 for (size_t i = 0; i < arraysize(bitmaps_); ++i) { 46 return skia::SharePtr(surface_->getCanvas());
34 bitmaps_[i] = new DriBuffer(dri_);
35 // TODO(dnicoara) Should select the configuration based on what the
36 // underlying system supports.
37 SkImageInfo info = SkImageInfo::MakeN32Premul(size_.width(),
38 size_.height());
39 if (!bitmaps_[i]->Initialize(info)) {
40 return false;
41 }
42 }
43
44 return true;
45 } 47 }
46 48
47 uint32_t DriSurface::GetFramebufferId() const { 49 void DriSurface::ResizeCanvas(const gfx::Size& viewport_size) {
48 CHECK(backbuffer()); 50 SkImageInfo info = SkImageInfo::MakeN32(
49 return backbuffer()->GetFramebufferId(); 51 viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType);
52 surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
53
54 if (!controller_)
55 return;
56
57 // For the display buffers use the mode size since a |viewport_size| smaller
58 // than the display size will not scanout.
59 gfx::Size mode_size(controller_->get_mode().hdisplay,
60 controller_->get_mode().vdisplay);
61 for (size_t i = 0; i < arraysize(buffers_); ++i)
62 buffers_[i] = AllocateBuffer(dri_, mode_size);
50 } 63 }
51 64
52 uint32_t DriSurface::GetHandle() const { 65 void DriSurface::PresentCanvas(const gfx::Rect& damage) {
53 CHECK(backbuffer()); 66 CHECK(base::MessageLoopForUI::IsCurrent());
54 return backbuffer()->GetHandle(); 67 CHECK(buffers_[front_buffer_ ^ 1]);
55 }
56 68
57 void DriSurface::PreSwapBuffers() { 69 if (!controller_)
58 } 70 return;
59 71
60 // This call is made after the hardware just started displaying our back buffer. 72 std::vector<OverlayPlane> planes(
61 // We need to update our pointer reference and synchronize the two buffers. 73 1, OverlayPlane(buffers_[front_buffer_ ^ 1]));
62 void DriSurface::SwapBuffers() { 74
63 CHECK(backbuffer()); 75 UpdateNativeSurface(damage);
76 if (controller_->SchedulePageFlip(planes))
77 controller_->WaitForPageFlipEvent();
64 78
65 // Update our front buffer pointer. 79 // Update our front buffer pointer.
66 front_buffer_ ^= 1; 80 front_buffer_ ^= 1;
67 } 81 }
68 82
69 gfx::Size DriSurface::Size() const { 83 scoped_ptr<gfx::VSyncProvider> DriSurface::CreateVSyncProvider() {
70 return size_; 84 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_));
71 } 85 }
72 86
73 SkCanvas* DriSurface::GetDrawableForWidget() { 87 void DriSurface::UpdateNativeSurface(const gfx::Rect& damage) {
74 CHECK(backbuffer()); 88 SkCanvas* canvas = buffers_[front_buffer_ ^ 1]->GetCanvas();
75 return backbuffer()->GetCanvas(); 89
90 // The DriSurface is double buffered, so the current back buffer is
91 // missing the previous update. Expand damage region.
92 SkRect real_damage = RectToSkRect(UnionRects(damage, last_damage_));
93
94 // Copy damage region.
95 skia::RefPtr<SkImage> image = skia::AdoptRef(surface_->newImageSnapshot());
96 image->draw(canvas, &real_damage, real_damage, NULL);
97
98 last_damage_ = damage;
76 } 99 }
77 100
78 } // namespace ui 101 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_surface.h ('k') | ui/ozone/platform/dri/dri_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698