Allows windowed apps to be built on the Mac just by writing a SkOSWindow subclass without needing nib/plist files.

Makes visualbench work on the Mac.

Review URL: https://codereview.chromium.org/1184143011
This commit is contained in:
bsalomon 2015-06-18 11:49:42 -07:00 коммит произвёл Commit bot
Родитель 274980cda1
Коммит 241b56db1d
16 изменённых файлов: 156 добавлений и 4201 удалений

Просмотреть файл

@ -15,7 +15,6 @@
{
'target_name': 'SampleApp',
'type': 'executable',
'mac_bundle' : 1,
'include_dirs' : [
'../src/core',
'../src/effects', #needed for BlurMask.h
@ -181,38 +180,6 @@
'../samplecode/SampleEncode.cpp',
],
}],
[ 'skia_os == "mac"', {
'sources': [
# Sample App specific files
'../src/views/mac/SampleApp-Info.plist',
'../src/views/mac/SampleAppDelegate.h',
'../src/views/mac/SampleAppDelegate.mm',
'../src/views/mac/SkSampleNSView.h',
'../src/views/mac/SkSampleNSView.mm',
# Mac files
'../src/views/mac/SkEventNotifier.h',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.h',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
],
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
'$(SDKROOT)/System/Library/Frameworks/OpenGL.framework',
],
'xcode_settings' : {
'INFOPLIST_FILE' : '../src/views/mac/SampleApp-Info.plist',
},
'mac_bundle_resources' : [
'../src/views/mac/SampleApp.xib',
],
}],
[ 'skia_os == "ios"', {
# TODO: This doesn't build properly yet, but it's getting there.
'sources!': [

Просмотреть файл

@ -12,17 +12,6 @@
'../experimental/SimpleCocoaApp/',
],
'sources': [
'../src/views/mac/SkEventNotifier.h',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.h',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
'../experimental/SimpleCocoaApp/SimpleApp-Info.plist',
'../experimental/SimpleCocoaApp/SimpleApp.h',
'../experimental/SimpleCocoaApp/SimpleApp.mm',

Просмотреть файл

@ -4,11 +4,13 @@
# found in the LICENSE file.
# GYP file to build hello world example.
{
'includes': [
'apptype_console.gypi',
],
'targets': [
{
'target_name': 'HelloWorld',
'type': 'executable',
'mac_bundle' : 1,
'include_dirs' : [
'../include/gpu',
],
@ -20,36 +22,6 @@
'skia_lib.gyp:skia_lib',
'views.gyp:views',
],
'conditions' : [
[ 'skia_os == "win"', {
'sources' : [
'../src/views/win/SkOSWindow_Win.cpp',
'../src/views/win/skia_win.cpp',
],
}],
[ 'skia_os == "mac"', {
'sources': [
'../example/mac/HelloWorldNSView.mm',
'../example/mac/HelloWorldDelegate.mm',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.m',
],
'include_dirs' : [
'../src/views/mac/'
],
'xcode_settings' : {
'INFOPLIST_FILE' : '../example/mac/HelloWorld-Info.plist',
},
'mac_bundle_resources' : [
'../example/mac/HelloWorld.xib'
],
}],
],
},
],
}

Просмотреть файл

@ -61,36 +61,6 @@
'../src/gpu',
]
}],
[ 'skia_os == "win"', {
'sources' : [
'../src/views/win/SkOSWindow_Win.cpp',
'../src/views/win/skia_win.cpp',
],
}],
[ 'skia_os == "mac"', {
'sources': [
'../src/views/mac/SampleAppDelegate.h',
'../src/views/mac/SampleAppDelegate.mm',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.h',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
],
'include_dirs' : [
'../src/views/mac/'
],
'xcode_settings' : {
'INFOPLIST_FILE' : '../experimental/SkiaExamples/SkiaExamples-Info.plist',
},
'mac_bundle_resources' : [
'../experimental/SkiaExamples/SkiaExamples.xib'
],
}],
],
}
],

Просмотреть файл

