diff options
Diffstat (limited to 'src/views')
-rw-r--r-- | src/views/mac/SkNSView.h | 1 | ||||
-rw-r--r-- | src/views/mac/SkNSView.mm | 29 | ||||
-rw-r--r-- | src/views/mac/SkOSWindow_Mac.mm | 13 | ||||
-rw-r--r-- | src/views/unix/SkOSWindow_Unix.cpp | 30 | ||||
-rw-r--r-- | src/views/win/SkOSWindow_win.cpp | 14 |
5 files changed, 63 insertions, 24 deletions
diff --git a/src/views/mac/SkNSView.h b/src/views/mac/SkNSView.h index 1718b2ac11..bf83c61c25 100644 --- a/src/views/mac/SkNSView.h +++ b/src/views/mac/SkNSView.h @@ -27,6 +27,7 @@ class SkEvent; @property (nonatomic, assign) id<SkNSViewOptionsDelegate> fOptionsDelegate; - (id)initWithDefaults; +- (void)setNSViewSize:(NSSize)size; - (void)setUpWindow; - (void)resizeSkView:(NSSize)newSize; - (void)setSkTitle:(const char*)title; diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm index 64c02ca2a5..94a3b5fa4e 100644 --- a/src/views/mac/SkNSView.mm +++ b/src/views/mac/SkNSView.mm @@ -51,6 +51,13 @@ BOOL fRedrawRequestPending; return self; } +- (void)setNSViewSize:(NSSize)size { + NSWindow* w = [self window]; + NSRect f; + f.size = size; + [w setFrame:f display:YES]; +} + - (void)setUpWindow { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backingPropertiesChanged:) @@ -98,7 +105,7 @@ BOOL fRedrawRequestPending; if (oldBackingScaleFactor == newBackingScaleFactor) { return; } - + // TODO: need a better way to force a refresh (that works). // [fGLContext update] does not appear to update if the point size has not changed, // even if the backing size has changed. @@ -220,7 +227,7 @@ static SkKey raw2key(UInt32 raw) { SK_Mac8Key, k8_SkKey }, { SK_Mac9Key, k9_SkKey } }; - + for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++) if (gKeys[i].fRaw == raw) return gKeys[i].fKey; @@ -230,7 +237,7 @@ static SkKey raw2key(UInt32 raw) - (void)keyDown:(NSEvent *)event { if (NULL == fWind) return; - + SkKey key = raw2key([event keyCode]); if (kNONE_SkKey != key) fWind->handleKey(key); @@ -243,7 +250,7 @@ static SkKey raw2key(UInt32 raw) - (void)keyUp:(NSEvent *)event { if (NULL == fWind) return; - + SkKey key = raw2key([event keyCode]); if (kNONE_SkKey != key) fWind->handleKeyUp(key); @@ -305,7 +312,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) { - (void)mouseMoved:(NSEvent *)event { NSPoint p = [event locationInWindow]; unsigned modi = convertNSModifiersToSk([event modifierFlags]); - + if ([self mouse:p inRect:[self bounds]] && fWind) { NSPoint loc = [self convertPoint:p fromView:nil]; #if RETINA_API_AVAILABLE @@ -320,7 +327,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) { - (void)mouseUp:(NSEvent *)event { NSPoint p = [event locationInWindow]; unsigned modi = convertNSModifiersToSk([event modifierFlags]); - + if ([self mouse:p inRect:[self bounds]] && fWind) { NSPoint loc = [self convertPoint:p fromView:nil]; #if RETINA_API_AVAILABLE @@ -338,7 +345,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) { static CGLContextObj createGLContext(int msaaSampleCount) { GLint major, minor; CGLGetVersion(&major, &minor); - + static const CGLPixelFormatAttribute attributes[] = { kCGLPFAStencilSize, (CGLPixelFormatAttribute) 8, kCGLPFAAccelerated, @@ -346,7 +353,7 @@ static CGLContextObj createGLContext(int msaaSampleCount) { kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, (CGLPixelFormatAttribute)0 }; - + CGLPixelFormatObj format; GLint npix = 0; if (msaaSampleCount > 0) { @@ -369,7 +376,7 @@ static CGLContextObj createGLContext(int msaaSampleCount) { CGLContextObj ctx; CGLCreateContext(format, NULL, &ctx); CGLDestroyPixelFormat(format); - + static const GLint interval = 1; CGLSetParameter(ctx, kCGLCPSwapInterval, &interval); CGLSetCurrentContext(ctx); @@ -378,9 +385,9 @@ static CGLContextObj createGLContext(int msaaSampleCount) { - (void)viewDidMoveToWindow { [super viewDidMoveToWindow]; - + //Attaching view to fGLContext requires that the view to be part of a window, - //and that the NSWindow instance must have a CoreGraphics counterpart (or + //and that the NSWindow instance must have a CoreGraphics counterpart (or //it must NOT be deferred or should have been on screen at least once) if ([fGLContext view] != self && nil != self.window) { [fGLContext setView:self]; diff --git a/src/views/mac/SkOSWindow_Mac.mm b/src/views/mac/SkOSWindow_Mac.mm index a256b39fa3..bb00bbcf77 100644 --- a/src/views/mac/SkOSWindow_Mac.mm +++ b/src/views/mac/SkOSWindow_Mac.mm @@ -14,13 +14,26 @@ #import "SkEventNotifier.h" #define kINVAL_NSVIEW_EventType "inval-nsview" +static constexpr int DEFAULT_W = 1024; +static constexpr int DEFAULT_H = 768; + static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build"); +SkOSWindow::SkOSWindow(void* hwnd, int w, int h): fHWND(hwnd) { + this->init(hwnd, w, h); +} + SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { + this->init(hWnd, DEFAULT_W, DEFAULT_H); +} + +void SkOSWindow::init(void* hwnd, int w, int h) { fInvalEventIsPending = false; fGLContext = NULL; fNotifier = [[SkEventNotifier alloc] init]; + [(SkNSView*)hwnd setNSViewSize:NSMakeSize(w, h)]; } + SkOSWindow::~SkOSWindow() { [(SkEventNotifier*)fNotifier release]; } diff --git a/src/views/unix/SkOSWindow_Unix.cpp b/src/views/unix/SkOSWindow_Unix.cpp index 2f195927e0..dcdfd06008 100644 --- a/src/views/unix/SkOSWindow_Unix.cpp +++ b/src/views/unix/SkOSWindow_Unix.cpp @@ -24,20 +24,30 @@ extern "C" { #include "keysym2ucs.h" } -const int WIDTH = 500; -const int HEIGHT = 500; +const int WIDTH = 1024; +const int HEIGHT = 768; // Determine which events to listen for. const long EVENT_MASK = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask |ExposureMask|PointerMotionMask|KeyPressMask|KeyReleaseMask; +void SkOSWindow::init(int w, int h) { + fUnixWindow.fDisplay = nullptr; + fUnixWindow.fGLContext = nullptr; + this->initWindow(0, nullptr, w, h); + this->resize(w, h); +} + SkOSWindow::SkOSWindow(void*) : fVi(nullptr) , fMSAASampleCount(0) { - fUnixWindow.fDisplay = nullptr; - fUnixWindow.fGLContext = nullptr; - this->initWindow(0, nullptr); - this->resize(WIDTH, HEIGHT); + this->init(WIDTH, HEIGHT); +} + +SkOSWindow::SkOSWindow(void*, int width, int height) + : fVi(nullptr) + , fMSAASampleCount(0) { + this->init(width, height); } SkOSWindow::~SkOSWindow() { @@ -58,7 +68,7 @@ void SkOSWindow::internalCloseWindow() { } } -void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info) { +void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info, int w, int h) { if (fMSAASampleCount != requestedMSAASampleCount) { this->internalCloseWindow(); } @@ -123,7 +133,7 @@ void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info) fUnixWindow.fWin = XCreateWindow(dsp, RootWindow(dsp, fVi->screen), 0, 0, // x, y - WIDTH, HEIGHT, + w, h, 0, // border width fVi->depth, InputOutput, @@ -139,7 +149,7 @@ void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info) fUnixWindow.fWin = XCreateSimpleWindow(dsp, DefaultRootWindow(dsp), 0, 0, // x, y - WIDTH, HEIGHT, + w, h, 0, // border width 0, // border value 0); // background value @@ -350,7 +360,7 @@ static void glXSwapInterval(Display* dsp, GLXDrawable drawable, int interval) { bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, bool deepColor, AttachmentInfo* info) { - this->initWindow(msaaSampleCount, info); + this->initWindow(msaaSampleCount, info, WIDTH, HEIGHT); if (nullptr == fUnixWindow.fDisplay) { return false; diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp index 4c5f151c97..8788b10ef4 100644 --- a/src/views/win/SkOSWindow_win.cpp +++ b/src/views/win/SkOSWindow_win.cpp @@ -29,8 +29,8 @@ #include <EGL/eglext.h> #endif // SK_ANGLE -const int kDefaultWindowWidth = 500; -const int kDefaultWindowHeight = 500; +const int kDefaultWindowWidth = 1024; +const int kDefaultWindowHeight = 768; #define GL_CALL(IFACE, X) \ SkASSERT(IFACE); \ @@ -48,10 +48,18 @@ void post_skwinevent(HWND hwnd) SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap; SkOSWindow::SkOSWindow(const void* winInit) { + this->init(winInit, kDefaultWindowWidth, kDefaultWindowHeight); +} + +SkOSWindow::SkOSWindow(const void* winInit, int w, int h) { + this->init(winInit, w, h); +} + +void SkOSWindow::init(const void* winInit, int w, int h) { fWinInit = *(const WindowInit*)winInit; fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, kDefaultWindowWidth, kDefaultWindowHeight, NULL, NULL, + CW_USEDEFAULT, 0, w, h, NULL, NULL, fWinInit.fInstance, NULL); gHwndToOSWindowMap.set(fHWND, this); #if SK_SUPPORT_GPU |