OLD | NEW |
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> | 7 #include <errno.h> |
8 #include <sys/mman.h> | 8 #include <sys/mman.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #include <xf86drm.h> | 10 #include <xf86drm.h> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "third_party/skia/include/core/SkCanvas.h" | 13 #include "third_party/skia/include/core/SkCanvas.h" |
14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
16 #include "ui/ozone/platform/dri/dri_buffer.h" | 16 #include "ui/ozone/platform/dri/dri_buffer.h" |
17 #include "ui/ozone/platform/dri/dri_wrapper.h" | 17 #include "ui/ozone/platform/dri/dri_wrapper.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 namespace { | |
22 | |
23 // TODO(dnicoara) Remove this once Skia implements this between 2 SkCanvases. | |
24 void CopyRect(DriBuffer* dst, DriBuffer* src, const gfx::Rect& damage) { | |
25 SkImageInfo src_info, dst_info; | |
26 size_t src_stride, dst_stride; | |
27 uint8_t* src_pixels = static_cast<uint8_t*>( | |
28 const_cast<void*>(src->canvas()->peekPixels(&src_info, &src_stride))); | |
29 uint8_t* dst_pixels = static_cast<uint8_t*>( | |
30 const_cast<void*>(dst->canvas()->peekPixels(&dst_info, &dst_stride))); | |
31 | |
32 // The 2 buffers should have the same properties. | |
33 DCHECK(src_info == dst_info); | |
34 DCHECK(src_stride == dst_stride); | |
35 | |
36 int bpp = src_info.bytesPerPixel(); | |
37 for (int height = damage.y(); height < damage.y() + damage.height(); ++height) | |
38 memcpy(dst_pixels + height * dst_stride + damage.x() * bpp, | |
39 src_pixels + height * src_stride + damage.x() * bpp, | |
40 damage.width() * bpp); | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 DriSurface::DriSurface( | 21 DriSurface::DriSurface( |
46 DriWrapper* dri, const gfx::Size& size) | 22 DriWrapper* dri, const gfx::Size& size) |
47 : dri_(dri), | 23 : dri_(dri), |
48 bitmaps_(), | 24 bitmaps_(), |
49 front_buffer_(0), | 25 front_buffer_(0), |
50 size_(size) { | 26 size_(size) { |
51 } | 27 } |
52 | 28 |
53 DriSurface::~DriSurface() { | 29 DriSurface::~DriSurface() { |
54 } | 30 } |
(...skipping 26 matching lines...) Expand all Loading... |
81 } | 57 } |
82 | 58 |
83 // This call is made after the hardware just started displaying our back buffer. | 59 // This call is made after the hardware just started displaying our back buffer. |
84 // We need to update our pointer reference and synchronize the two buffers. | 60 // We need to update our pointer reference and synchronize the two buffers. |
85 void DriSurface::SwapBuffers() { | 61 void DriSurface::SwapBuffers() { |
86 CHECK(frontbuffer()); | 62 CHECK(frontbuffer()); |
87 CHECK(backbuffer()); | 63 CHECK(backbuffer()); |
88 | 64 |
89 // Update our front buffer pointer. | 65 // Update our front buffer pointer. |
90 front_buffer_ ^= 1; | 66 front_buffer_ ^= 1; |
91 | |
92 SkIRect device_damage; | |
93 frontbuffer()->canvas()->getClipDeviceBounds(&device_damage); | |
94 CopyRect(backbuffer(), frontbuffer(), gfx::SkIRectToRect(device_damage)); | |
95 } | 67 } |
96 | 68 |
97 SkCanvas* DriSurface::GetDrawableForWidget() { | 69 SkCanvas* DriSurface::GetDrawableForWidget() { |
98 CHECK(backbuffer()); | 70 CHECK(backbuffer()); |
99 return backbuffer()->canvas(); | 71 return backbuffer()->canvas(); |
100 } | 72 } |
101 | 73 |
102 DriBuffer* DriSurface::CreateBuffer() { return new DriBuffer(dri_); } | 74 DriBuffer* DriSurface::CreateBuffer() { return new DriBuffer(dri_); } |
103 | 75 |
104 } // namespace ui | 76 } // namespace ui |
OLD | NEW |