revert gpu-less mac sample app, remove busted sample (that has equivalent gm)

Review URL: https://codereview.appspot.com/6450088/



git-svn-id: http://skia.googlecode.com/svn/trunk@4954 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2012-08-03 19:25:10 +00:00
Родитель 8d3d210e74
Коммит 2e40173c95
4 изменённых файлов: 46 добавлений и 204 удалений

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

@ -71,7 +71,6 @@
'../samplecode/SampleMeasure.cpp', '../samplecode/SampleMeasure.cpp',
'../samplecode/SampleMipMap.cpp', '../samplecode/SampleMipMap.cpp',
'../samplecode/SampleMovie.cpp', '../samplecode/SampleMovie.cpp',
'../samplecode/SampleNinePatch.cpp',
'../samplecode/SampleOvalTest.cpp', '../samplecode/SampleOvalTest.cpp',
'../samplecode/SampleOverflow.cpp', '../samplecode/SampleOverflow.cpp',
'../samplecode/SamplePageFlip.cpp', '../samplecode/SamplePageFlip.cpp',

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

@ -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);

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

@ -6,18 +6,15 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#import "SkNSView.h" #import "SkNSView.h"s
#include "SkCanvas.h" #include "SkCanvas.h"
#include "SkCGUtils.h" #include "SkCGUtils.h"
#include "SkEvent.h" #include "SkEvent.h"
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
//#define FORCE_REDRAW //#define FORCE_REDRAW
@implementation SkNSView @implementation SkNSView
@synthesize fWind, fTitle, fOptionsDelegate; @synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
#if SK_SUPPORT_GPU
@synthesize fGLContext;
#endif
- (id)initWithCoder:(NSCoder*)coder { - (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) { if ((self = [super initWithCoder:coder])) {
@ -46,7 +43,6 @@
fWind->setVisibleP(true); fWind->setVisibleP(true);
fWind->resize((int) self.frame.size.width, (int) self.frame.size.height, fWind->resize((int) self.frame.size.width, (int) self.frame.size.height,
SkBitmap::kARGB_8888_Config); SkBitmap::kARGB_8888_Config);
[self attach:SkOSWindow::kNone_BackEndType withMSAASampleCount:0];
} }
} }
@ -61,10 +57,8 @@
- (void)resizeSkView:(NSSize)newSize { - (void)resizeSkView:(NSSize)newSize {
if (NULL != fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) { if (NULL != fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) {
fWind->resize((int) newSize.width, (int) newSize.height); fWind->resize((int) newSize.width, (int) newSize.height);
#if SK_SUPPORT_GPU
glClear(GL_STENCIL_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT);
[fGLContext update]; [fGLContext update];
#endif
} }
} }
@ -75,9 +69,7 @@
- (void)dealloc { - (void)dealloc {
delete fWind; delete fWind;
#if SK_SUPPORT_GPU
self.fGLContext = nil; self.fGLContext = nil;
#endif
self.fTitle = nil; self.fTitle = nil;
[super dealloc]; [super dealloc];
} }
@ -231,8 +223,8 @@ static SkKey raw2key(UInt32 raw)
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#if SK_SUPPORT_GPU
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
namespace { namespace {
CGLContextObj createGLContext(int msaaSampleCount) { CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor; GLint major, minor;
@ -275,25 +267,19 @@ CGLContextObj createGLContext(int msaaSampleCount) {
return ctx; return ctx;
} }
} }
#endif
- (void)viewDidMoveToWindow { - (void)viewDidMoveToWindow {
[super viewDidMoveToWindow]; [super viewDidMoveToWindow];
#if SK_SUPPORT_GPU
//Attaching view to fGLContext requires that the view to be part of a window, //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) //it must NOT be deferred or should have been on screen at least once)
if ([fGLContext view] != self && nil != self.window) { if ([fGLContext view] != self && nil != self.window) {
[fGLContext setView:self]; [fGLContext setView:self];
} }
#endif
} }
- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount { - (bool)attach:(SkOSWindow::SkBackEndTypes)attachType
#if SK_SUPPORT_GPU withMSAASampleCount:(int) sampleCount {
if (SkOSWindow::kNativeGL_BackEndType == attachType) {
[self setWantsLayer:NO];
self.layer = nil;
if (nil == fGLContext) { if (nil == fGLContext) {
CGLContextObj ctx = createGLContext(sampleCount); CGLContextObj ctx = createGLContext(sampleCount);
fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
@ -311,39 +297,16 @@ CGLContextObj createGLContext(int msaaSampleCount) {
glClearStencil(0); glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
return true; return true;
}
#endif
if (SkOSWindow::kNone_BackEndType == attachType) {
[self detach];
[self setLayer:[CALayer layer]];
[self setWantsLayer:YES];
return true;
}
return false;
} }
- (void)detach { - (void)detach {
#if SK_SUPPORT_GPU
[fGLContext release]; [fGLContext release];
fGLContext = nil; fGLContext = nil;
#endif
} }
#include "SkCGUtils.h"
- (void)present { - (void)present {
#if SK_SUPPORT_GPU
if (nil != fGLContext) { if (nil != fGLContext) {
[fGLContext flushBuffer]; [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 @end

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

@ -17,11 +17,11 @@
#import "SkEventNotifier.h" #import "SkEventNotifier.h"
#define kINVAL_NSVIEW_EventType "inval-nsview" #define kINVAL_NSVIEW_EventType "inval-nsview"
SK_COMPILE_ASSERT(SK_SUPPORT_GPU, not_implemented_for_non_gpu_build);
SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
fInvalEventIsPending = false; fInvalEventIsPending = false;
#if SK_SUPPORT_GPU
fGLContext = NULL; fGLContext = NULL;
#endif
fNotifier = [[SkEventNotifier alloc] init]; fNotifier = [[SkEventNotifier alloc] init];
} }
SkOSWindow::~SkOSWindow() { SkOSWindow::~SkOSWindow() {
@ -40,9 +40,7 @@ bool SkOSWindow::onEvent(const SkEvent& evt) {
fInvalEventIsPending = false; fInvalEventIsPending = false;
const SkIRect& r = this->getDirtyBounds(); const SkIRect& r = this->getDirtyBounds();
[(SkNSView*)fHWND postInvalWithRect:&r]; [(SkNSView*)fHWND postInvalWithRect:&r];
#if SK_SUPPORT_GPU
[(NSOpenGLContext*)fGLContext update]; [(NSOpenGLContext*)fGLContext update];
#endif
return true; return true;
} }
if ([(SkNSView*)fHWND onHandleEvent:evt]) { if ([(SkNSView*)fHWND onHandleEvent:evt]) {