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

Unified Diff: ui/ozone/platform/drm/gpu/drm_surface.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_surface.h ('k') | ui/ozone/platform/drm/gpu/drm_surface_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/ozone/platform/drm/gpu/drm_surface.cc
diff --git a/ui/ozone/platform/drm/gpu/drm_surface.cc b/ui/ozone/platform/drm/gpu/drm_surface.cc
new file mode 100644
index 0000000000000000000000000000000000000000..707f3c98477982e20b6fc0e6e406055261aac050
--- /dev/null
+++ b/ui/ozone/platform/drm/gpu/drm_surface.cc
@@ -0,0 +1,116 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/ozone/platform/drm/gpu/drm_surface.h"
+
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/core/SkSurface.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/skia_util.h"
+#include "ui/ozone/platform/drm/gpu/drm_buffer.h"
+#include "ui/ozone/platform/drm/gpu/drm_device.h"
+#include "ui/ozone/platform/drm/gpu/drm_vsync_provider.h"
+#include "ui/ozone/platform/drm/gpu/drm_window.h"
+#include "ui/ozone/platform/drm/gpu/hardware_display_controller.h"
+
+namespace ui {
+
+namespace {
+
+scoped_refptr<DrmBuffer> AllocateBuffer(const scoped_refptr<DrmDevice>& drm,
+ const gfx::Size& size) {
+ scoped_refptr<DrmBuffer> buffer(new DrmBuffer(drm));
+ SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
+
+ bool initialized =
+ buffer->Initialize(info, true /* should_register_framebuffer */);
+ DCHECK(initialized) << "Failed to create drm buffer.";
+
+ return buffer;
+}
+
+} // namespace
+
+DrmSurface::DrmSurface(DrmWindow* window_delegate)
+ : window_delegate_(window_delegate),
+ weak_ptr_factory_(this) {
+}
+
+DrmSurface::~DrmSurface() {
+}
+
+skia::RefPtr<SkSurface> DrmSurface::GetSurface() {
+ return surface_;
+}
+
+void DrmSurface::ResizeCanvas(const gfx::Size& viewport_size) {
+ SkImageInfo info = SkImageInfo::MakeN32(
+ viewport_size.width(), viewport_size.height(), kOpaque_SkAlphaType);
+ surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
+
+ HardwareDisplayController* controller = window_delegate_->GetController();
+ if (!controller)
+ return;
+
+ // For the display buffers use the mode size since a |viewport_size| smaller
+ // than the display size will not scanout.
+ front_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
+ controller->GetModeSize());
+ back_buffer_ = AllocateBuffer(controller->GetAllocationDrmDevice(),
+ controller->GetModeSize());
+}
+
+void DrmSurface::PresentCanvas(const gfx::Rect& damage) {
+ DCHECK(base::MessageLoopForUI::IsCurrent());
+
+ // Create a snapshot of the requested drawing. If we get here again before
+ // presenting, just add the additional damage.
+ pending_image_damage_.Union(damage);
+ pending_image_ = skia::AdoptRef(surface_->newImageSnapshot());
+
+ if (!pending_pageflip_)
+ SchedulePageFlip();
+}
+
+scoped_ptr<gfx::VSyncProvider> DrmSurface::CreateVSyncProvider() {
+ return make_scoped_ptr(new DrmVSyncProvider(window_delegate_));
+}
+
+void DrmSurface::SchedulePageFlip() {
+ DCHECK(back_buffer_);
+ SkCanvas* canvas = back_buffer_->GetCanvas();
+
+ // The DrmSurface is double buffered, so the current back buffer is
+ // missing the previous update. Expand damage region.
+ SkRect real_damage =
+ RectToSkRect(UnionRects(pending_image_damage_, last_damage_));
+
+ // Copy damage region.
+ canvas->drawImageRect(pending_image_.get(), &real_damage, real_damage, NULL);
+ last_damage_ = pending_image_damage_;
+
+ pending_image_.clear();
+ pending_image_damage_ = gfx::Rect();
+
+ window_delegate_->QueueOverlayPlane(OverlayPlane(back_buffer_));
+
+ // Update our front buffer pointer.
+ std::swap(front_buffer_, back_buffer_);
+ pending_pageflip_ = window_delegate_->SchedulePageFlip(
+ false /* is_sync */,
+ base::Bind(&DrmSurface::OnPageFlip, weak_ptr_factory_.GetWeakPtr()));
+}
+
+void DrmSurface::OnPageFlip(gfx::SwapResult result) {
+ pending_pageflip_ = false;
+ if (!pending_image_)
+ return;
+
+ SchedulePageFlip();
+}
+
+} // namespace ui
« no previous file with comments | « ui/ozone/platform/drm/gpu/drm_surface.h ('k') | ui/ozone/platform/drm/gpu/drm_surface_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698