Add width and height option to SampleApp

So we can benchmark with given width/height dimensions.

Bug: skia:
Change-Id: I881c9f054cdcecc3e0b2bfb600afd778e1c57d95
Reviewed-on: https://skia-review.googlesource.com/51246
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
This commit is contained in:
Yuqian Li 2017-09-27 13:25:36 -04:00 committed by Skia Commit-Bot
parent b268d23281
commit 6e3d9950e3
9 changed files with 76 additions and 28 deletions

View File

@ -13,6 +13,7 @@
class SkOSWindow : public SkWindow {
public:
SkOSWindow(void* hwnd, int w, int h);
SkOSWindow(void* hwnd);
~SkOSWindow();
void* getHWND() const { return fHWND; }
@ -48,6 +49,8 @@ protected:
virtual void onSetTitle(const char[]);
private:
void init(void* hwnd, int w, int h);
void* fHWND;
bool fInvalEventIsPending;
void* fNotifier;

View File

@ -26,6 +26,7 @@ struct SkUnixWindow {
class SkOSWindow : public SkWindow {
public:
SkOSWindow(void*);
SkOSWindow(void*, int width, int height);
~SkOSWindow() override;
void* getHWND() const { return (void*)fUnixWindow.fWin; }
@ -71,7 +72,8 @@ private:
// Forcefully closes the window. If a graceful shutdown is desired then call the public
// closeWindow method
void internalCloseWindow();
void initWindow(int newMSAASampleCount, AttachmentInfo* info);
void initWindow(int newMSAASampleCount, AttachmentInfo* info, int w, int h);
void init(int w, int h);
SkUnixWindow fUnixWindow;

View File

@ -26,6 +26,7 @@ public:
};
SkOSWindow(const void* winInit);
SkOSWindow(const void* winInit, int w, int h);
virtual ~SkOSWindow();
static bool PostEvent(SkEvent* evt, SkEventSinkID, SkMSec delay);
@ -87,6 +88,7 @@ private:
void* fHWND;
void doPaint(void* ctx);
void init(const void* winInit, int w, int h);
#if SK_SUPPORT_GPU
void* fHGLRC;

View File

@ -762,15 +762,15 @@ DEFINE_int32(backendTiles, 0, "Number of tiles in the experimental threaded back
DEFINE_int32(backendThreads, 0, "Number of threads in the experimental threaded backend.");
DEFINE_int32(measureMS, 0, "Number of miliseconds to measure the FPS before closing the SampleApp. "
"If it's 0, we won't measure the FPS or close SampleApp automatically.");
DEFINE_int32(width, 1024, "Width of the window");
DEFINE_int32(height, 768, "Height of the window");
#include "SkTaskGroup.h"
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager)
: INHERITED(hwnd)
: INHERITED(hwnd, FLAGS_width, FLAGS_height)
, fDevManager(nullptr) {
SkCommandLineFlags::Parse(argc, argv);
fCurrIndex = -1;
if (!FLAGS_pictureDir.isEmpty()) {
@ -2528,6 +2528,8 @@ static void test() {
// FIXME: this should be in a header
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
SkCommandLineFlags::Parse(argc, argv);
if (false) { // avoid bit rot, suppress warning
test();
}

View File

@ -27,6 +27,7 @@ class SkEvent;
@property (nonatomic, assign) id<SkNSViewOptionsDelegate> fOptionsDelegate;
- (id)initWithDefaults;
- (void)setNSViewSize:(NSSize)size;
- (void)setUpWindow;
- (void)resizeSkView:(NSSize)newSize;
- (void)setSkTitle:(const char*)title;

View File

@ -51,6 +51,13 @@ BOOL fRedrawRequestPending;
return self;
}
- (void)setNSViewSize:(NSSize)size {
NSWindow* w = [self window];
NSRect f;
f.size = size;
[w setFrame:f display:YES];
}
- (void)setUpWindow {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(backingPropertiesChanged:)
@ -98,7 +105,7 @@ BOOL fRedrawRequestPending;
if (oldBackingScaleFactor == newBackingScaleFactor) {
return;
}
// TODO: need a better way to force a refresh (that works).
// [fGLContext update] does not appear to update if the point size has not changed,
// even if the backing size has changed.
@ -220,7 +227,7 @@ static SkKey raw2key(UInt32 raw)
{ 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;
@ -230,7 +237,7 @@ static SkKey raw2key(UInt32 raw)
- (void)keyDown:(NSEvent *)event {
if (NULL == fWind)
return;
SkKey key = raw2key([event keyCode]);
if (kNONE_SkKey != key)
fWind->handleKey(key);
@ -243,7 +250,7 @@ static SkKey raw2key(UInt32 raw)
- (void)keyUp:(NSEvent *)event {
if (NULL == fWind)
return;
SkKey key = raw2key([event keyCode]);
if (kNONE_SkKey != key)
fWind->handleKeyUp(key);
@ -305,7 +312,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
- (void)mouseMoved:(NSEvent *)event {
NSPoint p = [event locationInWindow];
unsigned modi = convertNSModifiersToSk([event modifierFlags]);
if ([self mouse:p inRect:[self bounds]] && fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
#if RETINA_API_AVAILABLE
@ -320,7 +327,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
- (void)mouseUp:(NSEvent *)event {
NSPoint p = [event locationInWindow];
unsigned modi = convertNSModifiersToSk([event modifierFlags]);
if ([self mouse:p inRect:[self bounds]] && fWind) {
NSPoint loc = [self convertPoint:p fromView:nil];
#if RETINA_API_AVAILABLE
@ -338,7 +345,7 @@ static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
static CGLContextObj createGLContext(int msaaSampleCount) {
GLint major, minor;
CGLGetVersion(&major, &minor);
static const CGLPixelFormatAttribute attributes[] = {
kCGLPFAStencilSize, (CGLPixelFormatAttribute) 8,
kCGLPFAAccelerated,
@ -346,7 +353,7 @@ static CGLContextObj createGLContext(int msaaSampleCount) {
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
(CGLPixelFormatAttribute)0
};
CGLPixelFormatObj format;
GLint npix = 0;
if (msaaSampleCount > 0) {
@ -369,7 +376,7 @@ static CGLContextObj createGLContext(int msaaSampleCount) {
CGLContextObj ctx;
CGLCreateContext(format, NULL, &ctx);
CGLDestroyPixelFormat(format);
static const GLint interval = 1;
CGLSetParameter(ctx, kCGLCPSwapInterval, &interval);
CGLSetCurrentContext(ctx);
@ -378,9 +385,9 @@ static CGLContextObj createGLContext(int msaaSampleCount) {
- (void)viewDidMoveToWindow {
[super viewDidMoveToWindow];
//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)
if ([fGLContext view] != self && nil != self.window) {
[fGLContext setView:self];

View File

@ -14,13 +14,26 @@
#import "SkEventNotifier.h"
#define kINVAL_NSVIEW_EventType "inval-nsview"
static constexpr int DEFAULT_W = 1024;
static constexpr int DEFAULT_H = 768;
static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");
SkOSWindow::SkOSWindow(void* hwnd, int w, int h): fHWND(hwnd) {
this->init(hwnd, w, h);
}
SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
this->init(hWnd, DEFAULT_W, DEFAULT_H);
}
void SkOSWindow::init(void* hwnd, int w, int h) {
fInvalEventIsPending = false;
fGLContext = NULL;
fNotifier = [[SkEventNotifier alloc] init];
[(SkNSView*)hwnd setNSViewSize:NSMakeSize(w, h)];
}
SkOSWindow::~SkOSWindow() {
[(SkEventNotifier*)fNotifier release];
}

View File

@ -24,20 +24,30 @@ extern "C" {
#include "keysym2ucs.h"
}
const int WIDTH = 500;
const int HEIGHT = 500;
const int WIDTH = 1024;
const int HEIGHT = 768;
// Determine which events to listen for.
const long EVENT_MASK = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask
|ExposureMask|PointerMotionMask|KeyPressMask|KeyReleaseMask;
void SkOSWindow::init(int w, int h) {
fUnixWindow.fDisplay = nullptr;
fUnixWindow.fGLContext = nullptr;
this->initWindow(0, nullptr, w, h);
this->resize(w, h);
}
SkOSWindow::SkOSWindow(void*)
: fVi(nullptr)
, fMSAASampleCount(0) {
fUnixWindow.fDisplay = nullptr;
fUnixWindow.fGLContext = nullptr;
this->initWindow(0, nullptr);
this->resize(WIDTH, HEIGHT);
this->init(WIDTH, HEIGHT);
}
SkOSWindow::SkOSWindow(void*, int width, int height)
: fVi(nullptr)
, fMSAASampleCount(0) {
this->init(width, height);
}
SkOSWindow::~SkOSWindow() {
@ -58,7 +68,7 @@ void SkOSWindow::internalCloseWindow() {
}
}
void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info) {
void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info, int w, int h) {
if (fMSAASampleCount != requestedMSAASampleCount) {
this->internalCloseWindow();
}
@ -123,7 +133,7 @@ void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info)
fUnixWindow.fWin = XCreateWindow(dsp,
RootWindow(dsp, fVi->screen),
0, 0, // x, y
WIDTH, HEIGHT,
w, h,
0, // border width
fVi->depth,
InputOutput,
@ -139,7 +149,7 @@ void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info)
fUnixWindow.fWin = XCreateSimpleWindow(dsp,
DefaultRootWindow(dsp),
0, 0, // x, y
WIDTH, HEIGHT,
w, h,
0, // border width
0, // border value
0); // background value
@ -350,7 +360,7 @@ static void glXSwapInterval(Display* dsp, GLXDrawable drawable, int interval) {
bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, bool deepColor,
AttachmentInfo* info) {
this->initWindow(msaaSampleCount, info);
this->initWindow(msaaSampleCount, info, WIDTH, HEIGHT);
if (nullptr == fUnixWindow.fDisplay) {
return false;

View File

@ -29,8 +29,8 @@
#include <EGL/eglext.h>
#endif // SK_ANGLE
const int kDefaultWindowWidth = 500;
const int kDefaultWindowHeight = 500;
const int kDefaultWindowWidth = 1024;
const int kDefaultWindowHeight = 768;
#define GL_CALL(IFACE, X) \
SkASSERT(IFACE); \
@ -48,10 +48,18 @@ void post_skwinevent(HWND hwnd)
SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap;
SkOSWindow::SkOSWindow(const void* winInit) {
this->init(winInit, kDefaultWindowWidth, kDefaultWindowHeight);
}
SkOSWindow::SkOSWindow(const void* winInit, int w, int h) {
this->init(winInit, w, h);
}
void SkOSWindow::init(const void* winInit, int w, int h) {
fWinInit = *(const WindowInit*)winInit;
fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, kDefaultWindowWidth, kDefaultWindowHeight, NULL, NULL,
CW_USEDEFAULT, 0, w, h, NULL, NULL,
fWinInit.fInstance, NULL);
gHwndToOSWindowMap.set(fHWND, this);
#if SK_SUPPORT_GPU