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

Unified Diff: ui/gfx/ozone/impl/software_surface_ozone.cc

Issue 26866006: [Ozone] Adding a software surface implementation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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
Index: ui/gfx/ozone/impl/software_surface_ozone.cc
diff --git a/ui/gfx/ozone/impl/software_surface_ozone.cc b/ui/gfx/ozone/impl/software_surface_ozone.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7213cc1c40e11073272c61c77959d9f5e44f45c1
--- /dev/null
+++ b/ui/gfx/ozone/impl/software_surface_ozone.cc
@@ -0,0 +1,112 @@
+// Copyright (c) 2013 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/gfx/ozone/impl/software_surface_ozone.h"
+
+#include <errno.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <xf86drm.h>
+
+#include "base/logging.h"
+#include "base/memory/scoped_vector.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkBitmapDevice.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "ui/gfx/ozone/impl/buffer_generator_ozone.h"
+#include "ui/gfx/ozone/impl/drm_skbitmap_ozone.h"
+#include "ui/gfx/ozone/impl/hardware_display_controller_ozone.h"
+#include "ui/gfx/skia_util.h"
+
+namespace gfx {
+
+namespace {
+
+// Extends the SkBitmapDevice to allow setting the SkPixelRef. We use the setter
+// to change the SkPixelRef such that the device always points to the
+// backbuffer.
+class CustomSkBitmapDevice : public SkBitmapDevice {
+ public:
+ CustomSkBitmapDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap) {}
+ virtual ~CustomSkBitmapDevice() {}
+
+ void SetPixelRef(SkPixelRef* pixel_ref) { setPixelRef(pixel_ref, 0); }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CustomSkBitmapDevice);
+};
+
+} // namespace
+
+////////////////////////////////////////////////////////////////////////////////
+// SoftwareSurfaceOzone implementation
+
+SoftwareSurfaceOzone::SoftwareSurfaceOzone(
+ HardwareDisplayControllerOzone* controller,
+ BufferGeneratorOzone* buffer_generator)
rjkroege 2013/10/11 17:26:51 rather than having a buffer generator class, why n
dnicoara 2013/10/11 19:20:07 Done.
+ : buffer_generator_(buffer_generator),
+ controller_(controller),
+ bitmaps_(),
+ front_buffer_(0) {
+}
+
+SoftwareSurfaceOzone::~SoftwareSurfaceOzone() {
+}
+
+bool SoftwareSurfaceOzone::Initialize() {
+ for (int i = 0; i < 2; ++i) {
+ DrmSkBitmapOzone* bitmap = buffer_generator_->CreateBuffer(
+ controller_->get_fd());
+ // TODO(dnicoara) Should select the configuration based on what the
+ // underlying system supports.
+ bitmap->setConfig(SkBitmap::kARGB_8888_Config,
+ controller_->get_mode().hdisplay,
+ controller_->get_mode().vdisplay);
+
+ if (!bitmap->Initialize()) {
+ delete bitmap;
+ return false;
+ }
+
+ bitmaps_.push_back(bitmap);
+ }
+
+ skia_device_ = skia::AdoptRef(
+ new SkBitmapDevice(*bitmaps_[front_buffer_ ^ 1]));
+ skia_canvas_ = skia::AdoptRef(new SkCanvas(skia_device_.get()));
+
+ return true;
+}
+
+uint32_t SoftwareSurfaceOzone::GetFramebufferId() const {
+ return bitmaps_[front_buffer_ ^ 1]->get_framebuffer();
+}
+
+// This call is made after the hardware just started displaying our back buffer.
+// We need to update our pointer reference and synchronize the two buffers.
+void SoftwareSurfaceOzone::SwapBuffers() {
+ // Update our front buffer pointer.
+ front_buffer_ ^= 1;
rjkroege 2013/10/11 17:26:51 either the vector is unnecessary or this will be s
dnicoara 2013/10/11 19:20:07 Changed how the bitmaps are stored and added CHECK
+
+ // Unlocking will unset the pixel pointer, so it won't be pointing to the old
+ // PixelRef.
+ skia_device_->accessBitmap(false).unlockPixels();
+ // Update the backing pixels for the bitmap device.
+ static_cast<CustomSkBitmapDevice*>(skia_device_.get())->SetPixelRef(
+ bitmaps_[front_buffer_ ^ 1]->pixelRef());
+ // Locking the pixels will set the pixel pointer based on the PixelRef value.
+ skia_device_->accessBitmap(false).lockPixels();
+
+ SkIRect device_damage;
+ skia_canvas_->getClipDeviceBounds(&device_damage);
+ SkRect damage = SkRect::Make(device_damage);
+
+ skia_canvas_->drawBitmapRectToRect(*bitmaps_[front_buffer_], &damage, damage);
+}
+
+SkCanvas* SoftwareSurfaceOzone::GetDrawableForWidget() {
+ return skia_canvas_.get();
+}
+
+} // namespace gfx
« ui/gfx/ozone/impl/software_surface_ozone.h ('K') | « ui/gfx/ozone/impl/software_surface_ozone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698