diff options
author | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-02 14:03:32 +0000 |
---|---|---|
committer | bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-08-02 14:03:32 +0000 |
commit | cf8fb1f6f03fc77f9927564f9ef9abeeeec508d2 (patch) | |
tree | 7534f5f2edd97cd61f18ee35ae4a14407a53453e /src/views | |
parent | f2a9e58858423be9cbfa72e01e8284754e7d6381 (diff) |
Create GPU-less build of Skia.
git-svn-id: http://skia.googlecode.com/svn/trunk@4912 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/views')
-rw-r--r-- | src/views/mac/SkNSView.h | 4 | ||||
-rw-r--r-- | src/views/mac/SkNSView.mm | 124 | ||||
-rw-r--r-- | src/views/mac/SkOSWindow_Mac.mm | 4 | ||||
-rw-r--r-- | src/views/win/SkOSWindow_win.cpp | 36 |
4 files changed, 113 insertions, 55 deletions
diff --git a/src/views/mac/SkNSView.h b/src/views/mac/SkNSView.h index bf6e67c71c..8b83b34f49 100644 --- a/src/views/mac/SkNSView.h +++ b/src/views/mac/SkNSView.h @@ -24,13 +24,17 @@ class SkEvent; NSString* fTitle; SkOSWindow* fWind; +#if SK_SUPPORT_GPU NSOpenGLContext* fGLContext; +#endif id<SkNSViewOptionsDelegate> fOptionsDelegate; } @property (nonatomic, readonly) SkOSWindow *fWind; @property (nonatomic, retain) NSString* fTitle; +#if SK_SUPPORT_GPU @property (nonatomic, retain) NSOpenGLContext* fGLContext; +#endif @property (nonatomic, assign) id<SkNSViewOptionsDelegate> fOptionsDelegate; - (id)initWithDefaults; diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm index dfb646d84f..92a357db19 100644 --- a/src/views/mac/SkNSView.mm +++ b/src/views/mac/SkNSView.mm @@ -6,14 +6,18 @@ * found in the LICENSE file. */ -#import "SkNSView.h"s +#import "SkNSView.h" #include "SkCanvas.h" #include "SkCGUtils.h" #include "SkEvent.h" //#define FORCE_REDRAW @implementation SkNSView -@synthesize fWind, fTitle, fOptionsDelegate, fGLContext; +@synthesize fWind, fTitle, fOptionsDelegate; + +#if SK_SUPPORT_GPU +@synthesize fGLContext; +#endif - (id)initWithCoder:(NSCoder*)coder { if ((self = [super initWithCoder:coder])) { @@ -42,6 +46,7 @@ fWind->setVisibleP(true); fWind->resize((int) self.frame.size.width, (int) self.frame.size.height, SkBitmap::kARGB_8888_Config); + [self attach:SkOSWindow::kNone_BackEndType withMSAASampleCount:0]; } } @@ -56,8 +61,10 @@ - (void)resizeSkView:(NSSize)newSize { if (NULL != fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) { fWind->resize((int) newSize.width, (int) newSize.height); +#if SK_SUPPORT_GPU glClear(GL_STENCIL_BUFFER_BIT); [fGLContext update]; +#endif } } @@ -68,7 +75,9 @@ - (void)dealloc { delete fWind; +#if SK_SUPPORT_GPU self.fGLContext = nil; +#endif self.fTitle = nil; [super dealloc]; } @@ -115,13 +124,13 @@ #include "SkKey.h" enum { - SK_MacReturnKey = 36, - SK_MacDeleteKey = 51, - SK_MacEndKey = 119, - SK_MacLeftKey = 123, - SK_MacRightKey = 124, - SK_MacDownKey = 125, - SK_MacUpKey = 126, + SK_MacReturnKey = 36, + SK_MacDeleteKey = 51, + SK_MacEndKey = 119, + SK_MacLeftKey = 123, + SK_MacRightKey = 124, + SK_MacDownKey = 125, + SK_MacUpKey = 126, SK_Mac0Key = 0x52, SK_Mac1Key = 0x53, SK_Mac2Key = 0x54, @@ -136,17 +145,17 @@ enum { static SkKey raw2key(UInt32 raw) { - static const struct { - UInt32 fRaw; - SkKey fKey; - } gKeys[] = { - { SK_MacUpKey, kUp_SkKey }, - { SK_MacDownKey, kDown_SkKey }, - { SK_MacLeftKey, kLeft_SkKey }, - { SK_MacRightKey, kRight_SkKey }, - { SK_MacReturnKey, kOK_SkKey }, - { SK_MacDeleteKey, kBack_SkKey }, - { SK_MacEndKey, kEnd_SkKey }, + static const struct { + UInt32 fRaw; + SkKey fKey; + } gKeys[] = { + { SK_MacUpKey, kUp_SkKey }, + { SK_MacDownKey, kDown_SkKey }, + { SK_MacLeftKey, kLeft_SkKey }, + { SK_MacRightKey, kRight_SkKey }, + { SK_MacReturnKey, kOK_SkKey }, + { SK_MacDeleteKey, kBack_SkKey }, + { SK_MacEndKey, kEnd_SkKey }, { SK_Mac0Key, k0_SkKey }, { SK_Mac1Key, k1_SkKey }, { SK_Mac2Key, k2_SkKey }, @@ -157,12 +166,12 @@ static SkKey raw2key(UInt32 raw) { SK_Mac7Key, k7_SkKey }, { 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; - return kNONE_SkKey; + for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++) + if (gKeys[i].fRaw == raw) + return gKeys[i].fKey; + return kNONE_SkKey; } - (void)keyDown:(NSEvent *)event { @@ -222,8 +231,8 @@ static SkKey raw2key(UInt32 raw) } /////////////////////////////////////////////////////////////////////////////// +#if SK_SUPPORT_GPU #include <OpenGL/OpenGL.h> - namespace { CGLContextObj createGLContext(int msaaSampleCount) { GLint major, minor; @@ -266,46 +275,75 @@ CGLContextObj createGLContext(int msaaSampleCount) { return ctx; } } +#endif - (void)viewDidMoveToWindow { [super viewDidMoveToWindow]; +#if SK_SUPPORT_GPU //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 //it must NOT be deferred or should have been on screen at least once) if ([fGLContext view] != self && nil != self.window) { [fGLContext setView:self]; } +#endif } -- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType - withMSAASampleCount:(int) sampleCount { - if (nil == fGLContext) { - CGLContextObj ctx = createGLContext(sampleCount); - fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; - CGLReleaseContext(ctx); - if (NULL == fGLContext) { - return false; +- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount { +#if SK_SUPPORT_GPU + if (SkOSWindow::kNativeGL_BackEndType == attachType) { + [self setWantsLayer:NO]; + self.layer = nil; + if (nil == fGLContext) { + CGLContextObj ctx = createGLContext(sampleCount); + fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; + CGLReleaseContext(ctx); + if (NULL == fGLContext) { + return false; + } + [fGLContext setView:self]; } - [fGLContext setView:self]; + + [fGLContext makeCurrentContext]; + + glViewport(0, 0, (int) self.bounds.size.width, (int) self.bounds.size.width); + glClearColor(0, 0, 0, 0); + glClearStencil(0); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + return true; } - - [fGLContext makeCurrentContext]; - - glViewport(0, 0, (int) self.bounds.size.width, (int) self.bounds.size.width); - glClearColor(0, 0, 0, 0); - glClearStencil(0); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - return true; +#endif + if (SkOSWindow::kNone_BackEndType == attachType) { + [self detach]; + [self setLayer:[CALayer layer]]; + [self setWantsLayer:YES]; + return true; + } + return false; } - (void)detach { +#if SK_SUPPORT_GPU [fGLContext release]; fGLContext = nil; +#endif } +#include "SkCGUtils.h" + - (void)present { +#if SK_SUPPORT_GPU if (nil != fGLContext) { [fGLContext flushBuffer]; + return; } +#endif + const SkBitmap& bmp = fWind->getBitmap(); + SkASSERT(self.layer); + // FIXME: This causes the layer to flicker during animation. Making a copy of the CGImage does + // not help. + CGImageRef img = SkCreateCGImageRef(bmp); + self.layer.contents = (id) img; + CGImageRelease(img); } @end diff --git a/src/views/mac/SkOSWindow_Mac.mm b/src/views/mac/SkOSWindow_Mac.mm index a5d3fef706..3e499ba4dd 100644 --- a/src/views/mac/SkOSWindow_Mac.mm +++ b/src/views/mac/SkOSWindow_Mac.mm @@ -19,7 +19,9 @@ SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { fInvalEventIsPending = false; +#if SK_SUPPORT_GPU fGLContext = NULL; +#endif fNotifier = [[SkEventNotifier alloc] init]; } SkOSWindow::~SkOSWindow() { @@ -38,7 +40,9 @@ bool SkOSWindow::onEvent(const SkEvent& evt) { fInvalEventIsPending = false; const SkIRect& r = this->getDirtyBounds(); [(SkNSView*)fHWND postInvalWithRect:&r]; +#if SK_SUPPORT_GPU [(NSOpenGLContext*)fGLContext update]; +#endif return true; } if ([(SkNSView*)fHWND onHandleEvent:evt]) { diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp index 2f8e0157c9..88a0a36a0f 100644 --- a/src/views/win/SkOSWindow_win.cpp +++ b/src/views/win/SkOSWindow_win.cpp @@ -38,19 +38,22 @@ void post_skwinevent() PostMessage(gEventTarget, WM_EVENT_CALLBACK, 0, 0); } -SkOSWindow::SkOSWindow(void* hWnd) - : fHWND(hWnd) +SkOSWindow::SkOSWindow(void* hWnd) { + fHWND = hWnd; +#if SK_SUPPORT_GPU #if SK_ANGLE - , fDisplay(EGL_NO_DISPLAY) - , fContext(EGL_NO_CONTEXT) - , fSurface(EGL_NO_SURFACE) + fDisplay = EGL_NO_DISPLAY; + fContext = EGL_NO_CONTEXT; + fSurface = EGL_NO_SURFACE; #endif - , fHGLRC(NULL) - , fAttached(kNone_BackEndType) { + fHGLRC = NULL; +#endif + fAttached = kNone_BackEndType; gEventTarget = (HWND)hWnd; } SkOSWindow::~SkOSWindow() { +#if SK_SUPPORT_GPU if (NULL != fHGLRC) { wglDeleteContext((HGLRC)fHGLRC); } @@ -69,7 +72,8 @@ SkOSWindow::~SkOSWindow() { eglTerminate(fDisplay); fDisplay = EGL_NO_DISPLAY; } -#endif +#endif // SK_ANGLE +#endif // SK_SUPPORT_GPU } static SkKey winToskKey(WPARAM vk) { @@ -305,6 +309,7 @@ void SkEvent::SignalQueueTimer(SkMSec delay) } } +#if SK_SUPPORT_GPU HGLRC create_gl(HWND hwnd, int msaaSampleCount) { HDC dc = GetDC(hwnd); @@ -563,7 +568,8 @@ void SkOSWindow::presentANGLE() { eglSwapBuffers(fDisplay, fSurface); } -#endif +#endif // SK_ANGLE +#endif // SK_SUPPORT_GPU // return true on success bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) { @@ -578,6 +584,7 @@ bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) { case kNone_BackEndType: // nothing to do break; +#if SK_SUPPORT_GPU case kNativeGL_BackEndType: result = attachGL(msaaSampleCount); break; @@ -585,7 +592,8 @@ bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) { case kANGLE_BackEndType: result = attachANGLE(msaaSampleCount); break; -#endif +#endif // SK_ANGLE +#endif // SK_SUPPORT_GPU default: SkASSERT(false); result = false; @@ -604,6 +612,7 @@ void SkOSWindow::detach() { case kNone_BackEndType: // nothing to do break; +#if SK_SUPPORT_GPU case kNativeGL_BackEndType: detachGL(); break; @@ -611,7 +620,8 @@ void SkOSWindow::detach() { case kANGLE_BackEndType: detachANGLE(); break; -#endif +#endif // SK_ANGLE +#endif // SK_SUPPORT_GPU default: SkASSERT(false); break; @@ -624,6 +634,7 @@ void SkOSWindow::present() { case kNone_BackEndType: // nothing to do return; +#if SK_SUPPORT_GPU case kNativeGL_BackEndType: presentGL(); break; @@ -631,7 +642,8 @@ void SkOSWindow::present() { case kANGLE_BackEndType: presentANGLE(); break; -#endif +#endif // SK_ANGLE +#endif // SK_SUPPORT_GPU default: SkASSERT(false); break; |