@ -61,6 +61,12 @@
'../src/views/SkWindow.cpp',
# Mac
'../src/views/mac/SkEventNotifier.h',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/skia_mac.mm',
@ -89,14 +95,22 @@
[ 'skia_os == "mac"', {
'link_settings': {
'libraries': [
'$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework',
'$(SDKROOT)/System/Library/Frameworks/OpenGL.framework',
'$(SDKROOT)/System/Library/Frameworks/Cocoa.framework',
'$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
],
},
},{
'sources!': [
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkEventNotifier.h',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/SkTextFieldCell.h',
'../src/views/mac/SkTextFieldCell.m',
'../src/views/mac/SkNSView.h',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/skia_mac.mm',
],
}],
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos"]', {

Просмотреть файл

@ -11,7 +11,6 @@
{
'target_name': 'visualbench',
'type': 'executable',
'mac_bundle' : 1,
'include_dirs' : [
'../include/gpu',
'../src/core',
@ -29,34 +28,6 @@
'views.gyp:views',
],
'conditions' : [
[ 'skia_os == "win"', {
'sources' : [
'../src/views/win/SkOSWindow_Win.cpp',
'../src/views/win/skia_win.cpp',
],
}],
[ 'skia_os == "mac"', {
'sources': [
'../example/mac/HelloWorldNSView.mm',
'../example/mac/HelloWorldDelegate.mm',
'../src/views/mac/SkEventNotifier.mm',
'../src/views/mac/skia_mac.mm',
'../src/views/mac/SkNSView.mm',
'../src/views/mac/SkOptionsTableView.mm',
'../src/views/mac/SkOSWindow_Mac.mm',
'../src/views/mac/SkTextFieldCell.m',
],
'include_dirs' : [
'../src/views/mac/'
],
'xcode_settings' : {
'INFOPLIST_FILE' : '../example/mac/HelloWorld-Info.plist',
},
'mac_bundle_resources' : [
'../example/mac/HelloWorld.xib'
],
}],
[ 'skia_os == "android"', {
'dependencies': [
'android_deps.gyp:Android_VisualBench',

Просмотреть файл

@ -30,10 +30,9 @@ public:
bool attach(SkBackEndTypes attachType, int msaaSampleCount, AttachmentInfo*);
void present();
bool makeFullscreen() { return false; }
void closeWindow() { /* Not impl yet */ }
void setVsync(bool) { /* Not impl yet */ }
bool makeFullscreen();
void closeWindow();
void setVsync(bool);
protected:
// overrides from SkEventSink
virtual bool onEvent(const SkEvent& evt);

Просмотреть файл

@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.googlecode.skia.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>SampleApp</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,27 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#import <Cocoa/Cocoa.h>
#import "SkSampleNSView.h"
#import "SkOptionsTableView.h"
@interface SampleAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow* fWindow;
SkSampleNSView* fView;
SkOptionsTableView* fOptions;
}
@property (assign) IBOutlet NSWindow* fWindow;
@property (assign) IBOutlet SkSampleNSView* fView;
@property (assign) IBOutlet SkOptionsTableView* fOptions;
- (IBAction)toiPadSize:(id)sender;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
@end

Просмотреть файл

@ -1,26 +0,0 @@
#import "SampleAppDelegate.h"
#include "SkApplication.h"
@implementation SampleAppDelegate
@synthesize fWindow, fView, fOptions;
-(void) applicationDidFinishLaunching:(NSNotification *)aNotification {
//Load specified skia views after launching
fView.fOptionsDelegate = fOptions;
[fWindow setAcceptsMouseMovedEvents:YES];
[fOptions registerMenus:fView.fWind->getMenus()];
}
- (IBAction)toiPadSize:(id)sender {
NSRect frame = NSMakeRect(fWindow.frame.origin.x, fWindow.frame.origin.y, 768, 1024);
[fWindow setFrame:frame display:YES animate:YES];
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
[fView freeNativeWind];
application_term();
return NSTerminateNow;
}
@end

Просмотреть файл

@ -50,6 +50,8 @@ class SkEvent;
- (void)detach;
- (void)present;
- (void)setVSync:(bool)enable;
- (void)freeNativeWind;
@end

Просмотреть файл

@ -329,8 +329,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
///////////////////////////////////////////////////////////////////////////////
#include <OpenGL/OpenGL.h>
namespace {
CGLContextObj createGLContext(int msaaSampleCount) {
static CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor;
CGLGetVersion(&major, &minor);
@ -369,7 +368,6 @@ CGLContextObj createGLContext(int msaaSampleCount) {
CGLSetCurrentContext(ctx);
return ctx;
}
}
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
@ -420,4 +418,12 @@ CGLContextObj createGLContext(int msaaSampleCount) {
[fGLContext flushBuffer];
}
}
- (void)setVSync:(bool)enable {
if (fGLContext) {
GLint interval = enable ? 1 : 0;
CGLContextObj ctx = (CGLContextObj)[fGLContext CGLContextObj];
CGLSetParameter(ctx, kCGLCPSwapInterval, &interval);
}
}
@end

Просмотреть файл

@ -77,4 +77,18 @@ void SkOSWindow::present() {
[(SkNSView*)fHWND present];
}
void SkOSWindow::closeWindow() {
[[(SkNSView*)fHWND window] close];
}
void SkOSWindow::setVsync(bool enable) {
[(SkNSView*)fHWND setVSync:enable];
}
bool SkOSWindow::makeFullscreen() {
[(SkNSView*)fHWND enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
return true;
}
#endif

Просмотреть файл

@ -6,19 +6,119 @@
* found in the LICENSE file.
*/
#include <crt_externs.h>
#import <Cocoa/Cocoa.h>
#include "SkApplication.h"
#include "SkNSView.h"
@interface MainView : SkNSView {
}
- (id)initWithFrame: (NSRect)frame ;
- (void)dealloc;
- (void)begin;
@end
@implementation MainView : SkNSView
- (id)initWithFrame: (NSRect)frame {
self = [super initWithFrame:frame];
return self;
}
- (void)dealloc {
delete fWind;
[super dealloc];
}
- (void)begin {
fWind = create_sk_window(self, *_NSGetArgc(), *_NSGetArgv());
[self setUpWindow];
}
@end
@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate> {
}
- (id)init;
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
@end
#
@implementation AppDelegate : NSObject
- (id)init {
self = [super init];
return self;
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
return TRUE;
}
@end
int main(int argc, char *argv[]) {
signal(SIGPIPE, SIG_IGN);
/*NSAutoreleasePool* pool = */ [[NSAutoreleasePool alloc] init];
application_init();
int retVal = NSApplicationMain(argc, (const char **)argv);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
#if 0
// we don't expect NSApplicationMain to return. See our applicationShouldTerminate handler.
application_term();
NSApplication* app = [NSApplication sharedApplication];
NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask);
NSRect windowRect = NSMakeRect(100, 100, 1000, 1000);
NSWindow* window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
NSRect rect = [NSWindow contentRectForFrameRect:windowRect styleMask:windowStyle];
MainView* customView = [[MainView alloc] initWithFrame:rect];
[customView setTranslatesAutoresizingMaskIntoConstraints:NO];
NSView* contentView = window.contentView;
[contentView addSubview:customView];
NSDictionary *views = NSDictionaryOfVariableBindings(customView);
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[customView]|"
options:0
metrics:nil
views:views]];
[contentView addConstraints:
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[customView]|"
options:0
metrics:nil
views:views]];
[customView begin];
[customView release];
[window makeKeyAndOrderFront:NSApp];
AppDelegate * appDelegate = [[[AppDelegate alloc] init] autorelease];
app.delegate = appDelegate;
NSMenu* menu=[[NSMenu alloc] initWithTitle:@"AMainMenu"];
NSMenuItem* item;
NSMenu* subMenu;
//Create the application menu.
item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""];
[menu addItem:item];
subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
[menu setSubmenu:subMenu forItem:item];
[item release];
item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
[subMenu addItem:item];
[item release];
[subMenu release];
//Add the menu to the app.
[app setMenu:menu];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
[app run];
[menu release];
[appDelegate release];
[window release];
[pool release];
#endif
return retVal;
return EXIT_SUCCESS;
}

Просмотреть файл

@ -123,7 +123,7 @@ void VisualBench::setupRenderTarget() {
inline void VisualBench::renderFrame(SkCanvas* canvas) {
canvas->drawPicture(fPicture);
fContext->flush();
canvas->flush();
INHERITED::present();
}