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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/ozone/impl/software_surface_ozone.h"
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"
13 #include "base/memory/scoped_vector.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkBitmapDevice.h"
16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "ui/gfx/ozone/impl/buffer_generator_ozone.h"
18 #include "ui/gfx/ozone/impl/drm_skbitmap_ozone.h"
19 #include "ui/gfx/ozone/impl/hardware_display_controller_ozone.h"
20 #include "ui/gfx/skia_util.h"
21
22 namespace gfx {
23
24 namespace {
25
26 // Extends the SkBitmapDevice to allow setting the SkPixelRef. We use the setter
27 // to change the SkPixelRef such that the device always points to the
28 // backbuffer.
29 class CustomSkBitmapDevice : public SkBitmapDevice {
30 public:
31 CustomSkBitmapDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap) {}
32 virtual ~CustomSkBitmapDevice() {}
33
34 void SetPixelRef(SkPixelRef* pixel_ref) { setPixelRef(pixel_ref, 0); }
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(CustomSkBitmapDevice);
38 };
39
40 } // namespace
41
42 ////////////////////////////////////////////////////////////////////////////////
43 // SoftwareSurfaceOzone implementation
44
45 SoftwareSurfaceOzone::SoftwareSurfaceOzone(
46 HardwareDisplayControllerOzone* controller,
47 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.
48 : buffer_generator_(buffer_generator),
49 controller_(controller),
50 bitmaps_(),
51 front_buffer_(0) {
52 }
53
54 SoftwareSurfaceOzone::~SoftwareSurfaceOzone() {
55 }
56
57 bool SoftwareSurfaceOzone::Initialize() {
58 for (int i = 0; i < 2; ++i) {
59 DrmSkBitmapOzone* bitmap = buffer_generator_->CreateBuffer(
60 controller_->get_fd());
61 // TODO(dnicoara) Should select the configuration based on what the
62 // underlying system supports.
63 bitmap->setConfig(SkBitmap::kARGB_8888_Config,
64 controller_->get_mode().hdisplay,
65 controller_->get_mode().vdisplay);
66
67 if (!bitmap->Initialize()) {
68 delete bitmap;
69 return false;
70 }
71
72 bitmaps_.push_back(bitmap);
73 }
74
75 skia_device_ = skia::AdoptRef(
76 new SkBitmapDevice(*bitmaps_[front_buffer_ ^ 1]));
77 skia_canvas_ = skia::AdoptRef(new SkCanvas(skia_device_.get()));
78
79 return true;
80 }
81
82 uint32_t SoftwareSurfaceOzone::GetFramebufferId() const {
83 return bitmaps_[front_buffer_ ^ 1]->get_framebuffer();
84 }
85
86 // This call is made after the hardware just started displaying our back buffer.
87 // We need to update our pointer reference and synchronize the two buffers.
88 void SoftwareSurfaceOzone::SwapBuffers() {
89 // Update our front buffer pointer.
90 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
91
92 // Unlocking will unset the pixel pointer, so it won't be pointing to the old
93 // PixelRef.
94 skia_device_->accessBitmap(false).unlockPixels();
95 // Update the backing pixels for the bitmap device.
96 static_cast<CustomSkBitmapDevice*>(skia_device_.get())->SetPixelRef(
97 bitmaps_[front_buffer_ ^ 1]->pixelRef());
98 // Locking the pixels will set the pixel pointer based on the PixelRef value.
99 skia_device_->accessBitmap(false).lockPixels();
100
101 SkIRect device_damage;
102 skia_canvas_->getClipDeviceBounds(&device_damage);
103 SkRect damage = SkRect::Make(device_damage);
104
105 skia_canvas_->drawBitmapRectToRect(*bitmaps_[front_buffer_], &damage, damage);
106 }
107
108 SkCanvas* SoftwareSurfaceOzone::GetDrawableForWidget() {
109 return skia_canvas_.get();
110 }
111
112 } // namespace gfx
OLDNEW
« 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