OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 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 #ifndef NP_NO_QUICKDRAW | |
6 | |
7 #include "webkit/plugins/npapi/quickdraw_drawing_manager_mac.h" | |
8 | |
9 #include "webkit/plugins/npapi/coregraphics_private_symbols_mac.h" | |
10 | |
11 // Turn off GCC warnings about deprecated functions (since QuickDraw is a | |
12 // deprecated API). According to the GCC documentation, this can only be done | |
13 // per file, not pushed and popped like some options can be. | |
14 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
15 | |
16 namespace webkit { | |
17 namespace npapi { | |
18 | |
19 QuickDrawDrawingManager::QuickDrawDrawingManager() | |
20 : plugin_window_(NULL), target_context_(NULL), current_port_(NULL) {} | |
21 | |
22 QuickDrawDrawingManager::~QuickDrawDrawingManager() { | |
23 } | |
24 | |
25 void QuickDrawDrawingManager::SetTargetContext(CGContextRef context, | |
26 const gfx::Size& plugin_size) { | |
27 target_context_ = context; | |
28 plugin_size_ = plugin_size; | |
29 } | |
30 | |
31 void QuickDrawDrawingManager::SetPluginWindow(WindowRef window) { | |
32 plugin_window_ = window; | |
33 current_port_ = GetWindowPort(window); | |
34 } | |
35 | |
36 void QuickDrawDrawingManager::UpdateContext() { | |
37 ScrapeWindow(plugin_window_, target_context_, plugin_size_); | |
38 } | |
39 | |
40 void QuickDrawDrawingManager::MakePortCurrent() { | |
41 SetPort(current_port_); | |
42 } | |
43 | |
44 void QuickDrawDrawingManager::ScrapeWindow(WindowRef window, | |
45 CGContextRef target_context, | |
46 const gfx::Size& plugin_size) { | |
47 if (!target_context) | |
48 return; | |
49 | |
50 CGRect window_bounds = CGRectMake(0, 0, | |
51 plugin_size.width(), | |
52 plugin_size.height()); | |
53 CGWindowID window_id = HIWindowGetCGWindowID(window); | |
54 CGContextSaveGState(target_context); | |
55 CGContextTranslateCTM(target_context, 0, plugin_size.height()); | |
56 CGContextScaleCTM(target_context, 1.0, -1.0); | |
57 CGContextCopyWindowCaptureContentsToRect(target_context, window_bounds, | |
58 _CGSDefaultConnection(), | |
59 window_id, 0); | |
60 CGContextRestoreGState(target_context); | |
61 } | |
62 | |
63 } // namespace npapi | |
64 } // namespace webkit | |
65 | |
66 #endif // !NP_NO_QUICKDRAW | |
OLD | NEW |