OLD | NEW |
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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 return YES; | 161 return YES; |
162 } | 162 } |
163 | 163 |
164 @end | 164 @end |
165 | 165 |
166 namespace { | 166 namespace { |
167 | 167 |
168 // Maximum number of characters we allow in a tooltip. | 168 // Maximum number of characters we allow in a tooltip. |
169 const size_t kMaxTooltipLength = 1024; | 169 const size_t kMaxTooltipLength = 1024; |
170 | 170 |
171 // Invalidation NSRect to trigger a drawRect on BuffersSwapped. | |
172 const NSRect kGpuSwapBuffersDirtyRect = { {0, 0}, {1, 1} }; | |
173 | |
174 // TODO(suzhe): Upstream this function. | 171 // TODO(suzhe): Upstream this function. |
175 WebKit::WebColor WebColorFromNSColor(NSColor *color) { | 172 WebKit::WebColor WebColorFromNSColor(NSColor *color) { |
176 CGFloat r, g, b, a; | 173 CGFloat r, g, b, a; |
177 [color getRed:&r green:&g blue:&b alpha:&a]; | 174 [color getRed:&r green:&g blue:&b alpha:&a]; |
178 | 175 |
179 return | 176 return |
180 std::max(0, std::min(static_cast<int>(lroundf(255.0f * a)), 255)) << 24 | | 177 std::max(0, std::min(static_cast<int>(lroundf(255.0f * a)), 255)) << 24 | |
181 std::max(0, std::min(static_cast<int>(lroundf(255.0f * r)), 255)) << 16 | | 178 std::max(0, std::min(static_cast<int>(lroundf(255.0f * r)), 255)) << 16 | |
182 std::max(0, std::min(static_cast<int>(lroundf(255.0f * g)), 255)) << 8 | | 179 std::max(0, std::min(static_cast<int>(lroundf(255.0f * g)), 255)) << 8 | |
183 std::max(0, std::min(static_cast<int>(lroundf(255.0f * b)), 255)); | 180 std::max(0, std::min(static_cast<int>(lroundf(255.0f * b)), 255)); |
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); | 982 gfx::Size window_size(NSSizeToCGSize([cocoa_view_ frame].size)); |
986 if (window_size.IsEmpty()) { | 983 if (window_size.IsEmpty()) { |
987 // setNeedsDisplay will never display and we'll never ack if the window is | 984 // setNeedsDisplay will never display and we'll never ack if the window is |
988 // empty, so ack now and don't bother calling setNeedsDisplay below. | 985 // empty, so ack now and don't bother calling setNeedsDisplay below. |
989 return true; | 986 return true; |
990 } | 987 } |
991 | 988 |
992 // No need to draw the surface if we are inside a drawRect. It will be done | 989 // No need to draw the surface if we are inside a drawRect. It will be done |
993 // later. | 990 // later. |
994 if (!about_to_validate_and_paint_) { | 991 if (!about_to_validate_and_paint_) { |
995 // Trigger a drawRect, but don't invalidate the whole window because it | 992 compositing_iosurface_->DrawIOSurface(cocoa_view_, |
996 // is expensive to clear it with transparency to expose the GL underneath. | 993 ScaleFactor(cocoa_view_)); |
997 [cocoa_view_ setNeedsDisplayInRect:kGpuSwapBuffersDirtyRect]; | |
998 | |
999 // While resizing, OSX fails to call drawRect on the NSView unless the | |
1000 // window size has changed. That means we won't see animations update if the | |
1001 // user has the mouse button held down, but is not currently changing the | |
1002 // size of the window. To work around that, display here while resizing. | |
1003 // Also, OSX will never call drawRect faster than vsync rate, so if | |
1004 // disable-gpu-vsync is set, we need to display now. | |
1005 if (compositing_iosurface_->is_vsync_disabled() || | |
1006 [cocoa_view_ inLiveResize]) { | |
1007 [cocoa_view_ displayIfNeeded]; | |
1008 } | |
1009 } | 994 } |
1010 return false; | 995 return true; |
1011 } | 996 } |
1012 | 997 |
1013 void RenderWidgetHostViewMac::AckPendingSwapBuffers() { | 998 void RenderWidgetHostViewMac::AckPendingSwapBuffers() { |
1014 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers"); | 999 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::AckPendingSwapBuffers"); |
1015 while (!pending_swap_buffers_acks_.empty()) { | 1000 while (!pending_swap_buffers_acks_.empty()) { |
1016 if (pending_swap_buffers_acks_.front().first != 0) { | 1001 if (pending_swap_buffers_acks_.front().first != 0) { |
1017 RenderWidgetHostImpl::AcknowledgeBufferPresent( | 1002 RenderWidgetHostImpl::AcknowledgeBufferPresent( |
1018 pending_swap_buffers_acks_.front().first, | 1003 pending_swap_buffers_acks_.front().first, |
1019 pending_swap_buffers_acks_.front().second, | 1004 pending_swap_buffers_acks_.front().second, |
1020 0); | 1005 0); |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 // blit the IOSurface below. | 2140 // blit the IOSurface below. |
2156 renderWidgetHostView_->about_to_validate_and_paint_ = true; | 2141 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
2157 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( | 2142 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( |
2158 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); | 2143 renderWidgetHostView_->render_widget_host_->GetBackingStore(true)); |
2159 renderWidgetHostView_->about_to_validate_and_paint_ = false; | 2144 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
2160 | 2145 |
2161 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); | 2146 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); |
2162 | 2147 |
2163 if (renderWidgetHostView_->last_frame_was_accelerated_ && | 2148 if (renderWidgetHostView_->last_frame_was_accelerated_ && |
2164 renderWidgetHostView_->compositing_iosurface_.get()) { | 2149 renderWidgetHostView_->compositing_iosurface_.get()) { |
2165 bool is_swap_without_dirty = | 2150 { |
2166 (dirtyRect.origin.x == kGpuSwapBuffersDirtyRect.origin.x && | |
2167 dirtyRect.origin.y == kGpuSwapBuffersDirtyRect.origin.y && | |
2168 dirtyRect.size.width == kGpuSwapBuffersDirtyRect.size.width && | |
2169 dirtyRect.size.height == kGpuSwapBuffersDirtyRect.size.height); | |
2170 if (!is_swap_without_dirty) { | |
2171 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(), | 2151 TRACE_EVENT2("gpu", "NSRectFill clear", "w", damagedRect.width(), |
2172 "h", damagedRect.height()); | 2152 "h", damagedRect.height()); |
2173 // Draw transparency to expose the GL underlay. NSRectFill is extremely | 2153 // Draw transparency to expose the GL underlay. NSRectFill is extremely |
2174 // slow (15ms for a window on a fast MacPro), so this is only done when | 2154 // slow (15ms for a window on a fast MacPro), so this is only done when |
2175 // it's a real invalidation from window damage (not when a BuffersSwapped | 2155 // it's a real invalidation from window damage (not when a BuffersSwapped |
2176 // was received). Note that even a 1x1 NSRectFill can take many | 2156 // was received). Note that even a 1x1 NSRectFill can take many |
2177 // milliseconds sometimes (!) so this is skipped completely for drawRects | 2157 // milliseconds sometimes (!) so this is skipped completely for drawRects |
2178 // that are triggered by BuffersSwapped messages. | 2158 // that are triggered by BuffersSwapped messages. |
2179 [[NSColor clearColor] set]; | 2159 [[NSColor clearColor] set]; |
2180 NSRectFill(dirtyRect); | 2160 NSRectFill(dirtyRect); |
2181 } | 2161 } |
2182 | 2162 |
2183 // TODO(thakis): Register for backing scale factor change events and pass | 2163 // TODO(thakis): Register for backing scale factor change events and pass |
2184 // that on. | 2164 // that on. |
2185 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( | 2165 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface( |
2186 self, ScaleFactor(self)); | 2166 self, ScaleFactor(self)); |
2187 // For latency_tests.cc: | |
2188 UNSHIPPED_TRACE_EVENT_INSTANT0("test_gpu", "CompositorSwapBuffersComplete"); | |
2189 renderWidgetHostView_->AckPendingSwapBuffers(); | |
2190 return; | 2167 return; |
2191 } | 2168 } |
2192 | 2169 |
2193 if (backingStore) { | 2170 if (backingStore) { |
2194 // Note: All coordinates are in view units, not pixels. | 2171 // Note: All coordinates are in view units, not pixels. |
2195 gfx::Rect bitmapRect(0, 0, | 2172 gfx::Rect bitmapRect(0, 0, |
2196 backingStore->size().width(), | 2173 backingStore->size().width(), |
2197 backingStore->size().height()); | 2174 backingStore->size().height()); |
2198 | 2175 |
2199 // Specify the proper y offset to ensure that the view is rooted to the | 2176 // Specify the proper y offset to ensure that the view is rooted to the |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3204 if (!string) return NO; | 3181 if (!string) return NO; |
3205 | 3182 |
3206 // If the user is currently using an IME, confirm the IME input, | 3183 // If the user is currently using an IME, confirm the IME input, |
3207 // and then insert the text from the service, the same as TextEdit and Safari. | 3184 // and then insert the text from the service, the same as TextEdit and Safari. |
3208 [self confirmComposition]; | 3185 [self confirmComposition]; |
3209 [self insertText:string]; | 3186 [self insertText:string]; |
3210 return YES; | 3187 return YES; |
3211 } | 3188 } |
3212 | 3189 |
3213 @end | 3190 @end |
OLD | NEW |