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

Side by Side Diff: chrome/browser/ui/views/ash/screenshot_taker.cc

Issue 10694003: Use capturing with XGetImage() only in screenshot_taker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | « no previous file | chrome/browser/ui/window_snapshot/window_snapshot_aura.cc » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ui/views/ash/screenshot_taker.h" 5 #include "chrome/browser/ui/views/ash/screenshot_taker.h"
6 6
7 #include <climits> 7 #include <climits>
8 #include <string> 8 #include <string>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/i18n/time_formatting.h" 15 #include "base/i18n/time_formatting.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ref_counted_memory.h" 17 #include "base/memory/ref_counted_memory.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/time.h" 19 #include "base/time.h"
20 #include "chrome/browser/download/download_util.h" 20 #include "chrome/browser/download/download_util.h"
21 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/profiles/profile_manager.h" 23 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 24 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
27 #include "ui/aura/root_window.h"
27 #include "ui/aura/window.h" 28 #include "ui/aura/window.h"
28 29
29 #if defined(OS_CHROMEOS) 30 #if defined(OS_CHROMEOS)
30 #include "chrome/browser/chromeos/login/user_manager.h" 31 #include "chrome/browser/chromeos/login/user_manager.h"
31 #endif 32 #endif
32 33
33 namespace { 34 namespace {
34 bool ShouldUse24HourClock() { 35 bool ShouldUse24HourClock() {
35 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
36 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 37 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 } 111 }
111 112
112 if (static_cast<size_t>(file_util::WriteFile( 113 if (static_cast<size_t>(file_util::WriteFile(
113 screenshot_path, 114 screenshot_path,
114 reinterpret_cast<char*>(&(png_data->data()[0])), 115 reinterpret_cast<char*>(&(png_data->data()[0])),
115 png_data->size())) != png_data->size()) { 116 png_data->size())) != png_data->size()) {
116 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); 117 LOG(ERROR) << "Failed to save to " << screenshot_path.value();
117 } 118 }
118 } 119 }
119 120
121 bool GrabWindowSnapshot(aura::Window* window,
122 const gfx::Rect& snapshot_bounds,
123 std::vector<unsigned char>* png_data) {
124 #if defined(OS_LINUX)
125 // We use XGetImage() for Linux/ChromeOS for performance reasons.
126 // See crbug.com/119492
127 // TODO(mukai): remove this when the performance issue has been fixed.
128 if (window->GetRootWindow()->GrabSnapshot(snapshot_bounds, png_data))
129 return true;
130 #endif // OS_LINUX
131
132 return browser::GrabWindowSnapshot(window, png_data, snapshot_bounds);
133 }
134
120 // How opaque should the layer that we flash onscreen to provide visual 135 // How opaque should the layer that we flash onscreen to provide visual
121 // feedback after the screenshot is taken be? 136 // feedback after the screenshot is taken be?
122 const float kVisualFeedbackLayerOpacity = 0.25f; 137 const float kVisualFeedbackLayerOpacity = 0.25f;
123 138
124 // How long should the visual feedback layer be displayed? 139 // How long should the visual feedback layer be displayed?
125 const int64 kVisualFeedbackLayerDisplayTimeMs = 100; 140 const int64 kVisualFeedbackLayerDisplayTimeMs = 100;
126 141
127 } // namespace 142 } // namespace
128 143
129 ScreenshotTaker::ScreenshotTaker() { 144 ScreenshotTaker::ScreenshotTaker() {
130 } 145 }
131 146
132 ScreenshotTaker::~ScreenshotTaker() { 147 ScreenshotTaker::~ScreenshotTaker() {
133 } 148 }
134 149
135 void ScreenshotTaker::HandleTakePartialScreenshot( 150 void ScreenshotTaker::HandleTakePartialScreenshot(
136 aura::Window* window, const gfx::Rect& rect) { 151 aura::Window* window, const gfx::Rect& rect) {
137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
138 153
139 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes); 154 scoped_refptr<base::RefCountedBytes> png_data(new base::RefCountedBytes);
140 155
141 bool is_logged_in = true; 156 bool is_logged_in = true;
142 #if defined(OS_CHROMEOS) 157 #if defined(OS_CHROMEOS)
143 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn(); 158 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn();
144 #endif 159 #endif
145 160
146 bool use_24hour_clock = ShouldUse24HourClock(); 161 bool use_24hour_clock = ShouldUse24HourClock();
147 162
148 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { 163 if (GrabWindowSnapshot(window, rect, &png_data->data())) {
149 DisplayVisualFeedback(rect); 164 DisplayVisualFeedback(rect);
150 content::BrowserThread::PostTask( 165 content::BrowserThread::PostTask(
151 content::BrowserThread::FILE, FROM_HERE, 166 content::BrowserThread::FILE, FROM_HERE,
152 base::Bind(&SaveScreenshot, is_logged_in, use_24hour_clock, png_data)); 167 base::Bind(&SaveScreenshot, is_logged_in, use_24hour_clock, png_data));
153 } else { 168 } else {
154 LOG(ERROR) << "Failed to grab the window screenshot"; 169 LOG(ERROR) << "Failed to grab the window screenshot";
155 } 170 }
156 } 171 }
157 172
158 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { 173 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
(...skipping 15 matching lines...) Expand all
174 ash::internal::kShellWindowId_OverlayContainer)->layer(); 189 ash::internal::kShellWindowId_OverlayContainer)->layer();
175 parent->Add(visual_feedback_layer_.get()); 190 parent->Add(visual_feedback_layer_.get());
176 visual_feedback_layer_->SetVisible(true); 191 visual_feedback_layer_->SetVisible(true);
177 192
178 MessageLoopForUI::current()->PostDelayedTask( 193 MessageLoopForUI::current()->PostDelayedTask(
179 FROM_HERE, 194 FROM_HERE,
180 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, 195 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer,
181 base::Unretained(this)), 196 base::Unretained(this)),
182 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); 197 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs));
183 } 198 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/window_snapshot/window_snapshot_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698