SkOSWindow(void* hwnd);
~SkOSWindow();
void* getHWND() const { return fHWND; }
-
+
virtual bool onDispatchClick(int x, int y, Click::State state,
void* owner);
-
enum SkBackEndTypes {
kNone_BackEndType,
kNativeGL_BackEndType,
};
void detach();
- bool attach(SkBackEndTypes attachType);
+ bool attach(SkBackEndTypes attachType, int msaaSampleCount);
void present();
-
+
protected:
// overrides from SkEventSink
virtual bool onEvent(const SkEvent& evt);
kNativeGL_BackEndType,
};
- bool attach(SkBackEndTypes attachType);
+ bool attach(SkBackEndTypes attachType, int msaaSampleCount);
void detach();
void present();
kD3D9_BackEndType
};
- bool attach(SkBackEndTypes attachType);
+ bool attach(SkBackEndTypes attachType, int msaaSampleCount);
void detach();
void present();
SkBackEndTypes fAttached;
- bool attachGL();
+ bool attachGL(int msaaSampleCount);
void detachGL();
void presentGL();
#if SK_ANGLE
bool attachANGLE();
- void detachANGLE();
+ void detachANGLE(int msaaSampleCount);
void presentANGLE();
#endif
: fCurContext(NULL)
, fCurIntf(NULL)
, fCurRenderTarget(NULL)
- , fBackend(kNone_BackEndType) {
+ , fBackend(kNone_BackEndType)
+ , fMSAASampleCount(0) {
}
virtual ~DefaultDeviceManager() {
SkSafeUnref(fCurRenderTarget);
}
- virtual void setUpBackend(SampleWindow* win) {
+ virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) {
SkASSERT(kNone_BackEndType == fBackend);
fBackend = kNone_BackEndType;
break;
}
- bool result = win->attach(fBackend);
+ bool result = win->attach(fBackend, msaaSampleCount);
if (!result) {
SkDebugf("Failed to initialize GL");
return;
}
+ fMSAASampleCount = msaaSampleCount;
SkASSERT(NULL == fCurIntf);
switch (win->getDeviceType()) {
virtual void windowSizeChanged(SampleWindow* win) {
if (fCurContext) {
- win->attach(fBackend);
+ win->attach(fBackend, fMSAASampleCount);
GrPlatformRenderTargetDesc desc;
desc.fWidth = SkScalarRound(win->width());
GrRenderTarget* fCurRenderTarget;
SkOSWindow::SkBackEndTypes fBackend;
+ int fMSAASampleCount;
typedef SampleWindow::DeviceManager INHERITED;
};
}
static void usage(const char * argv0) {
- SkDebugf("%s [--slide sampleName] [-i resourcePath]\n", argv0);
+ SkDebugf("%s [--slide sampleName] [-i resourcePath] [-msaa=<samplecnt>]\n", argv0);
SkDebugf(" sampleName: sample at which to start.\n");
SkDebugf(" resourcePath: directory that stores image resources.\n");
+ SkDebugf(" msaa: request multisampling with the given sample count.\n");
}
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) : INHERITED(hwnd) {
const char* resourcePath = NULL;
fCurrIndex = -1;
+ fMSAASampleCount = 0;
const char* const commandName = argv[0];
char* const* stop = argv + argc;
fprintf(stderr, "Unknown sample \"%s\"\n", *argv);
}
}
- }
+ } else if (1 == sscanf(*argv, "--msaa=%d", &fMSAASampleCount) &&
+ fMSAASampleCount >= 0) {
+ }
else {
usage(commandName);
}
devManager->ref();
fDevManager = devManager;
}
- fDevManager->setUpBackend(this);
+ fDevManager->setUpBackend(this, fMSAASampleCount);
// If another constructor set our dimensions, ensure that our
// onSizeChange gets called.
fDeviceType = type;
- fDevManager->setUpBackend(this);
+ fDevManager->setUpBackend(this, fMSAASampleCount);
this->updateTitle();
this->inval(NULL);
*/
class DeviceManager : public SkRefCnt {
public:
- virtual void setUpBackend(SampleWindow* win) = 0;
+ virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
virtual void tearDownBackend(SampleWindow* win) = 0;
SkOSMenu::TriState fHintingState;
unsigned fFlipAxis;
+ int fMSAASampleCount;
+
int fScrollTestX, fScrollTestY;
SkScalar fZoomCenterX, fZoomCenterY;
#include "SkTLazy.h"
#include "SkTrace.h"
-#define DEFER_TEXT_RENDERING 1
+#define DEFER_TEXT_RENDERING 0
-#define DEFER_PATHS 1
+#define DEFER_PATHS 0
-#define BATCH_RECT_TO_RECT (1 && !GR_STATIC_RECT_VB)
+#define BATCH_RECT_TO_RECT (0 && !GR_STATIC_RECT_VB)
#define MAX_BLUR_SIGMA 4.0f
GrAssert(NULL == fDrawBufferVBAllocPool);
GrAssert(NULL == fDrawBufferIBAllocPool);
-#if DEFER_TEXT_RENDERING || BATCH_RECT_TO_RECT
fDrawBufferVBAllocPool =
new GrVertexBufferAllocPool(fGpu, false,
DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
fDrawBuffer = new GrInOrderDrawBuffer(fGpu,
fDrawBufferVBAllocPool,
fDrawBufferIBAllocPool);
-#endif
-
-#if BATCH_RECT_TO_RECT
fDrawBuffer->setQuadIndexBuffer(this->getQuadIndexBuffer());
-#endif
fDrawBuffer->setAutoFlushTarget(fGpu);
fDrawBuffer->setDrawState(fDrawState);
}
// we prefer smooth lines over multisampled lines
// msaa should be disabled if drawing smooth lines.
+ bool handledMSAA = false;
if (GrIsPrimTypeLines(type)) {
bool smooth = this->willUseHWAALines();
if (!fHWAAState.fSmoothLineEnabled && smooth) {
GL_CALL(Disable(GR_GL_LINE_SMOOTH));
fHWAAState.fSmoothLineEnabled = false;
}
- if (rt->isMultisampled() &&
- fHWAAState.fMSAAEnabled) {
+ if (smooth && rt->isMultisampled() && fHWAAState.fMSAAEnabled) {
GL_CALL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
+ handledMSAA = true;
}
- } else if (rt->isMultisampled() &&
- this->getDrawState().isHWAntialiasState() !=
- fHWAAState.fMSAAEnabled) {
+ }
+ if (!handledMSAA && rt->isMultisampled() &&
+ this->getDrawState().isHWAntialiasState() !=
+ fHWAAState.fMSAAEnabled) {
if (fHWAAState.fMSAAEnabled) {
GL_CALL(Disable(GR_GL_MULTISAMPLE));
fHWAAState.fMSAAEnabled = false;
- (void)postInvalWithRect:(const SkIRect*)rectOrNil;
- (BOOL)onHandleEvent:(const SkEvent&)event;
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType;
+- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount;
- (void)detach;
- (void)present;
@end
///////////////////////////////////////////////////////////////////////////////
#include <OpenGL/OpenGL.h>
-CGLContextObj createGLContext() {
+namespace {
+CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor;
CGLGetVersion(&major, &minor);
- const CGLPixelFormatAttribute attributes[] = {
+ static const CGLPixelFormatAttribute attributes[] = {
kCGLPFAStencilSize, (CGLPixelFormatAttribute)8,
-#if USE_MSAA
- kCGLPFASampleBuffers, 1,
- kCGLPFAMultisample,
- kCGLPFASamples, 8,
-#endif
kCGLPFAAccelerated,
kCGLPFADoubleBuffer,
(CGLPixelFormatAttribute)0
};
CGLPixelFormatObj format;
- GLint npix;
- CGLChoosePixelFormat(attributes, &format, &npix);
+ GLint npix = 0;
+ if (msaaSampleCount > 0) {
+ static int kAttributeCount = SK_ARRAY_COUNT(attributes);
+ CGLPixelFormatAttribute msaaAttributes[kAttributeCount + 5];
+ memcpy(msaaAttributes, attributes, sizeof(attributes));
+ SkASSERT(0 == msaaAttributes[kAttributeCount - 1]);
+ msaaAttributes[kAttributeCount - 1] = kCGLPFASampleBuffers;
+ msaaAttributes[kAttributeCount + 0] = (CGLPixelFormatAttribute)1;
+ msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample;
+ msaaAttributes[kAttributeCount + 2] = kCGLPFASamples;
+ msaaAttributes[kAttributeCount + 3] = (CGLPixelFormatAttribute)msaaSampleCount;
+ msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0;
+ CGLChoosePixelFormat(msaaAttributes, &format, &npix);
+ }
+ if (!npix) {
+ CGLChoosePixelFormat(attributes, &format, &npix);
+ }
CGLContextObj ctx;
CGLCreateContext(format, NULL, &ctx);
CGLSetCurrentContext(ctx);
return ctx;
}
+}
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
[fGLContext setView:self];
}
}
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType {
+- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount {
if (nil == fGLContext) {
- fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:createGLContext()];
+ CGLContextObj ctx = createGLContext(sampleCount);
+ fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
+ CGLReleaseContext(ctx);
if (NULL == fGLContext) {
return false;
}
+ [fGLContext setView:self];
}
[fGLContext makeCurrentContext];
}
- (void)detach {
- [fGLContext clearDrawable];
+ [fGLContext release];
+ fGLContext = nil;
}
- (void)present {
- [fGLContext flushBuffer];
+ if (nil != fGLContext) {
+ [fGLContext flushBuffer];
+ }
}
@end
[(SkNSView*)fHWND onUpdateMenu:menu];
}
-bool SkOSWindow::attach(SkBackEndTypes attachType) {
- return [(SkNSView*)fHWND attach:attachType];
+bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount) {
+ return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount];
}
void SkOSWindow::detach() {
}
-bool SkOSWindow::attach(SkBackEndTypes /* attachType */)
+bool SkOSWindow::attach(SkBackEndTypes /* attachType */, int msaaSampleCount)
{
if (fGLAttached) return true;
Display* dsp = fUnixWindow.fDisplay;
#define USE_MSAA 0
-HGLRC create_gl(HWND hwnd) {
+HGLRC create_gl(HWND hwnd, int msaaSampleCount) {
HDC dc = GetDC(hwnd);
int format = 0;
- GLint iattrs[] = {
+ static const GLint iAttrs[] = {
SK_WGL_DRAW_TO_WINDOW, TRUE,
SK_WGL_DOUBLE_BUFFER, TRUE,
SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
SK_WGL_COLOR_BITS, 24,
SK_WGL_ALPHA_BITS, 8,
SK_WGL_STENCIL_BITS, 8,
-
- // these must be kept last
- SK_WGL_SAMPLE_BUFFERS, TRUE,
- SK_WGL_SAMPLES, 0,
- 0,0
+ 0, 0
};
- static const int kSampleBuffersValueIdx = SK_ARRAY_COUNT(iattrs) - 5;
- static const int kSamplesValueIdx = SK_ARRAY_COUNT(iattrs) - 3;
- if (USE_MSAA && extensions.hasExtension(dc, "WGL_ARB_multisample")) {
- for (int samples = 16; samples > 1; --samples) {
-
- iattrs[kSamplesValueIdx] = samples;
- GLfloat fattrs[] = {0,0};
- GLuint num;
- int formats[64];
- extensions.choosePixelFormat(dc, iattrs, fattrs, 64, formats, &num);
- num = min(num,64);
- for (GLuint i = 0; i < num; ++i) {
- DescribePixelFormat(dc, formats[i], sizeof(pfd), &pfd);
- if (SetPixelFormat(dc, formats[i], &pfd)) {
- format = formats[i];
- break;
- }
+ GLfloat fAttrs[] = {0, 0};
+
+ if (msaaSampleCount > 0 &&
+ extensions.hasExtension(dc, "WGL_ARB_multisample")) {
+ static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
+ GLint msaaIAttrs[kIAttrsCount + 4];
+ memcpy(msaaIAttrs, iAttrs, sizeof(GLint) * kIAttrsCount);
+ SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
+ 0 == msaaIAttrs[kIAttrsCount - 1]);
+ msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
+ msaaIAttrs[kIAttrsCount - 1] = TRUE;
+ msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
+ msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
+ msaaIAttrs[kIAttrsCount + 2] = 0;
+ msaaIAttrs[kIAttrsCount + 3] = 0;
+ GLuint num;
+ int formats[64];
+ extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
+ num = min(num,64);
+ for (GLuint i = 0; i < num; ++i) {
+ DescribePixelFormat(dc, formats[i], sizeof(pfd), &pfd);
+ if (SetPixelFormat(dc, formats[i], &pfd)) {
+ format = formats[i];
+ break;
}
}
}
if (0 == format) {
- iattrs[kSampleBuffersValueIdx-1] = iattrs[kSampleBuffersValueIdx] = 0;
- iattrs[kSamplesValueIdx-1] = iattrs[kSamplesValueIdx] = 0;
- GLfloat fattrs[] = {0,0};
GLuint num;
- extensions.choosePixelFormat(dc, iattrs, fattrs, 1, &format, &num);
+ extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num);
DescribePixelFormat(dc, format, sizeof(pfd), &pfd);
BOOL set = SetPixelFormat(dc, format, &pfd);
SkASSERT(TRUE == set);
return glrc;
}
-bool SkOSWindow::attachGL() {
+bool SkOSWindow::attachGL(int msaaSampleCount) {
if (NULL == fHGLRC) {
- fHGLRC = create_gl((HWND)fHWND);
+ fHGLRC = create_gl((HWND)fHWND, msaaSampleCount);
if (NULL == fHGLRC) {
return false;
}
}
#if SK_ANGLE
-bool create_ANGLE(EGLNativeWindowType hWnd, EGLDisplay* eglDisplay,
- EGLContext* eglContext, EGLSurface* eglSurface) {
- EGLint contextAttribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
+bool create_ANGLE(EGLNativeWindowType hWnd,
+ int msaaSampleCount,
+ angle::EGLDisplay* eglDisplay,
+ angle::EGLContext* eglContext,
+ angle::EGLSurface* eglSurface) {
+ static EGLint contextAttribs[] = {
EGL_NONE, EGL_NONE
};
- EGLint configAttribList[] = {
+ static EGLint configAttribList[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_STENCIL_SIZE, 8,
EGL_NONE
};
- EGLint surfaceAttribList[] = {
+ static EGLint surfaceAttribList[] = {
EGL_NONE, EGL_NONE
};
// Choose config
EGLConfig config;
- if (!eglChooseConfig(display, configAttribList,
- &config, 1, &numConfigs)) {
- return false;
+ bool foundConfig = false;
+ if (msaaSampleCount) {
+ static int kConfigAttribListCnt = SK_ARRAY_COUNT(configAttribList);
+ EGLint msaaConfigAttribList[kConfigAttribListCnt + 4];
+ memcpy(msaaConfigAttribList,
+ configAttribList,
+ sizeof(configAttribList));
+ SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]);
+ msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS;
+ msaaConfigAttribList[kConfigAttribListCnt + 0] = 1;
+ msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES;
+ msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaCount;
+ msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE;
+ if (eglChooseConfig(display, configAttribList,
+ &config, 1, &numConfigs)) {
+ if (numConfigs > 0) {
+ foundConfig = true;
+ }
+ }
+ }
+ if (!foundConfig) {
+ if (!eglChooseConfig(display, configAttribList,
+ &config, 1, &numConfigs)) {
+ return false;
+ }
}
// Create a surface
return true;
}
-bool SkOSWindow::attachANGLE() {
+bool SkOSWindow::attachANGLE(int msaaSampleCount) {
if (EGL_NO_DISPLAY == fDisplay) {
bool bResult = create_ANGLE((HWND)fHWND, &fDisplay, &fContext, &fSurface);
if (false == bResult) {
}
// return true on success
-bool SkOSWindow::attach(SkBackEndTypes attachType) {
+bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) {
// attach doubles as "windowResize" so we need to allo
// already bound states to pass through again
// nothing to do
break;
case kNativeGL_BackEndType:
- result = attachGL();
+ result = attachGL(msaaSampleCount);
break;
#if SK_ANGLE
case kANGLE_BackEndType:
- result = attachANGLE();
+ result = attachANGLE(msaaSampleCount);
break;
#endif
case kD3D9_BackEndType: