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 "content/browser/compositor/software_output_device_win.h" | 5 #include "content/browser/compositor/software_output_device_win.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
9 #include "third_party/skia/include/core/SkDevice.h" | 9 #include "third_party/skia/include/core/SkDevice.h" |
10 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" |
11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
12 #include "ui/gfx/canvas_skia_paint.h" | 12 #include "ui/gfx/canvas_skia_paint.h" |
13 #include "ui/gfx/gdi_util.h" | 13 #include "ui/gfx/gdi_util.h" |
14 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
15 | 15 |
16 namespace content { | 16 namespace content { |
17 | 17 |
18 SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor) | 18 SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor) |
19 : hwnd_(compositor->widget()), | 19 : hwnd_(compositor->widget()), |
20 is_hwnd_composited_(false) { | 20 is_hwnd_composited_(false) { |
21 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. | 21 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. |
22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 22 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
23 | 23 |
24 LONG style = GetWindowLong(hwnd_, GWL_EXSTYLE); | 24 LONG style = GetWindowLong(hwnd_, GWL_EXSTYLE); |
25 is_hwnd_composited_ = !!(style & WS_EX_COMPOSITED); | 25 is_hwnd_composited_ = !!(style & WS_EX_COMPOSITED); |
26 } | 26 } |
27 | 27 |
28 SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { | 28 SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
30 } | 30 } |
31 | 31 |
32 void SoftwareOutputDeviceWin::Resize(const gfx::Size& viewport_pixel_size, | 32 void SoftwareOutputDeviceWin::Resize(const gfx::Size& viewport_pixel_size, |
33 float scale_factor) { | 33 float scale_factor) { |
34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 34 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
35 | 35 |
36 scale_factor_ = scale_factor; | 36 scale_factor_ = scale_factor; |
37 | 37 |
38 if (viewport_pixel_size_ == viewport_pixel_size) | 38 if (viewport_pixel_size_ == viewport_pixel_size) |
39 return; | 39 return; |
40 | 40 |
41 viewport_pixel_size_ = viewport_pixel_size; | 41 viewport_pixel_size_ = viewport_pixel_size; |
42 contents_.reset(new gfx::Canvas(viewport_pixel_size, 1.0f, true)); | 42 contents_.reset(new gfx::Canvas(viewport_pixel_size, 1.0f, true)); |
43 memset(&bitmap_info_, 0, sizeof(bitmap_info_)); | 43 memset(&bitmap_info_, 0, sizeof(bitmap_info_)); |
44 gfx::CreateBitmapHeader(viewport_pixel_size_.width(), | 44 gfx::CreateBitmapHeader(viewport_pixel_size_.width(), |
45 viewport_pixel_size_.height(), | 45 viewport_pixel_size_.height(), |
46 &bitmap_info_.bmiHeader); | 46 &bitmap_info_.bmiHeader); |
47 } | 47 } |
48 | 48 |
49 SkCanvas* SoftwareOutputDeviceWin::BeginPaint(const gfx::Rect& damage_rect) { | 49 SkCanvas* SoftwareOutputDeviceWin::BeginPaint(const gfx::Rect& damage_rect) { |
50 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 50 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
51 DCHECK(contents_); | 51 DCHECK(contents_); |
52 | 52 |
53 damage_rect_ = damage_rect; | 53 damage_rect_ = damage_rect; |
54 return contents_ ? contents_->sk_canvas() : NULL; | 54 return contents_ ? contents_->sk_canvas() : NULL; |
55 } | 55 } |
56 | 56 |
57 void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) { | 57 void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) { |
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
59 DCHECK(contents_); | 59 DCHECK(contents_); |
60 DCHECK(frame_data); | 60 DCHECK(frame_data); |
61 | 61 |
62 if (!contents_) | 62 if (!contents_) |
63 return; | 63 return; |
64 | 64 |
65 SoftwareOutputDevice::EndPaint(frame_data); | 65 SoftwareOutputDevice::EndPaint(frame_data); |
66 | 66 |
67 gfx::Rect rect = damage_rect_; | 67 gfx::Rect rect = damage_rect_; |
68 rect.Intersect(gfx::Rect(viewport_pixel_size_)); | 68 rect.Intersect(gfx::Rect(viewport_pixel_size_)); |
(...skipping 29 matching lines...) Expand all Loading... |
98 | 98 |
99 void SoftwareOutputDeviceWin::CopyToPixels(const gfx::Rect& rect, | 99 void SoftwareOutputDeviceWin::CopyToPixels(const gfx::Rect& rect, |
100 void* pixels) { | 100 void* pixels) { |
101 DCHECK(contents_); | 101 DCHECK(contents_); |
102 SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height()); | 102 SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height()); |
103 contents_->sk_canvas()->readPixels( | 103 contents_->sk_canvas()->readPixels( |
104 info, pixels, info.minRowBytes(), rect.x(), rect.y()); | 104 info, pixels, info.minRowBytes(), rect.x(), rect.y()); |
105 } | 105 } |
106 | 106 |
107 } // namespace content | 107 } // namespace content |
OLD | NEW |