diff options
author | maf@google.com <maf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-29 21:34:47 +0000 |
---|---|---|
committer | maf@google.com <maf@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-29 21:34:47 +0000 |
commit | aaf2ff9d4c18ed9c821e1d949595d194fe1e28e4 (patch) | |
tree | d1ee29ad2718acda1b077a8e0cc317a7b26d8180 /o3d | |
parent | 15bc709d5af8b4d1d31d7297d21c5d95396f01c4 (diff) | |
download | chromium_src-aaf2ff9d4c18ed9c821e1d949595d194fe1e28e4.zip chromium_src-aaf2ff9d4c18ed9c821e1d949595d194fe1e28e4.tar.gz chromium_src-aaf2ff9d4c18ed9c821e1d949595d194fe1e28e4.tar.bz2 |
Some refactoring. Move a lot of drawing related but not O3D specific code out of plugin_mac.mm into a new graphics_utils_mac.mm file.
Also remove period at end of fullscreen message.
Review URL: http://codereview.chromium.org/149052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r-- | o3d/plugin/build.scons | 1 | ||||
-rw-r--r-- | o3d/plugin/mac/graphics_utils_mac.h | 56 | ||||
-rw-r--r-- | o3d/plugin/mac/graphics_utils_mac.mm | 130 | ||||
-rw-r--r-- | o3d/plugin/mac/main_mac.mm | 2 | ||||
-rw-r--r-- | o3d/plugin/mac/plugin_mac.h | 2 | ||||
-rw-r--r-- | o3d/plugin/mac/plugin_mac.mm | 143 |
6 files changed, 218 insertions, 116 deletions
diff --git a/o3d/plugin/build.scons b/o3d/plugin/build.scons index aac7f16..0989eaa 100644 --- a/o3d/plugin/build.scons +++ b/o3d/plugin/build.scons @@ -260,6 +260,7 @@ if env.Bit('mac'): inputs += [ 'mac/main_mac.mm', 'mac/config_mac.mm', + 'mac/graphics_utils_mac.mm', plugin_mac_object ] diff --git a/o3d/plugin/mac/graphics_utils_mac.h b/o3d/plugin/mac/graphics_utils_mac.h new file mode 100644 index 0000000..9c4cee5 --- /dev/null +++ b/o3d/plugin/mac/graphics_utils_mac.h @@ -0,0 +1,56 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef O3D_PLUGIN_MAC_GRAPHICS_UTILS_MAC_H_ +#define O3D_PLUGIN_MAC_GRAPHICS_UTILS_MAC_H_ + +#include <Carbon/Carbon.h> +#include <Cocoa/Cocoa.h> +#include <AGL/agl.h> + +void SlideWindowToRect(WindowRef the_window, + CGRect destination_rect, + double transition_duration_seconds); + +void SetWindowLevel(WindowRef window, int level); + +bool SetWindowForAGLContext(AGLContext context, WindowRef window); + +bool IsMacOSTenFiveOrHigher(); + +Rect CGRect2Rect(const CGRect &inRect); + +CGRect Rect2CGRect(const Rect &inRect); + +void PaintRoundedCGRect(CGContextRef context, CGRect rect, + float radius, bool fill); + +#endif // O3D_PLUGIN_MAC_GRAPHICS_UTILS_MAC_H_ diff --git a/o3d/plugin/mac/graphics_utils_mac.mm b/o3d/plugin/mac/graphics_utils_mac.mm new file mode 100644 index 0000000..88af452 --- /dev/null +++ b/o3d/plugin/mac/graphics_utils_mac.mm @@ -0,0 +1,130 @@ +/* + * Copyright 2009, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "plugin/mac/graphics_utils_mac.h" + +// Slide a window to a different rect, asynchronously, over a period of time. +void SlideWindowToRect(WindowRef the_window, + CGRect destination_rect, + double transition_duration_seconds) { + TransitionWindowOptions options = {0, transition_duration_seconds, + NULL, NULL}; + TransitionWindowWithOptions(the_window, + kWindowSlideTransitionEffect, + kWindowMoveTransitionAction, + &destination_rect, true, &options); +} + +// Sets a Carbon window to a custom window level, by creating a new window +// group at that level and adding the window to the group. +void SetWindowLevel(WindowRef window, int level) { + WindowGroupRef wGroup = NULL; + WindowGroupAttributes attrs = 0; + CreateWindowGroup(attrs, &wGroup); + SetWindowGroupLevel(wGroup, level); + SetWindowGroup(window, wGroup); +} + + +// Given a WindowRef and an AGLContext, make the context draw in that window. +// Return Value: true if the window is successfully set, false otherwise. +bool SetWindowForAGLContext(AGLContext context, WindowRef window) { + return (IsMacOSTenFiveOrHigher()) ? + aglSetWindowRef(context, window) : + aglSetDrawable(context, GetWindowPort(window)); +} + + +// Returns whether OS is 10.5 (Leopard) or higher. +bool IsMacOSTenFiveOrHigher() { + static bool isCached = false, result = false; + + if (!isCached) { + SInt32 major = 0; + SInt32 minor = 0; + // These selectors don't exist pre 10.4 but as we check the error + // the function will correctly return NO which is the right answer. + result = ((::Gestalt(gestaltSystemVersionMajor, &major) == noErr) && + (::Gestalt(gestaltSystemVersionMinor, &minor) == noErr) && + ((major > 10) || (major == 10 && minor >= 5))); + isCached = true; + } + return result; +} + + +Rect CGRect2Rect(const CGRect &inRect) { + Rect outRect; + outRect.left = inRect.origin.x; + outRect.top = inRect.origin.y; + outRect.right = inRect.origin.x + inRect.size.width; + outRect.bottom = inRect.origin.y + inRect.size.height; + return outRect; +} + + +CGRect Rect2CGRect(const Rect &inRect) { + CGRect outRect; + outRect.origin.x = inRect.left; + outRect.origin.y = inRect.top; + outRect.size.width = inRect.right - inRect.left; + outRect.size.height = inRect.bottom - inRect.top; + return outRect; +} + + +// Paint a round rect, with the corner radius you specify, either filled or +// stroked. +void PaintRoundedCGRect(CGContextRef context, + CGRect rect, + float radius, + bool fill) { + CGFloat lx = CGRectGetMinX(rect); + CGFloat cx = CGRectGetMidX(rect); + CGFloat rx = CGRectGetMaxX(rect); + CGFloat by = CGRectGetMinY(rect); + CGFloat cy = CGRectGetMidY(rect); + CGFloat ty = CGRectGetMaxY(rect); + + CGContextBeginPath(context); + CGContextMoveToPoint(context, lx, cy); + CGContextAddArcToPoint(context, lx, by, cx, by, radius); + CGContextAddArcToPoint(context, rx, by, rx, cy, radius); + CGContextAddArcToPoint(context, rx, ty, cx, ty, radius); + CGContextAddArcToPoint(context, lx, ty, lx, cy, radius); + CGContextClosePath(context); + + if (fill) + CGContextFillPath(context); + else + CGContextStrokePath(context); +} diff --git a/o3d/plugin/mac/main_mac.mm b/o3d/plugin/mac/main_mac.mm index 59c374a..45491a7 100644 --- a/o3d/plugin/mac/main_mac.mm +++ b/o3d/plugin/mac/main_mac.mm @@ -52,6 +52,8 @@ #include "plugin/cross/plugin_metrics.h" #include "plugin/cross/out_of_memory.h" #include "plugin/mac/plugin_mac.h" +#include "plugin/mac/graphics_utils_mac.h" + o3d::PluginLogging* g_logger = NULL; bool g_logging_initialized = false; diff --git a/o3d/plugin/mac/plugin_mac.h b/o3d/plugin/mac/plugin_mac.h index 8563228..1e9efe5 100644 --- a/o3d/plugin/mac/plugin_mac.h +++ b/o3d/plugin/mac/plugin_mac.h @@ -81,11 +81,9 @@ void ReleaseSafariBrowserWindow(void* browserWindow); // Some miscellaneous helper functions... -bool SetWindowForAGLContext(AGLContext context, WindowRef window); void CFReleaseIfNotNull(CFTypeRef cf); -bool IsMacOSTenFiveOrHigher(void); // Converts an old style Mac HFS path eg "HD:Users:xxx:file.zip" into a standard // Posix path eg "/Users/xxx/file.zip" Assumes UTF8 in and out, returns a block diff --git a/o3d/plugin/mac/plugin_mac.mm b/o3d/plugin/mac/plugin_mac.mm index 7d63a0c..9a70d1d 100644 --- a/o3d/plugin/mac/plugin_mac.mm +++ b/o3d/plugin/mac/plugin_mac.mm @@ -38,13 +38,13 @@ #include "plugin/cross/o3d_glue.h" #include "plugin/cross/main.h" #include "core/mac/display_window_mac.h" +#include "plugin/mac/graphics_utils_mac.h" BreakpadRef gBreakpadRef = NULL; using glue::_o3d::PluginObject; using o3d::DisplayWindowMac; -static void DrawToOverlayWindow(WindowRef overlayWindow); // Returns the version number of the running Mac browser, as parsed from // the short version string in the plist of the app's bundle. @@ -279,14 +279,6 @@ void CFReleaseIfNotNull(CFTypeRef cf) { } -// Given a WindowRef and an AGLContext, make the context draw in that window. -// Return Value: true if the window is successfully set, false otherwise. -bool SetWindowForAGLContext(AGLContext context, WindowRef window) { - return (IsMacOSTenFiveOrHigher()) ? - aglSetWindowRef(context, window) : - aglSetDrawable(context, GetWindowPort(window)); -} - // Converts an old style Mac HFS path eg "HD:Users:xxx:file.zip" into // a standard Posix path eg "/Users/xxx/file.zip" @@ -328,41 +320,6 @@ char* CreatePosixFilePathFromHFSFilePath(const char* hfsPath) { return posix_path; } -// Returns whether OS is 10.5 (Leopard) or higher. -bool IsMacOSTenFiveOrHigher() { - static bool isCached = false, result = false; - - if (!isCached) { - SInt32 major = 0; - SInt32 minor = 0; - // These selectors don't exist pre 10.4 but as we check the error - // the function will correctly return NO which is the right answer. - result = ((::Gestalt(gestaltSystemVersionMajor, &major) == noErr) && - (::Gestalt(gestaltSystemVersionMinor, &minor) == noErr) && - ((major > 10) || (major == 10 && minor >= 5))); - isCached = true; - } - return result; -} - - -static Rect CGRect2Rect(const CGRect &inRect) { - Rect outRect; - outRect.left = inRect.origin.x; - outRect.top = inRect.origin.y; - outRect.right = inRect.origin.x + inRect.size.width; - outRect.bottom = inRect.origin.y + inRect.size.height; - return outRect; -} - -static CGRect Rect2CGRect(const Rect &inRect) { - CGRect outRect; - outRect.origin.x = inRect.left; - outRect.origin.y = inRect.top; - outRect.size.width = inRect.right - inRect.left; - outRect.size.height = inRect.bottom - inRect.top; - return outRect; -} // A little wrapper for ATSUSetAttributes to make calling it with one attribute @@ -394,30 +351,6 @@ static void MySetLayoutControl(ATSUTextLayout layout, } -static void PaintRoundedCGRect(CGContextRef context, - CGRect rect, - float radius, - bool fill) { - CGFloat lx = CGRectGetMinX(rect); - CGFloat cx = CGRectGetMidX(rect); - CGFloat rx = CGRectGetMaxX(rect); - CGFloat by = CGRectGetMinY(rect); - CGFloat cy = CGRectGetMidY(rect); - CGFloat ty = CGRectGetMaxY(rect); - - CGContextBeginPath(context); - CGContextMoveToPoint(context, lx, cy); - CGContextAddArcToPoint(context, lx, by, cx, by, radius); - CGContextAddArcToPoint(context, rx, by, rx, cy, radius); - CGContextAddArcToPoint(context, rx, ty, cx, ty, radius); - CGContextAddArcToPoint(context, lx, ty, lx, cy, radius); - CGContextClosePath(context); - - if (fill) - CGContextFillPath(context); - else - CGContextStrokePath(context); -} // Convenience function for fetching SInt32 parameters from Carbon EventRefs. static SInt32 GetIntEventParam(EventRef inEvent, EventParamName inName) { @@ -429,34 +362,11 @@ static SInt32 GetIntEventParam(EventRef inEvent, EventParamName inName) { #pragma mark ____OVERLAY_WINDOW -static OSStatus HandleOverlayWindow(EventHandlerCallRef inHandlerCallRef, - EventRef inEvent, - void *inUserData) { - OSType event_class = GetEventClass(inEvent); - OSType event_kind = GetEventKind(inEvent); - - if (event_class == kEventClassWindow && - event_kind == kEventWindowPaint) { - WindowRef theWindow = NULL; - GetEventParameter(inEvent, kEventParamDirectObject, - typeWindowRef, NULL, - sizeof(theWindow), NULL, - &theWindow); - if (theWindow) { - CallNextEventHandler(inHandlerCallRef, inEvent); - DrawToOverlayWindow(theWindow); - } - } - - return noErr; -} - - // Returns the unicode 16 chars that we need to display as the fullscreen // message. Should be disposed with free() after use. static UniChar * GetFullscreenDisplayText(int *returned_length) { // TODO this will need to be a localized string. - NSString* ns_display_text = @"Press ESC to exit fullscreen."; + NSString* ns_display_text = @"Press ESC to exit fullscreen"; int count = [ns_display_text length]; UniChar* display_text_16 = (UniChar*) calloc(count, sizeof(UniChar)); @@ -570,16 +480,30 @@ static void DrawToOverlayWindow(WindowRef overlayWindow) { QDEndCGContext(GetWindowPort(overlayWindow), &overlayContext); } +static OSStatus HandleOverlayWindow(EventHandlerCallRef inHandlerCallRef, + EventRef inEvent, + void *inUserData) { + OSType event_class = GetEventClass(inEvent); + OSType event_kind = GetEventKind(inEvent); -static void SetWindowLevel(WindowRef window, int level) { - WindowGroupRef wGroup = NULL; - WindowGroupAttributes attrs = 0; - CreateWindowGroup(attrs, &wGroup); - SetWindowGroupLevel(wGroup, level); - SetWindowGroup(window, wGroup); + if (event_class == kEventClassWindow && + event_kind == kEventWindowPaint) { + WindowRef theWindow = NULL; + GetEventParameter(inEvent, kEventParamDirectObject, + typeWindowRef, NULL, + sizeof(theWindow), NULL, + &theWindow); + if (theWindow) { + CallNextEventHandler(inHandlerCallRef, inEvent); + DrawToOverlayWindow(theWindow); + } + } + + return noErr; } + static Rect GetOverlayWindowRect(bool visible) { #define kOverlayHeight 60 #define kOverlayWidth 340 @@ -981,7 +905,6 @@ void PluginObject::GetDisplayModes(std::vector<o3d::DisplayMode> *modes) { #pragma mark ____FULLSCREEN_SWITCHING - #define kTransitionTime 1.0 bool PluginObject::RequestFullscreenDisplay() { @@ -1041,19 +964,14 @@ bool PluginObject::RequestFullscreenDisplay() { client()->SendResizeEvent(renderer_->width(), renderer_->height(), true); SetFullscreenOverlayMacWindow(CreateOverlayWindow()); - ShowWindow(GetFullscreenOverlayMacWindow()); - DrawToOverlayWindow(GetFullscreenOverlayMacWindow()); - TransitionWindowOptions options = {0, kTransitionTime, NULL, NULL}; - CGRect shown_rect = Rect2CGRect(GetOverlayWindowRect(true)); + ShowWindow(mac_fullscreen_overlay_window_); + SlideWindowToRect(mac_fullscreen_overlay_window_, + Rect2CGRect(GetOverlayWindowRect(true)), + kTransitionTime); // Hide the overlay text 4 seconds from now. time_to_hide_overlay_ = [NSDate timeIntervalSinceReferenceDate] + 4.0; - TransitionWindowWithOptions(GetFullscreenOverlayMacWindow(), - kWindowSlideTransitionEffect, - kWindowMoveTransitionAction, - &shown_rect, true, &options); - return true; } @@ -1095,12 +1013,9 @@ void PluginObject::FullscreenIdle() { (time_to_hide_overlay_ != 0.0) && (time_to_hide_overlay_ < [NSDate timeIntervalSinceReferenceDate])) { time_to_hide_overlay_ = 0.0; - TransitionWindowOptions options = {0, kTransitionTime, NULL, NULL}; - CGRect hidden_rect = Rect2CGRect(GetOverlayWindowRect(false)); - TransitionWindowWithOptions(mac_fullscreen_overlay_window_, - kWindowSlideTransitionEffect, - kWindowMoveTransitionAction, - &hidden_rect, true, &options); + SlideWindowToRect(mac_fullscreen_overlay_window_, + Rect2CGRect(GetOverlayWindowRect(false)), + kTransitionTime); } } |