aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/SampleApp.gyp1
-rw-r--r--samplecode/SampleNinePatch.cpp118
-rw-r--r--src/views/mac/SkNSView.mm125
-rw-r--r--src/views/mac/SkOSWindow_Mac.mm6
4 files changed, 46 insertions, 204 deletions
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index 2db2a184cb..93f3b7311c 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -71,7 +71,6 @@
'../samplecode/SampleMeasure.cpp',
'../samplecode/SampleMipMap.cpp',
'../samplecode/SampleMovie.cpp',
- '../samplecode/SampleNinePatch.cpp',
'../samplecode/SampleOvalTest.cpp',
'../samplecode/SampleOverflow.cpp',
'../samplecode/SamplePageFlip.cpp',
diff --git a/samplecode/SampleNinePatch.cpp b/samplecode/SampleNinePatch.cpp
deleted file mode 100644
index 4286ed3e70..0000000000
--- a/samplecode/SampleNinePatch.cpp
+++ /dev/null
@@ -1,118 +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.
- */
-
-#include "SampleCode.h"
-#include "SkCanvas.h"
-#include "SkDevice.h"
-#include "SkPaint.h"
-#if SK_SUPPORT_GPU
-#include "SkGpuDevice.h"
-#else
-class GrContext;
-#endif
-
-static void make_bitmap(SkBitmap* bitmap, GrContext* ctx, SkIRect* center) {
- SkDevice* dev;
- SkCanvas canvas;
-
- const int kFixed = 28;
- const int kStretchy = 8;
- const int kSize = 2*kFixed + kStretchy;
-
-#if SK_SUPPORT_GPU
- if (ctx) {
- dev = new SkGpuDevice(ctx, SkBitmap::kARGB_8888_Config, kSize, kSize);
- *bitmap = dev->accessBitmap(false);
- } else
-#endif
- {
- bitmap->setConfig(SkBitmap::kARGB_8888_Config, kSize, kSize);
- bitmap->allocPixels();
- dev = new SkDevice(*bitmap);
- }
-
- canvas.setDevice(dev)->unref();
- canvas.clear(0);
-
- SkRect r = SkRect::MakeWH(SkIntToScalar(kSize), SkIntToScalar(kSize));
- const SkScalar strokeWidth = SkIntToScalar(6);
- const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
-
- center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
-
- SkPaint paint;
- paint.setAntiAlias(true);
-
- paint.setColor(0xFFFF0000);
- canvas.drawRoundRect(r, radius, radius, paint);
- r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize));
- paint.setColor(0x8800FF00);
- canvas.drawRect(r, paint);
- r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy));
- paint.setColor(0x880000FF);
- canvas.drawRect(r, paint);
-}
-
-
-class NinePatchView : public SampleView {
-public:
- NinePatchView() {}
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "NinePatch");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- virtual void onDrawContent(SkCanvas* canvas) {
- SkBitmap bm;
- SkIRect center;
- make_bitmap(&bm, SampleCode::GetGr(), &center);
-
- // amount of bm that should not be stretched (unless we have to)
- const SkScalar fixed = SkIntToScalar(bm.width() - center.width());
-
- const SkTSize<SkScalar> size[] = {
- { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
- { fixed * 4 / 5, fixed * 4 }, // shrink in X
- { fixed * 4, fixed * 4 / 5 }, // shrink in Y
- { fixed * 4, fixed * 4 }
- };
-
- canvas->drawBitmap(bm, SkIntToScalar(10), SkIntToScalar(10), NULL);
-
- SkScalar x = SkIntToScalar(100);
- SkScalar y = SkIntToScalar(100);
-
- SkPaint paint;
- paint.setFilterBitmap(true);
-
- for (int iy = 0; iy < 2; ++iy) {
- for (int ix = 0; ix < 2; ++ix) {
- int i = ix * 2 + iy;
- SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed,
- size[i].width(), size[i].height());
- canvas->drawBitmapNine(bm, center, r, &paint);
- }
- }
- }
-
-private:
- SkScalar fX, fY;
- typedef SampleView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new NinePatchView; }
-static SkViewRegister reg(MyFactory);
-
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
index 92a357db19..580651c0ad 100644
--- a/src/views/mac/SkNSView.mm
+++ b/src/views/mac/SkNSView.mm
@@ -6,18 +6,15 @@
* found in the LICENSE file.
*/
-#import "SkNSView.h"
+#import "SkNSView.h"s
#include "SkCanvas.h"
#include "SkCGUtils.h"
#include "SkEvent.h"
+SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
//#define FORCE_REDRAW
@implementation SkNSView
-@synthesize fWind, fTitle, fOptionsDelegate;
-
-#if SK_SUPPORT_GPU
-@synthesize fGLContext;
-#endif
+@synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
@@ -46,7 +43,6 @@
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];
}
}
@@ -61,10 +57,8 @@
- (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
}
}
@@ -75,9 +69,7 @@
- (void)dealloc {
delete fWind;
-#if SK_SUPPORT_GPU
self.fGLContext = nil;
-#endif
self.fTitle = nil;
[super dealloc];
}
@@ -124,13 +116,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,
@@ -145,17 +137,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 },
@@ -166,12 +158,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 {
@@ -231,8 +223,8 @@ static SkKey raw2key(UInt32 raw)
}
///////////////////////////////////////////////////////////////////////////////
-#if SK_SUPPORT_GPU
#include <OpenGL/OpenGL.h>
+
namespace {
CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor;
@@ -275,75 +267,46 @@ 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 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];
+- (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;
}
-
- [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;
+ [fGLContext setView:self];
}
- return false;
+
+ [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;
}
- (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 3e499ba4dd..e054a947b2 100644
--- a/src/views/mac/SkOSWindow_Mac.mm
+++ b/src/views/mac/SkOSWindow_Mac.mm
@@ -17,11 +17,11 @@
#import "SkEventNotifier.h"
#define kINVAL_NSVIEW_EventType "inval-nsview"
+SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
+
SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
fInvalEventIsPending = false;
-#if SK_SUPPORT_GPU
fGLContext = NULL;
-#endif
fNotifier = [[SkEventNotifier alloc] init];
}
SkOSWindow::~SkOSWindow() {
@@ -40,9 +40,7 @@ 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]) {