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

Side by Side Diff: content/browser/renderer_host/software_output_device_win.cc

Issue 15821012: [Aura] Fix software compositing blits to WS_EX_LAYERED windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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
« no previous file with comments | « content/browser/renderer_host/software_output_device_win.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/renderer_host/software_output_device_win.h" 5 #include "content/browser/renderer_host/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"
12 #include "ui/gfx/canvas_skia_paint.h"
11 #include "ui/gfx/gdi_util.h" 13 #include "ui/gfx/gdi_util.h"
12 14
13 namespace content { 15 namespace content {
14 16
15 SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor) 17 SoftwareOutputDeviceWin::SoftwareOutputDeviceWin(ui::Compositor* compositor)
16 : compositor_(compositor) { 18 : hwnd_(compositor->widget()),
19 is_hwnd_composited_(false) {
17 // TODO(skaslev) Remove this when crbug.com/180702 is fixed. 20 // TODO(skaslev) Remove this when crbug.com/180702 is fixed.
18 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 21 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
19 22
20 hwnd_ = compositor->widget(); 23 LONG style = GetWindowLong(hwnd_, GWL_EXSTYLE);
24 is_hwnd_composited_ = !!(style & WS_EX_COMPOSITED);
21 } 25 }
22 26
23 SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() { 27 SoftwareOutputDeviceWin::~SoftwareOutputDeviceWin() {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 } 29 }
26 30
27 void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) { 31 void SoftwareOutputDeviceWin::Resize(gfx::Size viewport_size) {
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
29 33
30 cc::SoftwareOutputDevice::Resize(viewport_size); 34 if (viewport_size_ == viewport_size)
35 return;
36
37 viewport_size_ = viewport_size;
38 contents_.reset(new gfx::Canvas(viewport_size, ui::SCALE_FACTOR_100P, false));
31 memset(&bitmap_info_, 0, sizeof(bitmap_info_)); 39 memset(&bitmap_info_, 0, sizeof(bitmap_info_));
32 gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(), 40 gfx::CreateBitmapHeader(viewport_size_.width(), viewport_size_.height(),
33 &bitmap_info_.bmiHeader); 41 &bitmap_info_.bmiHeader);
34 } 42 }
35 43
44 SkCanvas* SoftwareOutputDeviceWin::BeginPaint(gfx::Rect damage_rect) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
46 DCHECK(contents_);
47
48 damage_rect_ = damage_rect;
49 return contents_ ? contents_->sk_canvas() : NULL;
50 }
51
36 void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) { 52 void SoftwareOutputDeviceWin::EndPaint(cc::SoftwareFrameData* frame_data) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
38 DCHECK(device_); 54 DCHECK(contents_);
39 DCHECK(frame_data == NULL); 55 DCHECK(frame_data == NULL);
40 56
41 if (!device_) 57 if (!contents_)
42 return; 58 return;
43 59
44 gfx::Rect rect = damage_rect_; 60 gfx::Rect rect = damage_rect_;
45 rect.Intersect(gfx::Rect(viewport_size_)); 61 rect.Intersect(gfx::Rect(viewport_size_));
46 if (rect.IsEmpty()) 62 if (rect.IsEmpty())
47 return; 63 return;
48 64
49 const SkBitmap& bitmap = device_->accessBitmap(false); 65 SkCanvas* canvas = contents_->sk_canvas();
50 HDC hdc = ::GetDC(hwnd_); 66 DCHECK(canvas);
51 gfx::StretchDIBits(hdc, 67 if (is_hwnd_composited_) {
52 rect.x(), rect.y(), 68 RECT wr;
53 rect.width(), rect.height(), 69 GetWindowRect(hwnd_, &wr);
54 rect.x(), rect.y(), 70 SIZE size = {wr.right - wr.left, wr.bottom - wr.top};
55 rect.width(), rect.height(), 71 POINT position = {wr.left, wr.top};
56 bitmap.getPixels(), 72 POINT zero = {0, 0};
57 &bitmap_info_); 73 BLENDFUNCTION blend = {AC_SRC_OVER, 0x00, 0xFF, AC_SRC_ALPHA};
58 ::ReleaseDC(hwnd_, hdc); 74
75 DWORD style = GetWindowLong(hwnd_, GWL_EXSTYLE);
76 style &= ~WS_EX_COMPOSITED;
77 style |= WS_EX_LAYERED;
78 SetWindowLong(hwnd_, GWL_EXSTYLE, style);
79
80 HDC dib_dc = skia::BeginPlatformPaint(canvas);
81 ::UpdateLayeredWindow(hwnd_, NULL, &position, &size, dib_dc, &zero,
82 RGB(0xFF, 0xFF, 0xFF), &blend, ULW_ALPHA);
83 skia::EndPlatformPaint(canvas);
84 } else {
85 SkDevice* device = canvas->getDevice();
86 const SkBitmap& bitmap = device->accessBitmap(false);
87 HDC hdc = ::GetDC(hwnd_);
88 gfx::StretchDIBits(hdc,
89 rect.x(), rect.y(),
90 rect.width(), rect.height(),
91 rect.x(), rect.y(),
92 rect.width(), rect.height(),
93 bitmap.getPixels(),
94 &bitmap_info_);
95 ::ReleaseDC(hwnd_, hdc);
96 }
59 } 97 }
60 98
61 } // namespace content 99 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/software_output_device_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698