aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views/mac/SkNSView.mm
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-02 14:03:32 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-02 14:03:32 +0000
commitcf8fb1f6f03fc77f9927564f9ef9abeeeec508d2 (patch)
tree7534f5f2edd97cd61f18ee35ae4a14407a53453e /src/views/mac/SkNSView.mm
parentf2a9e58858423be9cbfa72e01e8284754e7d6381 (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/mac/SkNSView.mm')
-rw-r--r--src/views/mac/SkNSView.mm124
1 files changed, 81 insertions, 43 deletions
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