2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-03 17:53:59 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SampleApp.h"
|
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "OverView.h"
|
2014-07-18 17:58:56 +00:00
|
|
|
#include "Resources.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SampleCode.h"
|
2015-02-02 20:55:02 +00:00
|
|
|
#include "SkAnimTimer.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkCanvas.h"
|
2016-10-18 17:02:51 +00:00
|
|
|
#include "SkColorSpace_XYZ.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
2017-02-22 19:00:42 +00:00
|
|
|
#include "SkCommonFlagsPathRenderer.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkData.h"
|
2014-10-08 18:10:51 +00:00
|
|
|
#include "SkDocument.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkGraphics.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkOSFile.h"
|
2016-11-07 23:05:29 +00:00
|
|
|
#include "SkOSPath.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPaint.h"
|
2015-06-15 14:07:32 +00:00
|
|
|
#include "SkPaintFilterCanvas.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2016-04-20 16:20:46 +00:00
|
|
|
#include "SkPM4fPriv.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkStream.h"
|
2014-05-30 15:06:24 +00:00
|
|
|
#include "SkSurface.h"
|
2015-12-10 18:44:13 +00:00
|
|
|
#include "SkTemplates.h"
|
2013-07-11 14:28:04 +00:00
|
|
|
#include "SkTSort.h"
|
2009-11-23 21:07:51 +00:00
|
|
|
#include "SkTime.h"
|
2011-03-24 18:35:50 +00:00
|
|
|
#include "SkTypeface.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkWindow.h"
|
|
|
|
#include "sk_tool_utils.h"
|
2016-10-04 18:23:22 +00:00
|
|
|
#include "SkScan.h"
|
2016-12-12 15:02:12 +00:00
|
|
|
#include "SkClipOpPriv.h"
|
2017-04-03 14:52:48 +00:00
|
|
|
#include "SkThreadedBMPDevice.h"
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
#include "SkReadBuffer.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2016-09-30 19:26:47 +00:00
|
|
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
#include "SkCGUtils.h"
|
|
|
|
#endif
|
|
|
|
|
2017-03-15 01:10:42 +00:00
|
|
|
#define PICTURE_MEANS_PIPE false
|
|
|
|
#define SERIALIZE_PICTURE true
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-03-31 01:56:19 +00:00
|
|
|
# include "gl/GrGLInterface.h"
|
|
|
|
# include "gl/GrGLUtil.h"
|
|
|
|
# include "GrContext.h"
|
2016-04-22 17:57:16 +00:00
|
|
|
# include "SkGr.h"
|
2016-03-31 01:56:19 +00:00
|
|
|
# if SK_ANGLE
|
2016-03-31 17:59:06 +00:00
|
|
|
# include "gl/angle/GLTestContext_angle.h"
|
2016-03-31 01:56:19 +00:00
|
|
|
# endif
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
|
|
|
class GrContext;
|
|
|
|
#endif
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2016-09-29 21:37:02 +00:00
|
|
|
enum OutputColorSpace {
|
|
|
|
kLegacy_OutputColorSpace,
|
|
|
|
kSRGB_OutputColorSpace,
|
2016-12-02 17:10:36 +00:00
|
|
|
kNarrow_OutputColorSpace,
|
2016-09-29 21:37:02 +00:00
|
|
|
kMonitor_OutputColorSpace,
|
|
|
|
};
|
|
|
|
|
2016-02-15 15:48:35 +00:00
|
|
|
const struct {
|
|
|
|
SkColorType fColorType;
|
2016-09-29 21:37:02 +00:00
|
|
|
OutputColorSpace fColorSpace;
|
2016-02-15 15:48:35 +00:00
|
|
|
const char* fName;
|
|
|
|
} gConfig[] = {
|
2016-09-29 21:37:02 +00:00
|
|
|
{ kN32_SkColorType, kLegacy_OutputColorSpace, "L32" },
|
|
|
|
{ kN32_SkColorType, kSRGB_OutputColorSpace, "S32" },
|
|
|
|
{ kRGBA_F16_SkColorType, kSRGB_OutputColorSpace, "F16" },
|
2016-12-02 17:10:36 +00:00
|
|
|
{ kRGBA_F16_SkColorType, kNarrow_OutputColorSpace, "F16 Narrow" },
|
2016-09-29 21:37:02 +00:00
|
|
|
{ kRGBA_F16_SkColorType, kMonitor_OutputColorSpace, "F16 Device" },
|
2016-02-15 15:48:35 +00:00
|
|
|
};
|
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
// Should be 3x + 1
|
|
|
|
#define kMaxFatBitsScale 28
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
extern SampleView* CreateSamplePictFileView(const char filename[]);
|
|
|
|
|
|
|
|
class PictFileFactory : public SkViewFactory {
|
|
|
|
SkString fFilename;
|
|
|
|
public:
|
|
|
|
PictFileFactory(const SkString& filename) : fFilename(filename) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView* operator() () const override {
|
2012-06-04 12:05:43 +00:00
|
|
|
return CreateSamplePictFileView(fFilename.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-27 18:32:29 +00:00
|
|
|
extern SampleView* CreateSamplePathFinderView(const char filename[]);
|
|
|
|
|
|
|
|
class PathFinderFactory : public SkViewFactory {
|
|
|
|
SkString fFilename;
|
|
|
|
public:
|
|
|
|
PathFinderFactory(const SkString& filename) : fFilename(filename) {}
|
|
|
|
SkView* operator() () const override {
|
|
|
|
return CreateSamplePathFinderView(fFilename.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-15 14:48:47 +00:00
|
|
|
extern SampleView* CreateSampleSVGFileView(const SkString& filename);
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
class SVGFileFactory : public SkViewFactory {
|
|
|
|
SkString fFilename;
|
|
|
|
public:
|
|
|
|
SVGFileFactory(const SkString& filename) : fFilename(filename) {}
|
|
|
|
SkView* operator() () const override {
|
2016-08-15 14:48:47 +00:00
|
|
|
return CreateSampleSVGFileView(fFilename);
|
2016-07-27 01:46:34 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
extern SampleView* CreateSamplePdfFileViewer(const char filename[]);
|
|
|
|
|
|
|
|
class PdfFileViewerFactory : public SkViewFactory {
|
|
|
|
SkString fFilename;
|
|
|
|
public:
|
|
|
|
PdfFileViewerFactory(const SkString& filename) : fFilename(filename) {}
|
2015-03-26 01:17:31 +00:00
|
|
|
SkView* operator() () const override {
|
2013-07-11 14:28:04 +00:00
|
|
|
return CreateSamplePdfFileViewer(fFilename.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
|
|
|
|
2016-06-14 16:43:52 +00:00
|
|
|
#if SK_ANGLE
|
2012-04-02 19:24:21 +00:00
|
|
|
//#define DEFAULT_TO_ANGLE 1
|
|
|
|
#else
|
2013-09-09 15:36:26 +00:00
|
|
|
#define DEFAULT_TO_GPU 0 // if 1 default rendering is on GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
#endif
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#define ANIMATING_EVENTTYPE "nextSample"
|
2013-05-29 19:22:20 +00:00
|
|
|
#define ANIMATING_DELAY 250
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
#ifdef SK_DEBUG
|
2011-05-18 20:10:31 +00:00
|
|
|
#define FPS_REPEAT_MULTIPLIER 1
|
2011-04-22 01:59:09 +00:00
|
|
|
#else
|
2011-05-18 20:10:31 +00:00
|
|
|
#define FPS_REPEAT_MULTIPLIER 10
|
2011-04-22 01:59:09 +00:00
|
|
|
#endif
|
2011-05-18 20:10:31 +00:00
|
|
|
#define FPS_REPEAT_COUNT (10 * FPS_REPEAT_MULTIPLIER)
|
2011-04-22 01:59:09 +00:00
|
|
|
|
2011-07-06 13:59:47 +00:00
|
|
|
static SampleWindow* gSampleWindow;
|
|
|
|
|
2012-11-15 15:56:38 +00:00
|
|
|
static bool gShowGMBounds;
|
|
|
|
|
2013-12-11 17:05:23 +00:00
|
|
|
static void post_event_to_sink(SkEvent* evt, SkEventSink* sink) {
|
2011-11-08 15:18:10 +00:00
|
|
|
evt->setTargetID(sink->getSinkID())->post();
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
static SkAnimTimer gAnimTimer;
|
|
|
|
|
2011-12-27 22:33:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const char* skip_until(const char* str, const char* skip) {
|
|
|
|
if (!str) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2011-12-27 22:33:50 +00:00
|
|
|
}
|
|
|
|
return strstr(str, skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* skip_past(const char* str, const char* skip) {
|
|
|
|
const char* found = skip_until(str, skip);
|
|
|
|
if (!found) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2011-12-27 22:33:50 +00:00
|
|
|
}
|
|
|
|
return found + strlen(skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* gPrefFileName = "sampleapp_prefs.txt";
|
|
|
|
|
2011-12-28 15:13:41 +00:00
|
|
|
static bool readTitleFromPrefs(SkString* title) {
|
2011-12-27 22:33:50 +00:00
|
|
|
SkFILEStream stream(gPrefFileName);
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-27 13:42:58 +00:00
|
|
|
size_t len = stream.getLength();
|
2011-12-27 22:33:50 +00:00
|
|
|
SkString data(len);
|
|
|
|
stream.read(data.writable_str(), len);
|
|
|
|
const char* s = data.c_str();
|
|
|
|
|
|
|
|
s = skip_past(s, "curr-slide-title");
|
|
|
|
s = skip_past(s, "=");
|
|
|
|
s = skip_past(s, "\"");
|
|
|
|
const char* stop = skip_until(s, "\"");
|
|
|
|
if (stop > s) {
|
|
|
|
title->set(s, stop - s);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-12-28 15:13:41 +00:00
|
|
|
static void writeTitleToPrefs(const char* title) {
|
2011-12-27 22:33:50 +00:00
|
|
|
SkFILEWStream stream(gPrefFileName);
|
|
|
|
SkString data;
|
|
|
|
data.printf("curr-slide-title = \"%s\"\n", title);
|
|
|
|
stream.write(data.c_str(), data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
|
|
|
|
public:
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
DefaultDeviceManager() {
|
|
|
|
#if SK_SUPPORT_GPU
|
2015-08-27 14:41:13 +00:00
|
|
|
fCurContext = nullptr;
|
|
|
|
fCurIntf = nullptr;
|
2012-08-02 14:03:32 +00:00
|
|
|
fMSAASampleCount = 0;
|
2016-05-05 19:24:31 +00:00
|
|
|
fDeepColor = false;
|
|
|
|
fActualColorBits = 0;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
|
|
|
fBackend = kNone_BackEndType;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~DefaultDeviceManager() override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
SkSafeUnref(fCurIntf);
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2017-02-22 19:00:42 +00:00
|
|
|
void setUpBackend(SampleWindow* win, const BackendOptions& backendOptions) override {
|
2012-04-02 19:24:21 +00:00
|
|
|
SkASSERT(kNone_BackEndType == fBackend);
|
|
|
|
|
|
|
|
fBackend = kNone_BackEndType;
|
2012-03-28 16:19:11 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
switch (win->getDeviceType()) {
|
2015-05-05 19:14:45 +00:00
|
|
|
case kRaster_DeviceType: // fallthrough
|
2012-04-02 19:24:21 +00:00
|
|
|
case kGPU_DeviceType:
|
|
|
|
// all these guys use the native backend
|
|
|
|
fBackend = kNativeGL_BackEndType;
|
|
|
|
break;
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
2012-04-02 19:24:21 +00:00
|
|
|
case kANGLE_DeviceType:
|
|
|
|
// ANGLE is really the only odd man out
|
|
|
|
fBackend = kANGLE_BackEndType;
|
|
|
|
break;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
2012-04-02 19:24:21 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2012-03-28 16:19:11 +00:00
|
|
|
}
|
2013-03-05 20:06:05 +00:00
|
|
|
AttachmentInfo attachmentInfo;
|
2017-02-22 19:00:42 +00:00
|
|
|
bool result = win->attach(fBackend, backendOptions.fMSAASampleCount,
|
|
|
|
backendOptions.fDeepColor, &attachmentInfo);
|
2012-03-28 16:19:11 +00:00
|
|
|
if (!result) {
|
2011-10-27 20:44:19 +00:00
|
|
|
SkDebugf("Failed to initialize GL");
|
2012-04-02 19:24:21 +00:00
|
|
|
return;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
2017-02-22 19:00:42 +00:00
|
|
|
fMSAASampleCount = backendOptions.fMSAASampleCount;
|
|
|
|
fDeepColor = backendOptions.fDeepColor;
|
2016-05-05 19:24:31 +00:00
|
|
|
// Assume that we have at least 24-bit output, for backends that don't supply this data
|
|
|
|
fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24);
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fCurIntf);
|
2012-04-02 19:24:21 +00:00
|
|
|
switch (win->getDeviceType()) {
|
2015-05-05 19:14:45 +00:00
|
|
|
case kRaster_DeviceType: // fallthrough
|
2012-04-02 19:24:21 +00:00
|
|
|
case kGPU_DeviceType:
|
|
|
|
// all these guys use the native interface
|
2017-02-22 19:00:42 +00:00
|
|
|
fCurIntf = GrGLCreateNativeInterface();
|
2012-04-02 19:24:21 +00:00
|
|
|
break;
|
2012-03-28 16:19:11 +00:00
|
|
|
#if SK_ANGLE
|
2012-04-02 19:24:21 +00:00
|
|
|
case kANGLE_DeviceType:
|
2017-02-22 19:00:42 +00:00
|
|
|
fCurIntf = sk_gpu_test::CreateANGLEGLInterface();
|
2012-04-02 19:24:21 +00:00
|
|
|
break;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
2012-04-02 19:24:21 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2011-09-16 18:51:57 +00:00
|
|
|
}
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fCurContext);
|
2017-02-22 19:00:42 +00:00
|
|
|
fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf,
|
|
|
|
backendOptions.fGrContextOptions);
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == fCurContext || nullptr == fCurIntf) {
|
2012-04-02 19:24:21 +00:00
|
|
|
// We need some context and interface to see results
|
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
SkSafeUnref(fCurIntf);
|
2015-08-27 14:41:13 +00:00
|
|
|
fCurContext = nullptr;
|
|
|
|
fCurIntf = nullptr;
|
2011-07-14 14:30:46 +00:00
|
|
|
SkDebugf("Failed to setup 3D");
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2016-03-16 20:53:35 +00:00
|
|
|
win->release();
|
2011-10-27 20:44:19 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2016-07-28 22:17:34 +00:00
|
|
|
// call windowSizeChanged to create the gpu-backed Surface
|
2012-08-02 14:03:32 +00:00
|
|
|
this->windowSizeChanged(win);
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void tearDownBackend(SampleWindow *win) override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-10-30 18:29:08 +00:00
|
|
|
if (fCurContext) {
|
|
|
|
// in case we have outstanding refs to this guy (lua?)
|
|
|
|
fCurContext->abandonContext();
|
|
|
|
fCurContext->unref();
|
2015-08-27 14:41:13 +00:00
|
|
|
fCurContext = nullptr;
|
2014-10-30 18:29:08 +00:00
|
|
|
}
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
SkSafeUnref(fCurIntf);
|
2015-08-27 14:41:13 +00:00
|
|
|
fCurIntf = nullptr;
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2016-07-28 22:17:34 +00:00
|
|
|
fGpuSurface = nullptr;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2016-03-16 20:53:35 +00:00
|
|
|
win->release();
|
2012-04-10 15:56:29 +00:00
|
|
|
fBackend = kNone_BackEndType;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 22:17:34 +00:00
|
|
|
sk_sp<SkSurface> makeSurface(SampleWindow::DeviceType dType, SampleWindow* win) override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2014-09-05 20:34:00 +00:00
|
|
|
if (IsGpuDeviceType(dType) && fCurContext) {
|
2014-10-06 19:29:56 +00:00
|
|
|
SkSurfaceProps props(win->getSurfaceProps());
|
2016-05-05 19:24:31 +00:00
|
|
|
if (kRGBA_F16_SkColorType == win->info().colorType() || fActualColorBits > 24) {
|
|
|
|
// If we're rendering to F16, we need an off-screen surface - the current render
|
|
|
|
// target is most likely the wrong format.
|
|
|
|
//
|
|
|
|
// If we're using a deep (10-bit or higher) surface, we probably need an off-screen
|
|
|
|
// surface. 10-bit, in particular, has strange gamma behavior.
|
2016-04-14 19:39:00 +00:00
|
|
|
return SkSurface::MakeRenderTarget(fCurContext, SkBudgeted::kNo, win->info(),
|
2016-07-28 22:17:34 +00:00
|
|
|
fMSAASampleCount, &props);
|
2016-04-14 19:39:00 +00:00
|
|
|
} else {
|
2016-07-28 22:17:34 +00:00
|
|
|
return fGpuSurface;
|
2016-04-14 19:39:00 +00:00
|
|
|
}
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
2014-09-18 18:29:01 +00:00
|
|
|
#endif
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void publishCanvas(SampleWindow::DeviceType dType,
|
2016-07-29 15:28:25 +00:00
|
|
|
SkCanvas* renderingCanvas, SampleWindow* win) override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-05-05 19:24:31 +00:00
|
|
|
if (!IsGpuDeviceType(dType) ||
|
|
|
|
kRGBA_F16_SkColorType == win->info().colorType() ||
|
|
|
|
fActualColorBits > 24) {
|
2017-01-17 21:10:07 +00:00
|
|
|
// We made/have an off-screen surface. Extract the pixels exactly as we rendered them:
|
|
|
|
SkImageInfo info = win->info();
|
|
|
|
size_t rowBytes = info.minRowBytes();
|
|
|
|
size_t size = info.getSafeSize(rowBytes);
|
|
|
|
auto data = SkData::MakeUninitialized(size);
|
|
|
|
SkASSERT(data);
|
|
|
|
|
|
|
|
if (!renderingCanvas->readPixels(info, data->writable_data(), rowBytes, 0, 0)) {
|
|
|
|
SkDEBUGFAIL("Failed to read canvas pixels");
|
|
|
|
return;
|
2016-09-29 21:37:02 +00:00
|
|
|
}
|
2017-01-17 21:10:07 +00:00
|
|
|
|
|
|
|
// Now, re-interpret those pixels as sRGB, so they won't be color converted when we
|
|
|
|
// draw then to FBO0. This ensures that if we rendered in any strange gamut, we'll see
|
|
|
|
// the "correct" output (because we generated the pixel values we wanted in the
|
|
|
|
// offscreen canvas).
|
|
|
|
auto colorSpace = kRGBA_F16_SkColorType == info.colorType()
|
2017-02-07 18:56:11 +00:00
|
|
|
? SkColorSpace::MakeSRGBLinear()
|
|
|
|
: SkColorSpace::MakeSRGB();
|
2017-01-17 21:10:07 +00:00
|
|
|
auto offscreenImage = SkImage::MakeRasterData(info.makeColorSpace(colorSpace), data,
|
|
|
|
rowBytes);
|
2016-07-28 22:17:34 +00:00
|
|
|
|
2016-07-29 15:28:25 +00:00
|
|
|
SkCanvas* gpuCanvas = fGpuSurface->getCanvas();
|
2016-05-05 19:24:31 +00:00
|
|
|
|
|
|
|
// With ten-bit output, we need to manually apply the gamma of the output device
|
|
|
|
// (unless we're in non-gamma correct mode, in which case our data is already
|
|
|
|
// fake-sRGB, like we're expected to put in the 10-bit buffer):
|
2016-11-01 19:56:16 +00:00
|
|
|
bool doGamma = (fActualColorBits == 30) && win->info().colorSpace();
|
2016-07-29 15:28:25 +00:00
|
|
|
|
|
|
|
SkPaint gammaPaint;
|
2016-10-06 00:33:02 +00:00
|
|
|
gammaPaint.setBlendMode(SkBlendMode::kSrc);
|
2016-07-29 15:28:25 +00:00
|
|
|
if (doGamma) {
|
2017-01-26 14:32:33 +00:00
|
|
|
gammaPaint.setColorFilter(sk_tool_utils::MakeLinearToSRGBColorFilter());
|
2016-07-29 15:28:25 +00:00
|
|
|
}
|
|
|
|
|
2017-01-17 21:10:07 +00:00
|
|
|
gpuCanvas->drawImage(offscreenImage, 0, 0, &gammaPaint);
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
2016-07-29 15:28:25 +00:00
|
|
|
|
|
|
|
fGpuSurface->prepareForExternalIO();
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
win->present();
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
void windowSizeChanged(SampleWindow* win) override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
if (fCurContext) {
|
2013-03-05 20:06:05 +00:00
|
|
|
AttachmentInfo attachmentInfo;
|
2016-05-05 19:24:31 +00:00
|
|
|
win->attach(fBackend, fMSAASampleCount, fDeepColor, &attachmentInfo);
|
|
|
|
fActualColorBits = SkTMax(attachmentInfo.fColorBits, 24);
|
2016-07-28 22:17:34 +00:00
|
|
|
fGpuSurface = win->makeGpuBackedSurface(attachmentInfo, fCurIntf, fCurContext);
|
2011-10-27 20:44:19 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
GrContext* getGrContext() override {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
return fCurContext;
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
2012-04-06 20:13:38 +00:00
|
|
|
|
2016-07-28 22:17:34 +00:00
|
|
|
int numColorSamples() const override {
|
2016-09-15 14:19:53 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-07-28 22:17:34 +00:00
|
|
|
return fMSAASampleCount;
|
2016-09-15 14:19:53 +00:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2012-04-06 20:13:38 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 19:24:31 +00:00
|
|
|
int getColorBits() override {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
return fActualColorBits;
|
|
|
|
#else
|
|
|
|
return 24;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
private:
|
2012-08-02 14:03:32 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
GrContext* fCurContext;
|
|
|
|
const GrGLInterface* fCurIntf;
|
2016-07-28 22:17:34 +00:00
|
|
|
sk_sp<SkSurface> fGpuSurface;
|
2012-08-02 14:03:32 +00:00
|
|
|
int fMSAASampleCount;
|
2016-05-05 19:24:31 +00:00
|
|
|
bool fDeepColor;
|
|
|
|
int fActualColorBits;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
SkOSWindow::SkBackEndTypes fBackend;
|
|
|
|
|
|
|
|
typedef SampleWindow::DeviceManager INHERITED;
|
2011-07-14 14:30:46 +00:00
|
|
|
};
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
///////////////
|
|
|
|
static const char view_inval_msg[] = "view-inval-msg";
|
|
|
|
|
2011-06-21 16:01:26 +00:00
|
|
|
void SampleWindow::postInvalDelay() {
|
2011-08-04 13:50:17 +00:00
|
|
|
(new SkEvent(view_inval_msg, this->getSinkID()))->postDelay(1);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isInvalEvent(const SkEvent& evt) {
|
|
|
|
return evt.isType(view_inval_msg);
|
|
|
|
}
|
|
|
|
//////////////////
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
#include "GMSampleView.h"
|
|
|
|
|
|
|
|
class AutoUnrefArray {
|
|
|
|
public:
|
|
|
|
AutoUnrefArray() {}
|
|
|
|
~AutoUnrefArray() {
|
|
|
|
int count = fObjs.count();
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
fObjs[i]->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkRefCnt*& push_back() { return *fObjs.append(); }
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
private:
|
|
|
|
SkTDArray<SkRefCnt*> fObjs;
|
|
|
|
};
|
|
|
|
|
|
|
|
// registers GMs as Samples
|
|
|
|
// This can't be performed during static initialization because it could be
|
|
|
|
// run before GMRegistry has been fully built.
|
2012-06-06 12:09:51 +00:00
|
|
|
static void SkGMRegistyToSampleRegistry() {
|
2008-12-17 15:59:43 +00:00
|
|
|
static bool gOnce;
|
2012-08-01 17:58:01 +00:00
|
|
|
static AutoUnrefArray fRegisters;
|
2011-10-31 14:18:20 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
if (!gOnce) {
|
2011-10-31 14:18:20 +00:00
|
|
|
const skiagm::GMRegistry* gmreg = skiagm::GMRegistry::Head();
|
|
|
|
while (gmreg) {
|
|
|
|
fRegisters.push_back() = new SkViewRegister(gmreg->factory());
|
|
|
|
gmreg = gmreg->next();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
gOnce = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-11 20:08:25 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-04-05 13:07:03 +00:00
|
|
|
enum FlipAxisEnum {
|
|
|
|
kFlipAxis_X = (1 << 0),
|
|
|
|
kFlipAxis_Y = (1 << 1)
|
|
|
|
};
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-04-05 13:07:03 +00:00
|
|
|
#include "SkDrawFilter.h"
|
|
|
|
|
2013-06-03 21:26:34 +00:00
|
|
|
struct HintingState {
|
|
|
|
SkPaint::Hinting hinting;
|
|
|
|
const char* name;
|
|
|
|
const char* label;
|
|
|
|
};
|
|
|
|
static HintingState gHintingStates[] = {
|
2015-08-27 14:41:13 +00:00
|
|
|
{SkPaint::kNo_Hinting, "Mixed", nullptr },
|
2013-06-03 21:26:34 +00:00
|
|
|
{SkPaint::kNo_Hinting, "None", "H0 " },
|
|
|
|
{SkPaint::kSlight_Hinting, "Slight", "Hs " },
|
|
|
|
{SkPaint::kNormal_Hinting, "Normal", "Hn " },
|
|
|
|
{SkPaint::kFull_Hinting, "Full", "Hf " },
|
|
|
|
};
|
|
|
|
|
2016-03-31 15:30:38 +00:00
|
|
|
struct PixelGeometryState {
|
|
|
|
SkPixelGeometry pixelGeometry;
|
|
|
|
const char* name;
|
|
|
|
const char* label;
|
|
|
|
};
|
|
|
|
static PixelGeometryState gPixelGeometryStates[] = {
|
|
|
|
{SkPixelGeometry::kUnknown_SkPixelGeometry, "Mixed", nullptr },
|
|
|
|
{SkPixelGeometry::kUnknown_SkPixelGeometry, "Flat", "{Flat} " },
|
|
|
|
{SkPixelGeometry::kRGB_H_SkPixelGeometry, "RGB H", "{RGB H} " },
|
|
|
|
{SkPixelGeometry::kBGR_H_SkPixelGeometry, "BGR H", "{BGR H} " },
|
|
|
|
{SkPixelGeometry::kRGB_V_SkPixelGeometry, "RGB_V", "{RGB V} " },
|
|
|
|
{SkPixelGeometry::kBGR_V_SkPixelGeometry, "BGR_V", "{BGR V} " },
|
|
|
|
};
|
|
|
|
|
2015-03-16 17:08:34 +00:00
|
|
|
struct FilterQualityState {
|
|
|
|
SkFilterQuality fQuality;
|
|
|
|
const char* fName;
|
|
|
|
const char* fLabel;
|
2013-12-10 16:53:13 +00:00
|
|
|
};
|
2015-03-16 17:08:34 +00:00
|
|
|
static FilterQualityState gFilterQualityStates[] = {
|
2015-08-27 14:41:13 +00:00
|
|
|
{ kNone_SkFilterQuality, "Mixed", nullptr },
|
2015-03-16 17:08:34 +00:00
|
|
|
{ kNone_SkFilterQuality, "None", "F0 " },
|
|
|
|
{ kLow_SkFilterQuality, "Low", "F1 " },
|
|
|
|
{ kMedium_SkFilterQuality, "Medium", "F2 " },
|
|
|
|
{ kHigh_SkFilterQuality, "High", "F3 " },
|
2013-12-10 16:53:13 +00:00
|
|
|
};
|
|
|
|
|
2015-06-15 14:07:32 +00:00
|
|
|
class FlagsFilterCanvas : public SkPaintFilterCanvas {
|
2011-04-05 13:07:03 +00:00
|
|
|
public:
|
2015-06-15 14:07:32 +00:00
|
|
|
FlagsFilterCanvas(SkCanvas* canvas, SkOSMenu::TriState lcd, SkOSMenu::TriState aa,
|
|
|
|
SkOSMenu::TriState subpixel, int hinting, int filterQuality)
|
2016-01-11 21:58:29 +00:00
|
|
|
: INHERITED(canvas)
|
2015-06-15 14:07:32 +00:00
|
|
|
, fLCDState(lcd)
|
2013-12-10 16:53:13 +00:00
|
|
|
, fAAState(aa)
|
|
|
|
, fSubpixelState(subpixel)
|
|
|
|
, fHintingState(hinting)
|
2015-06-15 14:07:32 +00:00
|
|
|
, fFilterQualityIndex(filterQuality) {
|
2015-03-16 17:08:34 +00:00
|
|
|
SkASSERT((unsigned)filterQuality < SK_ARRAY_COUNT(gFilterQualityStates));
|
2013-12-10 16:53:13 +00:00
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2015-06-15 14:07:32 +00:00
|
|
|
protected:
|
2016-01-12 15:21:11 +00:00
|
|
|
bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type t) const override {
|
|
|
|
if (!*paint) {
|
2016-01-11 21:58:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
|
2011-04-05 13:07:03 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::kMixedState != fAAState) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setAntiAlias(SkOSMenu::kOnState == fAAState);
|
2011-03-11 20:08:25 +00:00
|
|
|
}
|
2015-03-16 17:08:34 +00:00
|
|
|
if (0 != fFilterQualityIndex) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setFilterQuality(gFilterQualityStates[fFilterQualityIndex].fQuality);
|
2011-05-17 15:32:04 +00:00
|
|
|
}
|
2013-06-03 21:26:34 +00:00
|
|
|
if (SkOSMenu::kMixedState != fSubpixelState) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setSubpixelText(SkOSMenu::kOnState == fSubpixelState);
|
2013-06-03 21:26:34 +00:00
|
|
|
}
|
2013-06-03 21:35:03 +00:00
|
|
|
if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) {
|
2016-01-12 15:21:11 +00:00
|
|
|
paint->writable()->setHinting(gHintingStates[fHintingState].hinting);
|
2011-05-18 12:04:31 +00:00
|
|
|
}
|
2016-01-11 21:58:29 +00:00
|
|
|
return true;
|
2011-03-11 20:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-08-08 15:37:23 +00:00
|
|
|
SkOSMenu::TriState fLCDState;
|
|
|
|
SkOSMenu::TriState fAAState;
|
2013-06-03 21:26:34 +00:00
|
|
|
SkOSMenu::TriState fSubpixelState;
|
|
|
|
int fHintingState;
|
2015-03-16 17:08:34 +00:00
|
|
|
int fFilterQualityIndex;
|
2015-06-15 14:07:32 +00:00
|
|
|
|
|
|
|
typedef SkPaintFilterCanvas INHERITED;
|
2011-03-11 20:08:25 +00:00
|
|
|
};
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
class SampleTFSerializer : public SkTypefaceSerializer {
|
|
|
|
public:
|
|
|
|
sk_sp<SkData> serialize(SkTypeface* tf) override {
|
|
|
|
tf->ref();
|
|
|
|
return SkData::MakeWithCopy(&tf, sizeof(tf));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SampleTFDeserializer : public SkTypefaceDeserializer {
|
|
|
|
public:
|
|
|
|
sk_sp<SkTypeface> deserialize(const void* data, size_t size) override {
|
|
|
|
SkASSERT(sizeof(SkTypeface*) == size);
|
|
|
|
SkTypeface* tf;
|
|
|
|
memcpy(&tf, data, size);
|
|
|
|
return sk_sp<SkTypeface>(tf); // this was ref'd in SampleTFSerializer
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-12-06 20:14:55 +00:00
|
|
|
enum TilingMode {
|
|
|
|
kNo_Tiling,
|
|
|
|
kAbs_128x128_Tiling,
|
|
|
|
kAbs_256x256_Tiling,
|
|
|
|
kRel_4x4_Tiling,
|
|
|
|
kRel_1x16_Tiling,
|
|
|
|
kRel_16x1_Tiling,
|
|
|
|
|
|
|
|
kLast_TilingMode_Enum
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TilingInfo {
|
|
|
|
const char* label;
|
|
|
|
SkScalar w, h;
|
|
|
|
};
|
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
static const struct TilingInfo gTilingInfo[] = {
|
2013-12-06 20:14:55 +00:00
|
|
|
{ "No tiling", SK_Scalar1 , SK_Scalar1 }, // kNo_Tiling
|
|
|
|
{ "128x128" , SkIntToScalar(128), SkIntToScalar(128) }, // kAbs_128x128_Tiling
|
|
|
|
{ "256x256" , SkIntToScalar(256), SkIntToScalar(256) }, // kAbs_256x256_Tiling
|
|
|
|
{ "1/4x1/4" , SK_Scalar1 / 4 , SK_Scalar1 / 4 }, // kRel_4x4_Tiling
|
|
|
|
{ "1/1x1/16" , SK_Scalar1 , SK_Scalar1 / 16 }, // kRel_1x16_Tiling
|
|
|
|
{ "1/16x1/1" , SK_Scalar1 / 16 , SK_Scalar1 }, // kRel_16x1_Tiling
|
|
|
|
};
|
2015-08-20 14:57:51 +00:00
|
|
|
static_assert((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum),
|
|
|
|
"Incomplete_tiling_labels");
|
2013-12-06 20:14:55 +00:00
|
|
|
|
2013-12-10 21:51:06 +00:00
|
|
|
SkSize SampleWindow::tileSize() const {
|
|
|
|
SkASSERT((TilingMode)fTilingMode < kLast_TilingMode_Enum);
|
|
|
|
const struct TilingInfo* info = gTilingInfo + fTilingMode;
|
|
|
|
return SkSize::Make(info->w > SK_Scalar1 ? info->w : this->width() * info->w,
|
|
|
|
info->h > SK_Scalar1 ? info->h : this->height() * info->h);
|
|
|
|
}
|
2013-12-06 20:14:55 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
static SkView* curr_view(SkWindow* wind) {
|
|
|
|
SkView::F2BIter iter(wind);
|
|
|
|
return iter.next();
|
|
|
|
}
|
|
|
|
|
2011-12-27 22:33:50 +00:00
|
|
|
static bool curr_title(SkWindow* wind, SkString* title) {
|
|
|
|
SkView* view = curr_view(wind);
|
|
|
|
if (view) {
|
|
|
|
SkEvent evt(gTitleEvtName);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
title->set(evt.findString(gTitleEvtName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-02 03:01:04 +00:00
|
|
|
bool SampleWindow::sendAnimatePulse() {
|
|
|
|
SkView* view = curr_view(this);
|
|
|
|
if (SampleView::IsSampleView(view)) {
|
2015-02-02 20:55:02 +00:00
|
|
|
return ((SampleView*)view)->animate(gAnimTimer);
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
void SampleWindow::setZoomCenter(float x, float y) {
|
2013-11-25 19:44:07 +00:00
|
|
|
fZoomCenterX = x;
|
|
|
|
fZoomCenterY = y;
|
2011-06-15 16:49:08 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
bool SampleWindow::zoomIn() {
|
2011-03-24 18:35:50 +00:00
|
|
|
// Arbitrarily decided
|
2015-08-15 18:57:23 +00:00
|
|
|
if (fFatBitsScale == kMaxFatBitsScale) return false;
|
2011-03-24 18:35:50 +00:00
|
|
|
fFatBitsScale++;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-03-24 18:35:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
bool SampleWindow::zoomOut() {
|
2011-03-24 18:35:50 +00:00
|
|
|
if (fFatBitsScale == 1) return false;
|
|
|
|
fFatBitsScale--;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-03-24 18:35:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
void SampleWindow::updatePointer(int x, int y) {
|
2011-03-24 18:35:50 +00:00
|
|
|
fMouseX = x;
|
|
|
|
fMouseY = y;
|
|
|
|
if (fShowZoomer) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-03-24 18:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
|
|
|
|
static const SampleWindow::DeviceType gCT[] = {
|
2016-01-05 08:04:32 +00:00
|
|
|
SampleWindow::kRaster_DeviceType
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-01-05 08:04:32 +00:00
|
|
|
, SampleWindow::kGPU_DeviceType
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
2016-01-05 08:04:32 +00:00
|
|
|
, SampleWindow::kANGLE_DeviceType
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
#endif // SK_SUPPORT_GPU
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2015-08-20 14:57:51 +00:00
|
|
|
static_assert(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, "array_size_mismatch");
|
2008-12-17 15:59:43 +00:00
|
|
|
return gCT[ct];
|
|
|
|
}
|
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
static SkString getSampleTitle(const SkViewFactory* sampleFactory) {
|
|
|
|
SkView* view = (*sampleFactory)();
|
|
|
|
SkString title;
|
|
|
|
SampleCode::RequestTitle(view, &title);
|
|
|
|
view->unref();
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2013-07-11 15:40:31 +00:00
|
|
|
static bool compareSampleTitle(const SkViewFactory* first, const SkViewFactory* second) {
|
2013-07-11 14:28:04 +00:00
|
|
|
return strcmp(getSampleTitle(first).c_str(), getSampleTitle(second).c_str()) < 0;
|
2012-03-20 17:40:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 19:59:17 +00:00
|
|
|
static int find_by_title(const SkViewFactory* const* factories, int count, const char title[]) {
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
if (getSampleTitle(factories[i]).equals(title)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restrict_samples(SkTDArray<const SkViewFactory*>& factories, const SkString titles[],
|
|
|
|
int count) {
|
|
|
|
int newCount = 0;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
int index = find_by_title(factories.begin(), factories.count(), titles[i].c_str());
|
|
|
|
if (index >= 0) {
|
|
|
|
SkTSwap(factories.begin()[newCount], factories.begin()[index]);
|
|
|
|
newCount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (newCount) {
|
|
|
|
factories.setCount(newCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 21:18:56 +00:00
|
|
|
DEFINE_string(slide, "", "Start on this sample.");
|
|
|
|
DEFINE_string(pictureDir, "", "Read pictures from here.");
|
|
|
|
DEFINE_string(picture, "", "Path to single picture.");
|
2017-03-27 18:32:29 +00:00
|
|
|
DEFINE_string(pathfinder, "", "SKP file with a single path to isolate.");
|
2016-07-27 01:46:34 +00:00
|
|
|
DEFINE_string(svg, "", "Path to single SVG file.");
|
|
|
|
DEFINE_string(svgDir, "", "Read SVGs from here.");
|
2015-11-05 19:59:17 +00:00
|
|
|
DEFINE_string(sequence, "", "Path to file containing the desired samples/gms to show.");
|
2014-06-19 21:18:56 +00:00
|
|
|
DEFINE_bool(sort, false, "Sort samples by title.");
|
|
|
|
DEFINE_bool(list, false, "List samples?");
|
2016-10-28 14:38:08 +00:00
|
|
|
DEFINE_bool(startgpu, false, "Start up with gpu?");
|
2016-02-24 19:47:47 +00:00
|
|
|
DEFINE_bool(redraw, false, "Force continuous redrawing, for profiling or debugging tools.");
|
2014-06-19 21:18:56 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
DEFINE_string(pdfPath, "", "Path to direcotry of pdf files.");
|
|
|
|
#endif
|
2017-02-22 19:00:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
DEFINE_pathrenderer_flag;
|
|
|
|
DEFINE_int32(msaa, 0, "Request multisampling with this count.");
|
|
|
|
DEFINE_bool(deepColor, false, "Request deep color (10-bit/channel or more) display buffer.");
|
|
|
|
#endif
|
2014-06-19 21:18:56 +00:00
|
|
|
|
2014-10-29 19:36:45 +00:00
|
|
|
#include "SkTaskGroup.h"
|
|
|
|
|
2012-08-01 17:58:01 +00:00
|
|
|
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager)
|
2012-04-10 13:34:11 +00:00
|
|
|
: INHERITED(hwnd)
|
2015-08-27 14:41:13 +00:00
|
|
|
, fDevManager(nullptr) {
|
2012-03-20 17:40:58 +00:00
|
|
|
|
2014-06-19 21:18:56 +00:00
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
|
2013-06-06 13:14:13 +00:00
|
|
|
fCurrIndex = -1;
|
|
|
|
|
2014-06-19 21:18:56 +00:00
|
|
|
if (!FLAGS_pictureDir.isEmpty()) {
|
|
|
|
SkOSFile::Iter iter(FLAGS_pictureDir[0], "skp");
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
|
|
|
*fSamples.append() = new PictFileFactory(
|
2014-07-29 02:26:58 +00:00
|
|
|
SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str()));
|
2014-06-19 21:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!FLAGS_picture.isEmpty()) {
|
|
|
|
SkString path(FLAGS_picture[0]);
|
|
|
|
fCurrIndex = fSamples.count();
|
|
|
|
*fSamples.append() = new PictFileFactory(path);
|
|
|
|
}
|
2017-03-27 18:32:29 +00:00
|
|
|
if (!FLAGS_pathfinder.isEmpty()) {
|
|
|
|
SkString path(FLAGS_pathfinder[0]);
|
|
|
|
fCurrIndex = fSamples.count();
|
|
|
|
*fSamples.append() = new PathFinderFactory(path);
|
|
|
|
}
|
2016-07-27 01:46:34 +00:00
|
|
|
if (!FLAGS_svg.isEmpty()) {
|
|
|
|
SkString path(FLAGS_svg[0]);
|
|
|
|
fCurrIndex = fSamples.count();
|
|
|
|
*fSamples.append() = new SVGFileFactory(path);
|
|
|
|
}
|
|
|
|
if (!FLAGS_svgDir.isEmpty()) {
|
|
|
|
SkOSFile::Iter iter(FLAGS_svgDir[0], "svg");
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
|
|
|
*fSamples.append() = new SVGFileFactory(
|
|
|
|
SkOSPath::Join(FLAGS_svgDir[0], filename.c_str()));
|
|
|
|
}
|
|
|
|
}
|
2013-07-11 14:28:04 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
2014-06-19 21:18:56 +00:00
|
|
|
if (!FLAGS_pdfPath.isEmpty()) {
|
|
|
|
SkOSFile::Iter iter(FLAGS_pdfPath[0], "pdf");
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
|
|
|
*fSamples.append() = new PdfFileViewerFactory(
|
2014-07-29 02:26:58 +00:00
|
|
|
SkOSPath::Join(FLAGS_pictureDir[0], filename.c_str()));
|
2014-06-19 21:18:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-22 14:12:15 +00:00
|
|
|
SkGMRegistyToSampleRegistry();
|
|
|
|
{
|
|
|
|
const SkViewRegister* reg = SkViewRegister::Head();
|
|
|
|
while (reg) {
|
|
|
|
*fSamples.append() = reg->factory();
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 19:59:17 +00:00
|
|
|
if (!FLAGS_sequence.isEmpty()) {
|
|
|
|
// The sequence file just contains a list (separated by CRs) of the samples or GM:gms
|
|
|
|
// you want to restrict to. Only these will appear when you cycle through.
|
|
|
|
// If none are found, or the file is empty, then it will be ignored, and all samples
|
|
|
|
// will be available.
|
|
|
|
SkFILEStream stream(FLAGS_sequence[0]);
|
|
|
|
if (stream.isValid()) {
|
|
|
|
size_t len = stream.getLength();
|
2015-12-10 18:44:13 +00:00
|
|
|
SkAutoTMalloc<char> storage(len + 1);
|
|
|
|
char* buffer = storage.get();
|
2015-11-05 19:59:17 +00:00
|
|
|
stream.read(buffer, len);
|
|
|
|
buffer[len] = 0;
|
|
|
|
|
|
|
|
SkTArray<SkString> titles;
|
|
|
|
SkStrSplit(buffer, "\n\r", &titles);
|
|
|
|
restrict_samples(fSamples, titles.begin(), titles.count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 21:18:56 +00:00
|
|
|
if (FLAGS_sort) {
|
2013-07-11 14:28:04 +00:00
|
|
|
// Sort samples, so foo.skp and foo.pdf are consecutive and we can quickly spot where
|
|
|
|
// skp -> pdf -> png fails.
|
2015-08-27 14:41:13 +00:00
|
|
|
SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : nullptr, compareSampleTitle);
|
2013-07-11 14:28:04 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 21:18:56 +00:00
|
|
|
if (!FLAGS_slide.isEmpty()) {
|
|
|
|
fCurrIndex = findByTitle(FLAGS_slide[0]);
|
|
|
|
if (fCurrIndex < 0) {
|
|
|
|
fprintf(stderr, "Unknown sample \"%s\"\n", FLAGS_slide[0]);
|
2012-05-03 18:22:28 +00:00
|
|
|
listTitles();
|
2012-03-20 17:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-22 19:00:42 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
fBackendOptions.fGrContextOptions.fGpuPathRenderers = CollectGpuPathRenderersFromFlags();
|
|
|
|
fBackendOptions.fMSAASampleCount = FLAGS_msaa;
|
|
|
|
fBackendOptions.fDeepColor = FLAGS_deepColor;
|
|
|
|
#endif
|
2016-09-29 21:37:02 +00:00
|
|
|
fColorConfigIndex = 0;
|
2014-06-19 21:18:56 +00:00
|
|
|
|
|
|
|
if (FLAGS_list) {
|
|
|
|
listTitles();
|
|
|
|
}
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
if (fCurrIndex < 0) {
|
|
|
|
SkString title;
|
|
|
|
if (readTitleFromPrefs(&title)) {
|
|
|
|
fCurrIndex = findByTitle(title.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fCurrIndex < 0) {
|
|
|
|
fCurrIndex = 0;
|
|
|
|
}
|
|
|
|
|
2014-10-29 19:36:45 +00:00
|
|
|
static SkTaskGroup::Enabler enabled(-1);
|
2011-07-06 13:59:47 +00:00
|
|
|
gSampleWindow = this;
|
|
|
|
|
2012-03-30 15:18:14 +00:00
|
|
|
fDeviceType = kRaster_DeviceType;
|
2015-10-02 17:42:36 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2016-10-28 14:38:08 +00:00
|
|
|
if (FLAGS_startgpu) {
|
2015-10-02 16:12:05 +00:00
|
|
|
fDeviceType = kGPU_DeviceType;
|
|
|
|
}
|
2015-10-02 17:42:36 +00:00
|
|
|
#endif
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
#if DEFAULT_TO_GPU
|
|
|
|
fDeviceType = kGPU_DeviceType;
|
|
|
|
#endif
|
|
|
|
#if SK_ANGLE && DEFAULT_TO_ANGLE
|
|
|
|
fDeviceType = kANGLE_DeviceType;
|
2012-03-30 14:47:53 +00:00
|
|
|
#endif
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fUseClip = false;
|
2016-01-08 16:23:19 +00:00
|
|
|
fUsePicture = false;
|
2008-12-17 15:59:43 +00:00
|
|
|
fAnimating = false;
|
2009-08-14 16:08:38 +00:00
|
|
|
fRotate = false;
|
2011-09-08 18:48:12 +00:00
|
|
|
fPerspAnim = false;
|
2010-12-20 18:26:13 +00:00
|
|
|
fRequestGrabImage = false;
|
2013-12-06 20:14:55 +00:00
|
|
|
fTilingMode = kNo_Tiling;
|
2011-04-22 01:59:09 +00:00
|
|
|
fMeasureFPS = false;
|
2016-07-08 15:43:27 +00:00
|
|
|
fUseDeferredCanvas = false;
|
2011-08-08 15:37:23 +00:00
|
|
|
fLCDState = SkOSMenu::kMixedState;
|
|
|
|
fAAState = SkOSMenu::kMixedState;
|
2013-06-03 21:26:34 +00:00
|
|
|
fSubpixelState = SkOSMenu::kMixedState;
|
|
|
|
fHintingState = 0;
|
2016-03-31 15:30:38 +00:00
|
|
|
fPixelGeometryIndex = 0;
|
2015-03-16 17:08:34 +00:00
|
|
|
fFilterQualityIndex = 0;
|
2011-04-05 13:07:03 +00:00
|
|
|
fFlipAxis = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
fMouseX = fMouseY = 0;
|
2011-04-08 00:38:05 +00:00
|
|
|
fFatBitsScale = 8;
|
2016-08-22 02:30:13 +00:00
|
|
|
fTypeface = SkTypeface::MakeFromName("Courier", SkFontStyle(SkFontStyle::kBold_Weight,
|
|
|
|
SkFontStyle::kNormal_Width,
|
|
|
|
SkFontStyle::kUpright_Slant));
|
2011-03-24 18:35:50 +00:00
|
|
|
fShowZoomer = false;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
fZoomLevel = 0;
|
|
|
|
fZoomScale = SK_Scalar1;
|
2016-03-03 21:32:38 +00:00
|
|
|
fOffset = { 0, 0 };
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
fMagnify = false;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
fSaveToPdf = false;
|
2015-08-05 01:46:38 +00:00
|
|
|
fSaveToSKP = false;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2016-09-13 15:09:45 +00:00
|
|
|
if (true) {
|
|
|
|
fPipeSerializer.setTypefaceSerializer(new SampleTFSerializer);
|
|
|
|
fPipeDeserializer.setTypefaceDeserializer(new SampleTFDeserializer);
|
|
|
|
}
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
int sinkID = this->getSinkID();
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu = new SkOSMenu;
|
|
|
|
fAppMenu->setTitle("Global Settings");
|
2011-08-08 15:37:23 +00:00
|
|
|
int itemID;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2016-02-15 15:48:35 +00:00
|
|
|
itemID = fAppMenu->appendList("ColorType", "ColorType", sinkID, 0,
|
2016-09-29 21:37:02 +00:00
|
|
|
gConfig[0].fName,
|
|
|
|
gConfig[1].fName,
|
|
|
|
gConfig[2].fName,
|
|
|
|
gConfig[3].fName,
|
2016-12-02 17:10:36 +00:00
|
|
|
gConfig[4].fName,
|
2016-09-29 21:37:02 +00:00
|
|
|
nullptr);
|
2016-02-15 15:48:35 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'C');
|
|
|
|
|
2016-01-05 08:04:32 +00:00
|
|
|
itemID = fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
|
|
|
|
"Raster",
|
|
|
|
"OpenGL",
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
2016-01-05 08:04:32 +00:00
|
|
|
"ANGLE",
|
2012-04-02 19:24:21 +00:00
|
|
|
#endif
|
2016-01-05 08:04:32 +00:00
|
|
|
nullptr);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'd');
|
|
|
|
itemID = fAppMenu->appendTriState("AA", "AA", sinkID, fAAState);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'b');
|
|
|
|
itemID = fAppMenu->appendTriState("LCD", "LCD", sinkID, fLCDState);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'l');
|
2015-03-16 17:08:34 +00:00
|
|
|
itemID = fAppMenu->appendList("FilterQuality", "FilterQuality", sinkID, fFilterQualityIndex,
|
|
|
|
gFilterQualityStates[0].fName,
|
|
|
|
gFilterQualityStates[1].fName,
|
|
|
|
gFilterQualityStates[2].fName,
|
|
|
|
gFilterQualityStates[3].fName,
|
|
|
|
gFilterQualityStates[4].fName,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'n');
|
2013-06-03 21:26:34 +00:00
|
|
|
itemID = fAppMenu->appendTriState("Subpixel", "Subpixel", sinkID, fSubpixelState);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 's');
|
|
|
|
itemID = fAppMenu->appendList("Hinting", "Hinting", sinkID, fHintingState,
|
|
|
|
gHintingStates[0].name,
|
|
|
|
gHintingStates[1].name,
|
|
|
|
gHintingStates[2].name,
|
|
|
|
gHintingStates[3].name,
|
2013-06-04 17:49:20 +00:00
|
|
|
gHintingStates[4].name,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
|
2012-08-15 14:41:58 +00:00
|
|
|
|
2016-03-31 15:30:38 +00:00
|
|
|
itemID = fAppMenu->appendList("Pixel Geometry", "Pixel Geometry", sinkID, fPixelGeometryIndex,
|
|
|
|
gPixelGeometryStates[0].name,
|
|
|
|
gPixelGeometryStates[1].name,
|
|
|
|
gPixelGeometryStates[2].name,
|
|
|
|
gPixelGeometryStates[3].name,
|
|
|
|
gPixelGeometryStates[4].name,
|
|
|
|
gPixelGeometryStates[5].name,
|
|
|
|
nullptr);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'P');
|
|
|
|
|
2013-12-06 20:14:55 +00:00
|
|
|
itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode,
|
|
|
|
gTilingInfo[kNo_Tiling].label,
|
|
|
|
gTilingInfo[kAbs_128x128_Tiling].label,
|
|
|
|
gTilingInfo[kAbs_256x256_Tiling].label,
|
|
|
|
gTilingInfo[kRel_4x4_Tiling].label,
|
|
|
|
gTilingInfo[kRel_1x16_Tiling].label,
|
|
|
|
gTilingInfo[kRel_16x1_Tiling].label,
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr);
|
2012-08-15 14:41:58 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 't');
|
|
|
|
|
2012-08-01 17:58:01 +00:00
|
|
|
itemID = fAppMenu->appendSwitch("Slide Show", "Slide Show" , sinkID, false);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'a');
|
|
|
|
itemID = fAppMenu->appendSwitch("Clip", "Clip" , sinkID, fUseClip);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'c');
|
2012-08-01 17:58:01 +00:00
|
|
|
itemID = fAppMenu->appendSwitch("Flip X", "Flip X" , sinkID, false);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'x');
|
|
|
|
itemID = fAppMenu->appendSwitch("Flip Y", "Flip Y" , sinkID, false);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'y');
|
|
|
|
itemID = fAppMenu->appendSwitch("Zoomer", "Zoomer" , sinkID, fShowZoomer);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'z');
|
|
|
|
itemID = fAppMenu->appendSwitch("Magnify", "Magnify" , sinkID, fMagnify);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'm');
|
2015-08-05 01:46:38 +00:00
|
|
|
|
2012-04-18 14:07:57 +00:00
|
|
|
itemID = fAppMenu->appendAction("Save to PDF", sinkID);
|
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'e');
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-04-18 14:07:57 +00:00
|
|
|
this->addMenu(fAppMenu);
|
|
|
|
fSlideMenu = new SkOSMenu;
|
|
|
|
this->addMenu(fSlideMenu);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-01-05 16:34:41 +00:00
|
|
|
this->setVisibleP(true);
|
2010-12-20 18:26:13 +00:00
|
|
|
this->setClipToBounds(false);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
this->loadView((*fSamples[fCurrIndex])());
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == devManager) {
|
2011-07-14 14:30:46 +00:00
|
|
|
fDevManager = new DefaultDeviceManager();
|
|
|
|
} else {
|
|
|
|
devManager->ref();
|
|
|
|
fDevManager = devManager;
|
|
|
|
}
|
2017-02-22 19:00:42 +00:00
|
|
|
fDevManager->setUpBackend(this, fBackendOptions);
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2011-06-17 13:53:05 +00:00
|
|
|
// If another constructor set our dimensions, ensure that our
|
|
|
|
// onSizeChange gets called.
|
|
|
|
if (this->height() && this->width()) {
|
|
|
|
this->onSizeChange();
|
|
|
|
}
|
2011-11-08 15:18:10 +00:00
|
|
|
|
|
|
|
// can't call this synchronously, since it may require a subclass to
|
|
|
|
// to implement, or the caller may need us to have returned from the
|
|
|
|
// constructor first. Hence we post an event to ourselves.
|
|
|
|
// this->updateTitle();
|
2013-12-11 17:05:23 +00:00
|
|
|
post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this);
|
2015-02-02 20:55:02 +00:00
|
|
|
|
|
|
|
gAnimTimer.run();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SampleWindow::~SampleWindow() {
|
2011-07-14 14:30:46 +00:00
|
|
|
SkSafeUnref(fDevManager);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
|
2011-12-27 22:33:50 +00:00
|
|
|
int SampleWindow::findByTitle(const char title[]) {
|
|
|
|
int i, count = fSamples.count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (getSampleTitle(i).equals(title)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2011-12-28 20:02:10 +00:00
|
|
|
return -1;
|
2011-12-27 22:33:50 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:22:28 +00:00
|
|
|
void SampleWindow::listTitles() {
|
|
|
|
int count = fSamples.count();
|
|
|
|
SkDebugf("All Slides:\n");
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
SkDebugf(" %s\n", getSampleTitle(i).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 21:46:47 +00:00
|
|
|
static SkBitmap capture_bitmap(SkCanvas* canvas) {
|
|
|
|
SkBitmap bm;
|
2014-09-02 19:50:45 +00:00
|
|
|
if (bm.tryAllocPixels(canvas->imageInfo())) {
|
2017-04-17 14:53:29 +00:00
|
|
|
canvas->readPixels(bm, 0, 0);
|
2014-02-13 17:14:46 +00:00
|
|
|
}
|
2009-11-23 21:46:47 +00:00
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:03:20 +00:00
|
|
|
static void drawText(SkCanvas* canvas, SkString str, SkScalar left, SkScalar top, SkPaint& paint) {
|
2011-03-24 18:35:50 +00:00
|
|
|
SkColor desiredColor = paint.getColor();
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
2015-02-21 17:03:20 +00:00
|
|
|
const char* c_str = str.c_str();
|
|
|
|
size_t size = str.size();
|
2011-03-24 18:35:50 +00:00
|
|
|
SkRect bounds;
|
|
|
|
paint.measureText(c_str, size, &bounds);
|
|
|
|
bounds.offset(left, top);
|
|
|
|
SkScalar inset = SkIntToScalar(-2);
|
|
|
|
bounds.inset(inset, inset);
|
|
|
|
canvas->drawRect(bounds, paint);
|
|
|
|
paint.setColor(desiredColor);
|
|
|
|
canvas->drawText(c_str, size, left, top, paint);
|
|
|
|
}
|
|
|
|
|
2009-11-23 21:07:51 +00:00
|
|
|
#define XCLIP_N 8
|
|
|
|
#define YCLIP_N 8
|
2009-11-23 20:10:41 +00:00
|
|
|
|
2016-07-08 15:43:27 +00:00
|
|
|
#include "SkDeferredCanvas.h"
|
|
|
|
#include "SkDumpCanvas.h"
|
|
|
|
|
2009-11-23 20:10:41 +00:00
|
|
|
void SampleWindow::draw(SkCanvas* canvas) {
|
2017-04-03 14:52:48 +00:00
|
|
|
std::unique_ptr<SkThreadedBMPDevice> tDev;
|
|
|
|
std::unique_ptr<SkCanvas> tCanvas;
|
|
|
|
if (fThreads > 0) {
|
|
|
|
tDev.reset(new SkThreadedBMPDevice(this->getBitmap(), fThreads));
|
|
|
|
tCanvas.reset(new SkCanvas(tDev.get()));
|
|
|
|
canvas = tCanvas.get();
|
|
|
|
}
|
|
|
|
|
2015-02-02 20:55:02 +00:00
|
|
|
gAnimTimer.updateTime();
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
if (fGesture.isActive()) {
|
|
|
|
this->updateMatrix();
|
2011-03-16 12:10:02 +00:00
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-12-10 14:12:55 +00:00
|
|
|
if (fMeasureFPS) {
|
|
|
|
fMeasureFPS_Time = 0;
|
|
|
|
}
|
|
|
|
|
2015-02-21 17:03:20 +00:00
|
|
|
SkSize tile = this->tileSize();
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2015-02-21 17:03:20 +00:00
|
|
|
if (kNo_Tiling == fTilingMode) {
|
2016-07-08 15:43:27 +00:00
|
|
|
SkDebugfDumper dumper;
|
|
|
|
SkDumpCanvas dump(&dumper);
|
2017-03-17 19:51:53 +00:00
|
|
|
SkDeferredCanvas deferred(canvas, SkDeferredCanvas::kEager);
|
2016-07-08 15:43:27 +00:00
|
|
|
SkCanvas* c = fUseDeferredCanvas ? &deferred : canvas;
|
|
|
|
this->INHERITED::draw(c); // no looping or surfaces needed
|
2009-11-23 20:10:41 +00:00
|
|
|
} else {
|
2016-03-03 21:32:38 +00:00
|
|
|
const SkScalar w = SkScalarCeilToScalar(tile.width());
|
|
|
|
const SkScalar h = SkScalarCeilToScalar(tile.height());
|
|
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(SkScalarTruncToInt(w), SkScalarTruncToInt(h));
|
2016-03-24 01:59:25 +00:00
|
|
|
auto surface(canvas->makeSurface(info));
|
2015-02-21 17:03:20 +00:00
|
|
|
SkCanvas* tileCanvas = surface->getCanvas();
|
|
|
|
|
2016-03-03 21:32:38 +00:00
|
|
|
for (SkScalar y = 0; y < height(); y += h) {
|
|
|
|
for (SkScalar x = 0; x < width(); x += w) {
|
2015-02-21 17:03:20 +00:00
|
|
|
SkAutoCanvasRestore acr(tileCanvas, true);
|
|
|
|
tileCanvas->translate(-x, -y);
|
|
|
|
tileCanvas->clear(0);
|
|
|
|
this->INHERITED::draw(tileCanvas);
|
2015-08-27 14:41:13 +00:00
|
|
|
surface->draw(canvas, x, y, nullptr);
|
2012-08-17 13:29:50 +00:00
|
|
|
}
|
2015-02-21 17:03:20 +00:00
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2015-02-21 17:03:20 +00:00
|
|
|
// for drawing the borders between tiles
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x60FF00FF);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2013-12-06 20:14:55 +00:00
|
|
|
|
2015-02-21 17:03:20 +00:00
|
|
|
for (SkScalar y = 0; y < height(); y += tile.height()) {
|
|
|
|
for (SkScalar x = 0; x < width(); x += tile.width()) {
|
|
|
|
canvas->drawRect(SkRect::MakeXYWH(x, y, tile.width(), tile.height()), paint);
|
2012-08-17 13:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
}
|
2015-02-21 17:03:20 +00:00
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
if (fShowZoomer && !fSaveToPdf) {
|
2011-05-25 20:50:42 +00:00
|
|
|
showZoomer(canvas);
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (fMagnify && !fSaveToPdf) {
|
|
|
|
magnify(canvas);
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-12-10 14:12:55 +00:00
|
|
|
if (fMeasureFPS && fMeasureFPS_Time) {
|
|
|
|
this->updateTitle();
|
|
|
|
this->postInvalDelay();
|
|
|
|
}
|
|
|
|
|
2016-02-24 19:47:47 +00:00
|
|
|
if (this->sendAnimatePulse() || FLAGS_redraw) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 14:52:48 +00:00
|
|
|
canvas->flush();
|
|
|
|
|
2011-07-06 17:56:47 +00:00
|
|
|
// do this last
|
2011-07-14 14:30:46 +00:00
|
|
|
fDevManager->publishCanvas(fDeviceType, canvas, this);
|
2011-05-25 20:50:42 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
static float clipW = 200;
|
|
|
|
static float clipH = 200;
|
|
|
|
void SampleWindow::magnify(SkCanvas* canvas) {
|
|
|
|
SkRect r;
|
|
|
|
int count = canvas->save();
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
SkMatrix m = canvas->getTotalMatrix();
|
2012-06-04 13:22:14 +00:00
|
|
|
if (!m.invert(&m)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
SkPoint offset, center;
|
2011-10-24 21:09:40 +00:00
|
|
|
SkScalar mouseX = fMouseX * SK_Scalar1;
|
|
|
|
SkScalar mouseY = fMouseY * SK_Scalar1;
|
|
|
|
m.mapXY(mouseX - clipW/2, mouseY - clipH/2, &offset);
|
|
|
|
m.mapXY(mouseX, mouseY, ¢er);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
r.set(0, 0, clipW * m.getScaleX(), clipH * m.getScaleX());
|
|
|
|
r.offset(offset.fX, offset.fY);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFF66AAEE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2011-10-24 21:09:40 +00:00
|
|
|
paint.setStrokeWidth(10.f * m.getScaleX());
|
2011-08-08 15:37:23 +00:00
|
|
|
//lense offset
|
|
|
|
//canvas->translate(0, -250);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->clipRect(r);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
m = canvas->getTotalMatrix();
|
|
|
|
m.setTranslate(-center.fX, -center.fY);
|
2011-10-24 21:09:40 +00:00
|
|
|
m.postScale(0.5f * fFatBitsScale, 0.5f * fFatBitsScale);
|
2011-08-08 15:37:23 +00:00
|
|
|
m.postTranslate(center.fX, center.fY);
|
|
|
|
canvas->concat(m);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
this->INHERITED::draw(canvas);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
canvas->restoreToCount(count);
|
|
|
|
}
|
|
|
|
|
2015-08-15 18:57:23 +00:00
|
|
|
static SkPaint& set_color_ref(SkPaint& paint, SkColor c) {
|
|
|
|
paint.setColor(c);
|
|
|
|
return paint;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_lcd_box(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c,
|
|
|
|
SkScalar sx, SkScalar sy) {
|
|
|
|
const SkScalar w = (1 - 1/sx) / 3;
|
|
|
|
SkPaint paint;
|
|
|
|
SkRect r = SkRect::MakeXYWH(x, y, w, 1 - 1/sy);
|
|
|
|
canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0)));
|
|
|
|
r.offset(w, 0);
|
|
|
|
canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0)));
|
|
|
|
r.offset(w, 0);
|
|
|
|
canvas->drawRect(r, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB(c))));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_lcd_circle(SkCanvas* canvas, SkScalar x, SkScalar y, SkColor c,
|
|
|
|
SkScalar, SkScalar) {
|
|
|
|
const SkRect r = SkRect::MakeXYWH(x, y, 1, 1);
|
|
|
|
const SkScalar cx = x + 0.5f;
|
|
|
|
const SkScalar cy = y + 0.5f;
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkPath path;
|
|
|
|
path.addArc(r, 0, 120); path.lineTo(cx, cy);
|
|
|
|
canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(SkColorGetR(c), 0, 0)));
|
|
|
|
|
|
|
|
path.reset(); path.addArc(r, 120, 120); path.lineTo(cx, cy);
|
|
|
|
canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, SkColorGetG(c), 0)));
|
|
|
|
|
|
|
|
path.reset(); path.addArc(r, 240, 120); path.lineTo(cx, cy);
|
|
|
|
canvas->drawPath(path, set_color_ref(paint, SkColorSetRGB(0, 0, SkColorGetB(c))));
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef void (*ShowLCDProc)(SkCanvas*, SkScalar, SkScalar, SkColor, SkScalar, SkScalar);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Like drawBitmapRect but we manually draw each pixels in RGB
|
|
|
|
*/
|
|
|
|
static void show_lcd_grid(SkCanvas* canvas, const SkBitmap& bitmap,
|
2015-08-15 21:02:29 +00:00
|
|
|
const SkIRect& origSrc, const SkRect& dst, ShowLCDProc proc) {
|
2015-08-15 18:57:23 +00:00
|
|
|
SkIRect src;
|
|
|
|
if (!src.intersect(origSrc, bitmap.bounds())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const SkScalar sx = dst.width() / src.width();
|
|
|
|
const SkScalar sy = dst.height() / src.height();
|
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->translate(dst.left(), dst.top());
|
|
|
|
canvas->scale(sx, sy);
|
|
|
|
|
|
|
|
for (int y = 0; y < src.height(); ++y) {
|
|
|
|
for (int x = 0; x < src.width(); ++x) {
|
|
|
|
proc(canvas, SkIntToScalar(x), SkIntToScalar(y),
|
|
|
|
bitmap.getColor(src.left() + x, src.top() + y), sx, sy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-25 20:50:42 +00:00
|
|
|
void SampleWindow::showZoomer(SkCanvas* canvas) {
|
2015-08-15 18:57:23 +00:00
|
|
|
int count = canvas->save();
|
|
|
|
canvas->resetMatrix();
|
|
|
|
// Ensure the mouse position is on screen.
|
|
|
|
int width = SkScalarRoundToInt(this->width());
|
|
|
|
int height = SkScalarRoundToInt(this->height());
|
|
|
|
if (fMouseX >= width) fMouseX = width - 1;
|
|
|
|
else if (fMouseX < 0) fMouseX = 0;
|
|
|
|
if (fMouseY >= height) fMouseY = height - 1;
|
|
|
|
else if (fMouseY < 0) fMouseY = 0;
|
|
|
|
|
|
|
|
SkBitmap bitmap = capture_bitmap(canvas);
|
|
|
|
|
|
|
|
// Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle.
|
|
|
|
int zoomedWidth = (width >> 1) | 1;
|
|
|
|
int zoomedHeight = (height >> 1) | 1;
|
|
|
|
SkIRect src;
|
|
|
|
src.set(0, 0, zoomedWidth / fFatBitsScale, zoomedHeight / fFatBitsScale);
|
|
|
|
src.offset(fMouseX - (src.width()>>1), fMouseY - (src.height()>>1));
|
|
|
|
SkRect dest;
|
|
|
|
dest.set(0, 0, SkIntToScalar(zoomedWidth), SkIntToScalar(zoomedHeight));
|
|
|
|
dest.offset(SkIntToScalar(width - zoomedWidth), SkIntToScalar(height - zoomedHeight));
|
|
|
|
SkPaint paint;
|
|
|
|
// Clear the background behind our zoomed in view
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
canvas->drawRect(dest, paint);
|
2015-08-15 21:02:29 +00:00
|
|
|
switch (fFatBitsScale) {
|
|
|
|
case kMaxFatBitsScale:
|
|
|
|
show_lcd_grid(canvas, bitmap, src, dest, show_lcd_box);
|
|
|
|
break;
|
|
|
|
case kMaxFatBitsScale - 1:
|
|
|
|
show_lcd_grid(canvas, bitmap, src, dest, show_lcd_circle);
|
|
|
|
break;
|
|
|
|
default:
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->drawBitmapRect(bitmap, src, dest, nullptr);
|
2015-08-15 21:02:29 +00:00
|
|
|
break;
|
2015-08-15 18:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
// Draw a border around the pixel in the middle
|
|
|
|
SkRect originalPixel;
|
|
|
|
originalPixel.set(SkIntToScalar(fMouseX), SkIntToScalar(fMouseY), SkIntToScalar(fMouseX + 1), SkIntToScalar(fMouseY + 1));
|
|
|
|
SkMatrix matrix;
|
|
|
|
SkRect scalarSrc;
|
|
|
|
scalarSrc.set(src);
|
|
|
|
SkColor color = bitmap.getColor(fMouseX, fMouseY);
|
|
|
|
if (matrix.setRectToRect(scalarSrc, dest, SkMatrix::kFill_ScaleToFit)) {
|
|
|
|
SkRect pixel;
|
|
|
|
matrix.mapRect(&pixel, originalPixel);
|
|
|
|
// TODO Perhaps measure the values and make the outline white if it's "dark"
|
|
|
|
if (color == SK_ColorBLACK) {
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
2011-03-24 18:35:50 +00:00
|
|
|
}
|
2015-08-15 18:57:23 +00:00
|
|
|
canvas->drawRect(pixel, paint);
|
|
|
|
}
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
// Draw a border around the destination rectangle
|
|
|
|
canvas->drawRect(dest, paint);
|
|
|
|
paint.setStyle(SkPaint::kStrokeAndFill_Style);
|
|
|
|
// Identify the pixel and its color on screen
|
|
|
|
paint.setTypeface(fTypeface);
|
|
|
|
paint.setAntiAlias(true);
|
2016-08-22 02:30:13 +00:00
|
|
|
paint.setTextSize(18);
|
2015-08-27 14:41:13 +00:00
|
|
|
SkScalar lineHeight = paint.getFontMetrics(nullptr);
|
2015-08-15 18:57:23 +00:00
|
|
|
SkString string;
|
|
|
|
string.appendf("(%i, %i)", fMouseX, fMouseY);
|
|
|
|
SkScalar left = dest.fLeft + SkIntToScalar(3);
|
|
|
|
SkScalar i = SK_Scalar1;
|
2017-02-14 15:59:19 +00:00
|
|
|
drawText(canvas, string, left, lineHeight * i + dest.fTop, paint);
|
2015-08-15 18:57:23 +00:00
|
|
|
// Alpha
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("A: %X", SkColorGetA(color));
|
2017-02-14 15:59:19 +00:00
|
|
|
drawText(canvas, string, left, lineHeight * i + dest.fTop, paint);
|
2015-08-15 18:57:23 +00:00
|
|
|
// Red
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("R: %X", SkColorGetR(color));
|
|
|
|
paint.setColor(SK_ColorRED);
|
2017-02-14 15:59:19 +00:00
|
|
|
drawText(canvas, string, left, lineHeight * i + dest.fTop, paint);
|
2015-08-15 18:57:23 +00:00
|
|
|
// Green
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("G: %X", SkColorGetG(color));
|
2016-08-22 02:30:13 +00:00
|
|
|
paint.setColor(0xFF008800);
|
2017-02-14 15:59:19 +00:00
|
|
|
drawText(canvas, string, left, lineHeight * i + dest.fTop, paint);
|
2015-08-15 18:57:23 +00:00
|
|
|
// Blue
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("B: %X", SkColorGetB(color));
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
2017-02-14 15:59:19 +00:00
|
|
|
drawText(canvas, string, left, lineHeight * i + dest.fTop, paint);
|
2015-08-15 18:57:23 +00:00
|
|
|
canvas->restoreToCount(count);
|
2009-11-23 20:10:41 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
void SampleWindow::onDraw(SkCanvas* canvas) {
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
void SampleWindow::saveToPdf()
|
|
|
|
{
|
|
|
|
fSaveToPdf = true;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-06-21 14:44:57 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
|
2011-06-21 14:44:57 +00:00
|
|
|
if (fSaveToPdf) {
|
2014-10-08 18:10:51 +00:00
|
|
|
SkString name;
|
|
|
|
if (!this->getRawTitle(&name)) {
|
|
|
|
name.set("unknown_sample");
|
|
|
|
}
|
|
|
|
name.append(".pdf");
|
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
|
|
|
name.prepend("/sdcard/");
|
|
|
|
#endif
|
2016-05-03 19:10:04 +00:00
|
|
|
fPDFDocument = SkDocument::MakePDF(name.c_str());
|
2014-10-08 18:10:51 +00:00
|
|
|
canvas = fPDFDocument->beginPage(this->width(), this->height());
|
2016-01-05 08:04:32 +00:00
|
|
|
} else if (fSaveToSKP) {
|
|
|
|
canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
|
2016-01-08 16:23:19 +00:00
|
|
|
} else if (fUsePicture) {
|
2017-03-15 01:10:42 +00:00
|
|
|
if (PICTURE_MEANS_PIPE) {
|
|
|
|
fPipeStream.reset(new SkDynamicMemoryWStream);
|
|
|
|
canvas = fPipeSerializer.beginWrite(SkRect::MakeWH(this->width(), this->height()),
|
|
|
|
fPipeStream.get());
|
|
|
|
} else {
|
|
|
|
canvas = fRecorder.beginRecording(9999, 9999, nullptr, 0);
|
|
|
|
}
|
2011-06-21 14:44:57 +00:00
|
|
|
} else {
|
2015-02-11 19:11:11 +00:00
|
|
|
canvas = this->INHERITED::beforeChildren(canvas);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fUseClip) {
|
|
|
|
canvas->drawColor(0xFFFF88FF);
|
2016-12-09 14:00:50 +00:00
|
|
|
canvas->clipPath(fClipPath, kIntersect_SkClipOp, true);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 14:07:32 +00:00
|
|
|
// Install a flags filter proxy canvas if needed
|
|
|
|
if (fLCDState != SkOSMenu::kMixedState ||
|
|
|
|
fAAState != SkOSMenu::kMixedState ||
|
|
|
|
fSubpixelState != SkOSMenu::kMixedState ||
|
|
|
|
fHintingState > 0 ||
|
|
|
|
fFilterQualityIndex > 0) {
|
2015-08-26 20:07:48 +00:00
|
|
|
canvas = new FlagsFilterCanvas(canvas, fLCDState, fAAState, fSubpixelState, fHintingState,
|
|
|
|
fFilterQualityIndex);
|
2015-06-15 14:07:32 +00:00
|
|
|
fFlagsFilterCanvas.reset(canvas);
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
return canvas;
|
|
|
|
}
|
2014-10-29 19:36:45 +00:00
|
|
|
#include "SkMultiPictureDraw.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
void SampleWindow::afterChildren(SkCanvas* orig) {
|
2015-08-27 14:41:13 +00:00
|
|
|
fFlagsFilterCanvas.reset(nullptr);
|
2015-06-15 14:07:32 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
if (fSaveToPdf) {
|
|
|
|
fSaveToPdf = false;
|
2014-10-08 18:10:51 +00:00
|
|
|
fPDFDocument->endPage();
|
2015-08-27 14:41:13 +00:00
|
|
|
fPDFDocument.reset(nullptr);
|
2011-06-21 14:44:57 +00:00
|
|
|
// We took over the draw calls in order to create the PDF, so we need
|
|
|
|
// to redraw.
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-06-21 14:44:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
if (fRequestGrabImage) {
|
|
|
|
fRequestGrabImage = false;
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2014-06-30 16:05:34 +00:00
|
|
|
SkBitmap bmp = capture_bitmap(orig);
|
|
|
|
if (!bmp.isNull()) {
|
2010-12-20 18:26:13 +00:00
|
|
|
static int gSampleGrabCounter;
|
|
|
|
SkString name;
|
2012-09-08 21:20:33 +00:00
|
|
|
name.printf("sample_grab_%d.png", gSampleGrabCounter++);
|
2016-11-23 15:55:18 +00:00
|
|
|
sk_tool_utils::EncodeImageToFile(name.c_str(), bmp,
|
|
|
|
SkEncodedImageFormat::kPNG, 100);
|
2010-12-20 18:26:13 +00:00
|
|
|
}
|
2016-01-05 08:04:32 +00:00
|
|
|
this->inval(nullptr);
|
|
|
|
return;
|
2010-12-20 18:26:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-05 08:04:32 +00:00
|
|
|
if (fSaveToSKP) {
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
|
2016-01-05 08:04:32 +00:00
|
|
|
SkFILEWStream stream("sample_app.skp");
|
|
|
|
picture->serialize(&stream);
|
|
|
|
fSaveToSKP = false;
|
|
|
|
this->inval(nullptr);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-13 19:09:42 +00:00
|
|
|
|
2016-01-08 16:23:19 +00:00
|
|
|
if (fUsePicture) {
|
2017-03-15 01:10:42 +00:00
|
|
|
if (PICTURE_MEANS_PIPE) {
|
2016-09-13 15:09:45 +00:00
|
|
|
fPipeSerializer.endWrite();
|
|
|
|
sk_sp<SkData> data(fPipeStream->detachAsData());
|
|
|
|
fPipeDeserializer.playback(data->data(), data->size(), orig);
|
|
|
|
fPipeStream.reset();
|
|
|
|
} else {
|
|
|
|
sk_sp<SkPicture> picture(fRecorder.finishRecordingAsPicture());
|
2017-03-15 01:10:42 +00:00
|
|
|
if (SERIALIZE_PICTURE) {
|
|
|
|
auto data = picture->serialize();
|
|
|
|
picture = SkPicture::MakeFromData(data.get(), nullptr);
|
|
|
|
}
|
2016-09-13 15:09:45 +00:00
|
|
|
orig->drawPicture(picture.get());
|
2016-01-07 19:28:08 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2011-04-25 14:31:44 +00:00
|
|
|
// Do this after presentGL and other finishing, rather than in afterChild
|
2015-08-11 18:07:07 +00:00
|
|
|
if (fMeasureFPS) {
|
2015-11-09 21:10:30 +00:00
|
|
|
orig->flush();
|
2015-08-11 18:07:07 +00:00
|
|
|
fTimer.end();
|
|
|
|
fMeasureFPS_Time += fTimer.fWall;
|
2011-04-25 14:31:44 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2009-08-14 16:08:38 +00:00
|
|
|
void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
|
|
|
|
if (fRotate) {
|
|
|
|
SkScalar cx = this->width() / 2;
|
|
|
|
SkScalar cy = this->height() / 2;
|
2016-07-12 22:01:19 +00:00
|
|
|
canvas->rotate(gAnimTimer.scaled(10), cx, cy);
|
2009-08-14 16:08:38 +00:00
|
|
|
}
|
2013-07-09 21:58:56 +00:00
|
|
|
|
2011-09-08 18:48:12 +00:00
|
|
|
if (fPerspAnim) {
|
2015-02-02 20:55:02 +00:00
|
|
|
SkScalar secs = gAnimTimer.scaled(1);
|
2011-09-16 18:51:57 +00:00
|
|
|
|
|
|
|
static const SkScalar gAnimPeriod = 10 * SK_Scalar1;
|
|
|
|
static const SkScalar gAnimMag = SK_Scalar1 / 1000;
|
2015-02-02 20:55:02 +00:00
|
|
|
SkScalar t = SkScalarMod(secs, gAnimPeriod);
|
2015-05-12 17:37:34 +00:00
|
|
|
if (SkScalarFloorToInt(secs / gAnimPeriod) & 0x1) {
|
2011-09-16 18:51:57 +00:00
|
|
|
t = gAnimPeriod - t;
|
|
|
|
}
|
|
|
|
t = 2 * t - gAnimPeriod;
|
2015-05-12 17:37:34 +00:00
|
|
|
t *= gAnimMag / gAnimPeriod;
|
2011-09-16 18:51:57 +00:00
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
2014-09-19 20:04:17 +00:00
|
|
|
#if 1
|
2011-09-16 18:51:57 +00:00
|
|
|
m.setPerspY(t);
|
2014-09-19 20:04:17 +00:00
|
|
|
#else
|
|
|
|
m.setPerspY(SK_Scalar1 / 1000);
|
2015-05-12 17:37:34 +00:00
|
|
|
m.setSkewX(8.0f / 25);
|
2014-09-19 20:04:17 +00:00
|
|
|
m.dump();
|
|
|
|
#endif
|
2011-09-08 18:48:12 +00:00
|
|
|
canvas->concat(m);
|
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
if (fMeasureFPS) {
|
2015-08-11 18:07:07 +00:00
|
|
|
(void)SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT);
|
|
|
|
fTimer.start();
|
2011-04-22 14:10:48 +00:00
|
|
|
} else {
|
|
|
|
(void)SampleView::SetRepeatDraw(child, 1);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2013-07-09 21:58:56 +00:00
|
|
|
if (fPerspAnim || fRotate) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-09-08 18:48:12 +00:00
|
|
|
}
|
2009-08-14 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 21:32:38 +00:00
|
|
|
void SampleWindow::changeOffset(SkVector delta) {
|
|
|
|
fOffset += delta;
|
|
|
|
this->updateMatrix();
|
|
|
|
}
|
|
|
|
|
2011-06-13 16:58:40 +00:00
|
|
|
void SampleWindow::changeZoomLevel(float delta) {
|
2013-11-25 19:44:07 +00:00
|
|
|
fZoomLevel += delta;
|
2011-03-21 00:53:39 +00:00
|
|
|
if (fZoomLevel > 0) {
|
2011-06-13 16:58:40 +00:00
|
|
|
fZoomLevel = SkMinScalar(fZoomLevel, MAX_ZOOM_LEVEL);
|
|
|
|
fZoomScale = fZoomLevel + SK_Scalar1;
|
2011-03-21 00:53:39 +00:00
|
|
|
} else if (fZoomLevel < 0) {
|
2011-06-13 16:58:40 +00:00
|
|
|
fZoomLevel = SkMaxScalar(fZoomLevel, MIN_ZOOM_LEVEL);
|
|
|
|
fZoomScale = SK_Scalar1 / (SK_Scalar1 - fZoomLevel);
|
2011-03-21 00:53:39 +00:00
|
|
|
} else {
|
|
|
|
fZoomScale = SK_Scalar1;
|
|
|
|
}
|
2011-11-11 21:42:12 +00:00
|
|
|
this->updateMatrix();
|
|
|
|
}
|
2011-03-21 00:53:39 +00:00
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
void SampleWindow::updateMatrix(){
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
2016-03-03 21:32:38 +00:00
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
if (fZoomLevel) {
|
|
|
|
SkPoint center;
|
|
|
|
//m = this->getLocalMatrix();//.invert(&m);
|
|
|
|
m.mapXY(fZoomCenterX, fZoomCenterY, ¢er);
|
|
|
|
SkScalar cx = center.fX;
|
|
|
|
SkScalar cy = center.fY;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
m.setTranslate(-cx, -cy);
|
|
|
|
m.postScale(fZoomScale, fZoomScale);
|
|
|
|
m.postTranslate(cx, cy);
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2016-03-03 21:32:38 +00:00
|
|
|
m.postTranslate(fOffset.fX, fOffset.fY);
|
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
if (fFlipAxis) {
|
|
|
|
m.preTranslate(fZoomCenterX, fZoomCenterY);
|
|
|
|
if (fFlipAxis & kFlipAxis_X) {
|
|
|
|
m.preScale(-SK_Scalar1, SK_Scalar1);
|
|
|
|
}
|
|
|
|
if (fFlipAxis & kFlipAxis_Y) {
|
|
|
|
m.preScale(SK_Scalar1, -SK_Scalar1);
|
|
|
|
}
|
|
|
|
m.preTranslate(-fZoomCenterX, -fZoomCenterY);
|
|
|
|
//canvas->concat(m);
|
|
|
|
}
|
|
|
|
// Apply any gesture matrix
|
|
|
|
m.preConcat(fGesture.localM());
|
|
|
|
m.preConcat(fGesture.globalM());
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-11-11 21:42:12 +00:00
|
|
|
this->setLocalMatrix(m);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-13 16:58:40 +00:00
|
|
|
this->updateTitle();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-03-21 00:53:39 +00:00
|
|
|
}
|
2011-06-15 16:49:08 +00:00
|
|
|
bool SampleWindow::previousSample() {
|
2011-06-21 16:01:26 +00:00
|
|
|
fCurrIndex = (fCurrIndex - 1 + fSamples.count()) % fSamples.count();
|
2015-01-14 03:43:04 +00:00
|
|
|
this->loadView((*fSamples[fCurrIndex])());
|
2011-06-15 16:49:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-08-19 19:25:40 +00:00
|
|
|
#include "SkResourceCache.h"
|
|
|
|
#include "SkGlyphCache.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleWindow::nextSample() {
|
2009-11-03 04:00:48 +00:00
|
|
|
fCurrIndex = (fCurrIndex + 1) % fSamples.count();
|
2015-01-14 03:43:04 +00:00
|
|
|
this->loadView((*fSamples[fCurrIndex])());
|
2015-08-19 19:25:40 +00:00
|
|
|
|
|
|
|
if (false) {
|
|
|
|
SkResourceCache::TestDumpMemoryStatistics();
|
|
|
|
SkGlyphCache::Dump();
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
|
2009-11-03 04:00:48 +00:00
|
|
|
return true;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2011-06-24 16:04:50 +00:00
|
|
|
bool SampleWindow::goToSample(int i) {
|
|
|
|
fCurrIndex = (i) % fSamples.count();
|
2015-01-14 03:43:04 +00:00
|
|
|
this->loadView((*fSamples[fCurrIndex])());
|
2011-06-24 16:04:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString SampleWindow::getSampleTitle(int i) {
|
2013-07-11 14:28:04 +00:00
|
|
|
return ::getSampleTitle(fSamples[i]);
|
2011-06-24 16:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SampleWindow::sampleCount() {
|
|
|
|
return fSamples.count();
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
void SampleWindow::showOverview() {
|
2015-01-14 03:43:04 +00:00
|
|
|
this->loadView(create_overview(fSamples.count(), fSamples.begin()));
|
2011-08-08 15:37:23 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void SampleWindow::postAnimatingEvent() {
|
|
|
|
if (fAnimating) {
|
2011-08-04 13:50:17 +00:00
|
|
|
(new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATING_DELAY);
|
2011-06-15 16:49:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-08 19:36:00 +00:00
|
|
|
|
2016-09-29 21:37:02 +00:00
|
|
|
static sk_sp<SkColorSpace> getMonitorColorSpace() {
|
|
|
|
#if defined(SK_BUILD_FOR_MAC)
|
|
|
|
CGColorSpaceRef cs = CGDisplayCopyColorSpace(CGMainDisplayID());
|
|
|
|
CFDataRef dataRef = CGColorSpaceCopyICCProfile(cs);
|
|
|
|
const uint8_t* data = CFDataGetBytePtr(dataRef);
|
|
|
|
size_t size = CFDataGetLength(dataRef);
|
|
|
|
|
2016-10-24 13:24:02 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeICC(data, size);
|
2016-09-29 21:37:02 +00:00
|
|
|
|
|
|
|
CFRelease(cs);
|
|
|
|
CFRelease(dataRef);
|
|
|
|
return colorSpace;
|
|
|
|
#elif defined(SK_BUILD_FOR_WIN)
|
|
|
|
DISPLAY_DEVICE dd = { sizeof(DISPLAY_DEVICE) };
|
|
|
|
|
|
|
|
// Chrome's code for this currently just gets the primary monitor's profile. This code iterates
|
|
|
|
// over all attached monitors, so it's "better" in that sense. Making intelligent use of this
|
|
|
|
// information (via things like MonitorFromWindow or MonitorFromRect to pick the correct
|
|
|
|
// profile for a particular window or region of a window), is an exercise left to the reader.
|
|
|
|
for (int i = 0; EnumDisplayDevices(NULL, i, &dd, 0); ++i) {
|
|
|
|
if (dd.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) {
|
|
|
|
// There are other helpful things in dd at this point:
|
|
|
|
// dd.DeviceString has a longer name for the adapter
|
|
|
|
// dd.StateFlags indicates primary display, mirroring, etc...
|
|
|
|
HDC dc = CreateDC(NULL, dd.DeviceName, NULL, NULL);
|
|
|
|
if (dc) {
|
|
|
|
char icmPath[MAX_PATH + 1];
|
|
|
|
DWORD pathLength = MAX_PATH;
|
2016-10-28 14:38:08 +00:00
|
|
|
BOOL success = GetICMProfileA(dc, &pathLength, icmPath);
|
2016-09-29 21:37:02 +00:00
|
|
|
DeleteDC(dc);
|
|
|
|
if (success) {
|
|
|
|
sk_sp<SkData> iccData = SkData::MakeFromFileName(icmPath);
|
2016-10-24 13:24:02 +00:00
|
|
|
return SkColorSpace::MakeICC(iccData->data(), iccData->size());
|
2016-09-29 21:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleWindow::onEvent(const SkEvent& evt) {
|
2011-11-08 15:18:10 +00:00
|
|
|
if (evt.isType(gUpdateWindowTitleEvtName)) {
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
if (evt.isType(ANIMATING_EVENTTYPE)) {
|
|
|
|
if (fAnimating) {
|
|
|
|
this->nextSample();
|
|
|
|
this->postAnimatingEvent();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-03 04:00:48 +00:00
|
|
|
if (evt.isType("set-curr-index")) {
|
2011-08-08 15:37:23 +00:00
|
|
|
this->goToSample(evt.getFast32());
|
2009-11-03 04:00:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-04-22 01:59:09 +00:00
|
|
|
if (isInvalEvent(evt)) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-04-22 01:59:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-02 13:39:12 +00:00
|
|
|
int selected = -1;
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindListIndex(evt, "Device Type", &selected)) {
|
2011-08-02 13:39:12 +00:00
|
|
|
this->setDeviceType((DeviceType)selected);
|
2012-08-01 17:58:01 +00:00
|
|
|
return true;
|
2011-08-02 13:39:12 +00:00
|
|
|
}
|
2016-02-15 15:48:35 +00:00
|
|
|
if (SkOSMenu::FindListIndex(evt, "ColorType", &selected)) {
|
2016-09-29 21:37:02 +00:00
|
|
|
fColorConfigIndex = selected;
|
|
|
|
sk_sp<SkColorSpace> colorSpace = nullptr;
|
|
|
|
switch (gConfig[selected].fColorSpace) {
|
|
|
|
case kSRGB_OutputColorSpace:
|
2017-02-07 18:56:11 +00:00
|
|
|
colorSpace = SkColorSpace::MakeSRGB();
|
2016-09-29 21:37:02 +00:00
|
|
|
break;
|
2016-12-02 17:10:36 +00:00
|
|
|
case kNarrow_OutputColorSpace:
|
|
|
|
{
|
|
|
|
// NarrowGamut RGB (an artifically smaller than sRGB gamut)
|
|
|
|
SkColorSpacePrimaries primaries ={
|
|
|
|
0.54f, 0.33f, // Rx, Ry
|
|
|
|
0.33f, 0.50f, // Gx, Gy
|
|
|
|
0.25f, 0.20f, // Bx, By
|
|
|
|
0.3127f, 0.3290f, // Wx, Wy
|
|
|
|
};
|
|
|
|
SkMatrix44 narrowGamutRGBMatrix(SkMatrix44::kUninitialized_Constructor);
|
|
|
|
primaries.toXYZD50(&narrowGamutRGBMatrix);
|
|
|
|
colorSpace = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
|
|
|
narrowGamutRGBMatrix);
|
|
|
|
}
|
|
|
|
break;
|
2016-09-29 21:37:02 +00:00
|
|
|
case kMonitor_OutputColorSpace:
|
|
|
|
colorSpace = getMonitorColorSpace();
|
|
|
|
if (!colorSpace) {
|
|
|
|
// Fallback for platforms / machines where we can't get a monitor profile
|
2017-02-07 18:56:11 +00:00
|
|
|
colorSpace = SkColorSpace::MakeSRGB();
|
2016-09-29 21:37:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kLegacy_OutputColorSpace:
|
|
|
|
default:
|
|
|
|
// Do nothing
|
|
|
|
break;
|
|
|
|
}
|
2016-08-30 14:07:59 +00:00
|
|
|
if (kRGBA_F16_SkColorType == gConfig[selected].fColorType) {
|
2016-09-29 21:37:02 +00:00
|
|
|
SkASSERT(colorSpace);
|
2016-10-18 17:02:51 +00:00
|
|
|
SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(colorSpace)->type());
|
|
|
|
SkColorSpace_XYZ* csXYZ = static_cast<SkColorSpace_XYZ*>(colorSpace.get());
|
|
|
|
colorSpace = csXYZ->makeLinearGamma();
|
2016-08-30 14:07:59 +00:00
|
|
|
}
|
2016-09-29 21:37:02 +00:00
|
|
|
this->setDeviceColorType(gConfig[selected].fColorType, colorSpace);
|
2016-02-15 15:48:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) {
|
2011-08-02 13:39:12 +00:00
|
|
|
this->toggleSlideshow();
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindTriState(evt, "AA", &fAAState) ||
|
|
|
|
SkOSMenu::FindTriState(evt, "LCD", &fLCDState) ||
|
2015-03-16 17:08:34 +00:00
|
|
|
SkOSMenu::FindListIndex(evt, "FilterQuality", &fFilterQualityIndex) ||
|
2013-06-03 21:26:34 +00:00
|
|
|
SkOSMenu::FindTriState(evt, "Subpixel", &fSubpixelState) ||
|
|
|
|
SkOSMenu::FindListIndex(evt, "Hinting", &fHintingState) ||
|
2011-08-12 14:27:47 +00:00
|
|
|
SkOSMenu::FindSwitchState(evt, "Clip", &fUseClip) ||
|
|
|
|
SkOSMenu::FindSwitchState(evt, "Zoomer", &fShowZoomer) ||
|
2016-06-25 01:14:07 +00:00
|
|
|
SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify))
|
2015-08-05 01:46:38 +00:00
|
|
|
{
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2013-12-10 21:51:06 +00:00
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
2016-03-31 15:30:38 +00:00
|
|
|
if (SkOSMenu::FindListIndex(evt, "Pixel Geometry", &fPixelGeometryIndex)) {
|
|
|
|
this->setPixelGeometry(fPixelGeometryIndex);
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-10 21:51:06 +00:00
|
|
|
if (SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
|
|
|
|
if (SampleView::IsSampleView(curr_view(this))) {
|
|
|
|
((SampleView*)curr_view(this))->onTileSizeChanged(this->tileSize());
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-08-02 13:39:12 +00:00
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Flip X", nullptr)) {
|
2011-08-02 13:39:12 +00:00
|
|
|
fFlipAxis ^= kFlipAxis_X;
|
2011-11-11 21:42:12 +00:00
|
|
|
this->updateMatrix();
|
2011-08-02 13:39:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Flip Y", nullptr)) {
|
2011-08-02 13:39:12 +00:00
|
|
|
fFlipAxis ^= kFlipAxis_Y;
|
2011-11-11 21:42:12 +00:00
|
|
|
this->updateMatrix();
|
2011-08-02 13:39:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindAction(evt,"Save to PDF")) {
|
2011-08-02 13:39:12 +00:00
|
|
|
this->saveToPdf();
|
|
|
|
return true;
|
2012-08-01 17:58:01 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
bool SampleWindow::onQuery(SkEvent* query) {
|
|
|
|
if (query->isType("get-slide-count")) {
|
|
|
|
query->setFast32(fSamples.count());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (query->isType("get-slide-title")) {
|
2011-10-31 14:18:20 +00:00
|
|
|
SkView* view = (*fSamples[query->getFast32()])();
|
2010-12-20 18:26:13 +00:00
|
|
|
SkEvent evt(gTitleEvtName);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
query->setString("title", evt.findString(gTitleEvtName));
|
|
|
|
}
|
|
|
|
SkSafeUnref(view);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (query->isType("use-fast-text")) {
|
|
|
|
SkEvent evt(gFastTextEvtName);
|
|
|
|
return curr_view(this)->doQuery(&evt);
|
|
|
|
}
|
2011-07-06 17:56:47 +00:00
|
|
|
if (query->isType("ignore-window-bitmap")) {
|
2015-08-27 14:41:13 +00:00
|
|
|
query->setFast32(this->getGrContext() != nullptr);
|
2011-07-06 17:56:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-12-20 18:26:13 +00:00
|
|
|
return this->INHERITED::onQuery(query);
|
|
|
|
}
|
|
|
|
|
2014-07-31 12:58:44 +00:00
|
|
|
DECLARE_bool(portableFonts);
|
2014-06-23 18:25:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleWindow::onHandleChar(SkUnichar uni) {
|
2010-12-20 18:26:13 +00:00
|
|
|
{
|
|
|
|
SkView* view = curr_view(this);
|
|
|
|
if (view) {
|
|
|
|
SkEvent evt(gCharEvtName);
|
|
|
|
evt.setFast32(uni);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
int dx = 0xFF;
|
|
|
|
int dy = 0xFF;
|
|
|
|
|
|
|
|
switch (uni) {
|
|
|
|
case '5': dx = 0; dy = 0; break;
|
|
|
|
case '8': dx = 0; dy = -1; break;
|
|
|
|
case '6': dx = 1; dy = 0; break;
|
|
|
|
case '2': dx = 0; dy = 1; break;
|
|
|
|
case '4': dx = -1; dy = 0; break;
|
|
|
|
case '7': dx = -1; dy = -1; break;
|
|
|
|
case '9': dx = 1; dy = -1; break;
|
|
|
|
case '3': dx = 1; dy = 1; break;
|
|
|
|
case '1': dx = -1; dy = 1; break;
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
if (0xFF != dx && 0xFF != dy) {
|
2016-03-03 21:32:38 +00:00
|
|
|
this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)});
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-23 16:49:54 +00:00
|
|
|
switch (uni) {
|
2015-02-02 20:55:02 +00:00
|
|
|
case 27: // ESC
|
|
|
|
gAnimTimer.stop();
|
|
|
|
if (this->sendAnimatePulse()) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2015-02-02 20:55:02 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-04-03 14:52:48 +00:00
|
|
|
case '+':
|
|
|
|
gSampleWindow->setThreads(gSampleWindow->getThreads() + 1);
|
|
|
|
this->inval(nullptr);
|
|
|
|
this->updateTitle();
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
gSampleWindow->setThreads(SkTMax(0, gSampleWindow->getThreads() - 1));
|
|
|
|
this->inval(nullptr);
|
|
|
|
this->updateTitle();
|
|
|
|
break;
|
2015-02-02 03:01:04 +00:00
|
|
|
case ' ':
|
2015-02-02 20:55:02 +00:00
|
|
|
gAnimTimer.togglePauseResume();
|
2015-02-02 03:01:04 +00:00
|
|
|
if (this->sendAnimatePulse()) {
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2015-02-02 03:01:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-10-04 18:23:22 +00:00
|
|
|
case 'A':
|
2017-01-13 15:13:13 +00:00
|
|
|
if (gSkUseAnalyticAA.load() && !gSkForceAnalyticAA.load()) {
|
|
|
|
gSkForceAnalyticAA = true;
|
|
|
|
} else {
|
|
|
|
gSkUseAnalyticAA = !gSkUseAnalyticAA.load();
|
|
|
|
gSkForceAnalyticAA = false;
|
|
|
|
}
|
2016-10-04 18:23:22 +00:00
|
|
|
this->inval(nullptr);
|
2016-10-11 19:20:08 +00:00
|
|
|
this->updateTitle();
|
2016-10-04 18:23:22 +00:00
|
|
|
break;
|
2012-11-15 15:56:38 +00:00
|
|
|
case 'B':
|
2015-08-26 20:07:48 +00:00
|
|
|
post_event_to_sink(new SkEvent("PictFileView::toggleBBox"), curr_view(this));
|
2013-12-11 17:05:23 +00:00
|
|
|
// Cannot call updateTitle() synchronously, because the toggleBBox event is still in
|
|
|
|
// the queue.
|
2015-08-26 20:07:48 +00:00
|
|
|
post_event_to_sink(new SkEvent(gUpdateWindowTitleEvtName), this);
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2012-11-15 15:56:38 +00:00
|
|
|
break;
|
2014-10-06 19:29:56 +00:00
|
|
|
case 'D':
|
|
|
|
toggleDistanceFieldFonts();
|
|
|
|
break;
|
2016-07-08 15:43:27 +00:00
|
|
|
case 'E':
|
|
|
|
fUseDeferredCanvas = !fUseDeferredCanvas;
|
|
|
|
this->inval(nullptr);
|
|
|
|
break;
|
2011-08-12 14:27:47 +00:00
|
|
|
case 'f':
|
2012-08-01 17:58:01 +00:00
|
|
|
// only
|
2011-11-07 15:43:57 +00:00
|
|
|
toggleFPS();
|
2011-08-12 14:27:47 +00:00
|
|
|
break;
|
2014-06-23 18:25:00 +00:00
|
|
|
case 'F':
|
2014-07-31 12:58:44 +00:00
|
|
|
FLAGS_portableFonts ^= true;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2014-06-23 18:25:00 +00:00
|
|
|
break;
|
2010-12-20 18:26:13 +00:00
|
|
|
case 'g':
|
|
|
|
fRequestGrabImage = true;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2012-11-15 15:56:38 +00:00
|
|
|
break;
|
|
|
|
case 'G':
|
|
|
|
gShowGMBounds = !gShowGMBounds;
|
2013-12-11 17:05:23 +00:00
|
|
|
post_event_to_sink(GMSampleView::NewShowSizeEvt(gShowGMBounds),
|
2012-11-15 15:56:38 +00:00
|
|
|
curr_view(this));
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2010-12-20 18:26:13 +00:00
|
|
|
break;
|
2011-04-22 01:59:09 +00:00
|
|
|
case 'i':
|
|
|
|
this->zoomIn();
|
|
|
|
break;
|
2011-03-22 14:03:21 +00:00
|
|
|
case 'o':
|
|
|
|
this->zoomOut();
|
|
|
|
break;
|
2011-04-22 01:59:09 +00:00
|
|
|
case 'r':
|
|
|
|
fRotate = !fRotate;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-04-22 01:59:09 +00:00
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2011-09-08 18:48:12 +00:00
|
|
|
case 'k':
|
|
|
|
fPerspAnim = !fPerspAnim;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-09-08 18:48:12 +00:00
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2015-08-05 01:46:38 +00:00
|
|
|
case 'K':
|
|
|
|
fSaveToSKP = true;
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2015-08-05 01:46:38 +00:00
|
|
|
return true;
|
2016-01-05 08:04:32 +00:00
|
|
|
case 'M':
|
2016-01-08 16:23:19 +00:00
|
|
|
fUsePicture = !fUsePicture;
|
2016-01-05 08:04:32 +00:00
|
|
|
this->inval(nullptr);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-01-27 19:12:00 +00:00
|
|
|
case 'p':
|
|
|
|
{
|
|
|
|
GrContext* grContext = this->getGrContext();
|
|
|
|
if (grContext) {
|
2014-05-09 14:29:32 +00:00
|
|
|
size_t cacheBytes;
|
2015-08-27 14:41:13 +00:00
|
|
|
grContext->getResourceCacheUsage(nullptr, &cacheBytes);
|
2012-01-27 19:12:00 +00:00
|
|
|
grContext->freeGpuResources();
|
2014-05-09 14:29:32 +00:00
|
|
|
SkDebugf("Purged %d bytes from the GPU resource cache.\n", cacheBytes);
|
2012-01-27 19:12:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2008-12-23 16:49:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-04-18 14:07:57 +00:00
|
|
|
if (fAppMenu->handleKeyEquivalent(uni)|| fSlideMenu->handleKeyEquivalent(uni)) {
|
|
|
|
this->onUpdateMenu(fAppMenu);
|
|
|
|
this->onUpdateMenu(fSlideMenu);
|
2011-08-08 15:37:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->INHERITED::onHandleChar(uni);
|
|
|
|
}
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
void SampleWindow::setDeviceType(DeviceType type) {
|
2012-04-02 19:24:21 +00:00
|
|
|
if (type == fDeviceType)
|
|
|
|
return;
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
fDevManager->tearDownBackend(this);
|
|
|
|
fDeviceType = type;
|
2017-02-22 19:00:42 +00:00
|
|
|
fDevManager->setUpBackend(this, fBackendOptions);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-02-15 15:48:35 +00:00
|
|
|
this->updateTitle();
|
|
|
|
this->inval(nullptr);
|
|
|
|
}
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2016-06-16 20:03:24 +00:00
|
|
|
void SampleWindow::setDeviceColorType(SkColorType ct, sk_sp<SkColorSpace> cs) {
|
|
|
|
this->setColorType(ct, std::move(cs));
|
2016-02-15 15:48:35 +00:00
|
|
|
|
|
|
|
fDevManager->tearDownBackend(this);
|
2017-02-22 19:00:42 +00:00
|
|
|
fDevManager->setUpBackend(this, fBackendOptions);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
this->updateTitle();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-08-02 13:39:12 +00:00
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void SampleWindow::toggleSlideshow() {
|
|
|
|
fAnimating = !fAnimating;
|
|
|
|
this->postAnimatingEvent();
|
|
|
|
this->updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleWindow::toggleRendering() {
|
2012-04-02 19:24:21 +00:00
|
|
|
this->setDeviceType(cycle_devicetype(fDeviceType));
|
2011-06-15 16:49:08 +00:00
|
|
|
this->updateTitle();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-06-15 16:49:08 +00:00
|
|
|
}
|
|
|
|
|
2011-11-07 15:43:57 +00:00
|
|
|
void SampleWindow::toggleFPS() {
|
|
|
|
fMeasureFPS = !fMeasureFPS;
|
|
|
|
this->updateTitle();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-11-07 15:43:57 +00:00
|
|
|
}
|
|
|
|
|
2014-10-06 19:29:56 +00:00
|
|
|
void SampleWindow::toggleDistanceFieldFonts() {
|
2015-11-08 16:07:24 +00:00
|
|
|
// reset backend
|
|
|
|
fDevManager->tearDownBackend(this);
|
2017-02-22 19:00:42 +00:00
|
|
|
fDevManager->setUpBackend(this, fBackendOptions);
|
2015-11-08 16:07:24 +00:00
|
|
|
|
2014-10-06 19:29:56 +00:00
|
|
|
SkSurfaceProps props = this->getSurfaceProps();
|
2015-08-31 19:39:41 +00:00
|
|
|
uint32_t flags = props.flags() ^ SkSurfaceProps::kUseDeviceIndependentFonts_Flag;
|
2014-10-06 19:29:56 +00:00
|
|
|
this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry()));
|
|
|
|
|
|
|
|
this->updateTitle();
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2014-10-06 19:29:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 15:30:38 +00:00
|
|
|
void SampleWindow::setPixelGeometry(int pixelGeometryIndex) {
|
|
|
|
// reset backend
|
|
|
|
fDevManager->tearDownBackend(this);
|
2017-02-22 19:00:42 +00:00
|
|
|
fDevManager->setUpBackend(this, fBackendOptions);
|
2016-03-31 15:30:38 +00:00
|
|
|
|
|
|
|
const SkSurfaceProps& oldProps = this->getSurfaceProps();
|
|
|
|
SkSurfaceProps newProps(oldProps.flags(), SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
if (pixelGeometryIndex > 0) {
|
|
|
|
newProps = SkSurfaceProps(oldProps.flags(),
|
|
|
|
gPixelGeometryStates[pixelGeometryIndex].pixelGeometry);
|
|
|
|
}
|
|
|
|
this->setSurfaceProps(newProps);
|
|
|
|
|
|
|
|
this->updateTitle();
|
|
|
|
this->inval(nullptr);
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkDumpCanvas.h"
|
|
|
|
|
|
|
|
bool SampleWindow::onHandleKey(SkKey key) {
|
2010-12-20 18:26:13 +00:00
|
|
|
{
|
|
|
|
SkView* view = curr_view(this);
|
|
|
|
if (view) {
|
|
|
|
SkEvent evt(gKeyEvtName);
|
|
|
|
evt.setFast32(key);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-03 21:32:38 +00:00
|
|
|
|
|
|
|
int dx = 0xFF;
|
|
|
|
int dy = 0xFF;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
switch (key) {
|
|
|
|
case kRight_SkKey:
|
|
|
|
if (this->nextSample()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kLeft_SkKey:
|
2012-08-15 20:03:06 +00:00
|
|
|
if (this->previousSample()) {
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
case kUp_SkKey:
|
2015-02-21 17:03:20 +00:00
|
|
|
this->changeZoomLevel(1.f / 32.f);
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
case kDown_SkKey:
|
2015-02-21 17:03:20 +00:00
|
|
|
this->changeZoomLevel(-1.f / 32.f);
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
2011-12-27 22:33:50 +00:00
|
|
|
case kOK_SkKey: {
|
|
|
|
SkString title;
|
|
|
|
if (curr_title(this, &title)) {
|
|
|
|
writeTitleToPrefs(title.c_str());
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
2011-12-27 22:33:50 +00:00
|
|
|
}
|
2009-11-03 04:00:48 +00:00
|
|
|
case kBack_SkKey:
|
2011-08-08 15:37:23 +00:00
|
|
|
this->showOverview();
|
2009-11-03 04:00:48 +00:00
|
|
|
return true;
|
2016-03-03 21:32:38 +00:00
|
|
|
|
|
|
|
case k5_SkKey: dx = 0; dy = 0; break;
|
|
|
|
case k8_SkKey: dx = 0; dy = -1; break;
|
|
|
|
case k6_SkKey: dx = 1; dy = 0; break;
|
|
|
|
case k2_SkKey: dx = 0; dy = 1; break;
|
|
|
|
case k4_SkKey: dx = -1; dy = 0; break;
|
|
|
|
case k7_SkKey: dx = -1; dy = -1; break;
|
|
|
|
case k9_SkKey: dx = 1; dy = -1; break;
|
|
|
|
case k3_SkKey: dx = 1; dy = 1; break;
|
|
|
|
case k1_SkKey: dx = -1; dy = 1; break;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-03-03 21:32:38 +00:00
|
|
|
|
|
|
|
if (0xFF != dx && 0xFF != dy) {
|
|
|
|
this->changeOffset({SkIntToScalar(dx / 32.0f), SkIntToScalar(dy / 32.0f)});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
return this->INHERITED::onHandleKey(key);
|
|
|
|
}
|
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const char gGestureClickType[] = "GestureClickType";
|
|
|
|
|
2011-06-22 13:26:56 +00:00
|
|
|
bool SampleWindow::onDispatchClick(int x, int y, Click::State state,
|
2013-01-08 16:17:50 +00:00
|
|
|
void* owner, unsigned modi) {
|
2011-03-24 18:35:50 +00:00
|
|
|
if (Click::kMoved_State == state) {
|
|
|
|
updatePointer(x, y);
|
|
|
|
}
|
2013-12-17 19:22:07 +00:00
|
|
|
int w = SkScalarRoundToInt(this->width());
|
|
|
|
int h = SkScalarRoundToInt(this->height());
|
2011-03-21 00:53:39 +00:00
|
|
|
|
|
|
|
// check for the resize-box
|
|
|
|
if (w - x < 16 && h - y < 16) {
|
|
|
|
return false; // let the OS handle the click
|
2012-08-01 17:58:01 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
else if (fMagnify) {
|
|
|
|
//it's only necessary to update the drawing if there's a click
|
2015-08-27 14:41:13 +00:00
|
|
|
this->inval(nullptr);
|
2011-08-08 15:37:23 +00:00
|
|
|
return false; //prevent dragging while magnify is enabled
|
2013-01-08 16:17:50 +00:00
|
|
|
} else {
|
|
|
|
// capture control+option, and trigger debugger
|
|
|
|
if ((modi & kControl_SkModifierKey) && (modi & kOption_SkModifierKey)) {
|
|
|
|
if (Click::kDown_State == state) {
|
|
|
|
SkEvent evt("debug-hit-test");
|
|
|
|
evt.setS32("debug-hit-test-x", x);
|
|
|
|
evt.setS32("debug-hit-test-y", y);
|
|
|
|
curr_view(this)->doEvent(evt);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
|
|
|
|
}
|
2011-03-21 00:53:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
class GestureClick : public SkView::Click {
|
|
|
|
public:
|
|
|
|
GestureClick(SkView* target) : SkView::Click(target) {
|
|
|
|
this->setType(gGestureClickType);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsGesture(Click* click) {
|
|
|
|
return click->isType(gGestureClickType);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-08 16:17:50 +00:00
|
|
|
SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y,
|
|
|
|
unsigned modi) {
|
2011-03-16 12:10:02 +00:00
|
|
|
return new GestureClick(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleWindow::onClick(Click* click) {
|
|
|
|
if (GestureClick::IsGesture(click)) {
|
2011-12-12 18:34:01 +00:00
|
|
|
float x = static_cast<float>(click->fICurr.fX);
|
|
|
|
float y = static_cast<float>(click->fICurr.fY);
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
switch (click->fState) {
|
|
|
|
case SkView::Click::kDown_State:
|
2011-06-22 13:26:56 +00:00
|
|
|
fGesture.touchBegin(click->fOwner, x, y);
|
2011-03-16 12:10:02 +00:00
|
|
|
break;
|
|
|
|
case SkView::Click::kMoved_State:
|
2011-06-22 13:26:56 +00:00
|
|
|
fGesture.touchMoved(click->fOwner, x, y);
|
2011-11-11 21:42:12 +00:00
|
|
|
this->updateMatrix();
|
2011-03-16 12:10:02 +00:00
|
|
|
break;
|
|
|
|
case SkView::Click::kUp_State:
|
2011-06-22 13:26:56 +00:00
|
|
|
fGesture.touchEnd(click->fOwner);
|
2011-11-11 21:42:12 +00:00
|
|
|
this->updateMatrix();
|
2011-03-16 12:10:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
void SampleWindow::loadView(SkView* view) {
|
|
|
|
SkView::F2BIter iter(this);
|
|
|
|
SkView* prev = iter.next();
|
|
|
|
if (prev) {
|
|
|
|
prev->detachFromParent();
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
view->setVisibleP(true);
|
2010-12-20 18:26:13 +00:00
|
|
|
view->setClipToBounds(false);
|
2008-12-17 15:59:43 +00:00
|
|
|
this->attachChildToFront(view)->unref();
|
|
|
|
view->setSize(this->width(), this->height());
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
//repopulate the slide menu when a view is loaded
|
2012-04-18 14:07:57 +00:00
|
|
|
fSlideMenu->reset();
|
2013-01-17 13:20:01 +00:00
|
|
|
|
2012-04-18 14:07:57 +00:00
|
|
|
this->onUpdateMenu(fSlideMenu);
|
2008-12-17 15:59:43 +00:00
|
|
|
this->updateTitle();
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
static const char* gDeviceTypePrefix[] = {
|
2008-12-17 15:59:43 +00:00
|
|
|
"raster: ",
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-27 20:44:19 +00:00
|
|
|
"opengl: ",
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
"angle: ",
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
#endif // SK_SUPPORT_GPU
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2015-08-20 14:57:51 +00:00
|
|
|
static_assert(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt,
|
|
|
|
"array_size_mismatch");
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
static const char* trystate_str(SkOSMenu::TriState state,
|
2011-04-05 13:07:03 +00:00
|
|
|
const char trueStr[], const char falseStr[]) {
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::kOnState == state) {
|
2011-04-05 13:07:03 +00:00
|
|
|
return trueStr;
|
2011-08-08 15:37:23 +00:00
|
|
|
} else if (SkOSMenu::kOffState == state) {
|
2011-04-05 13:07:03 +00:00
|
|
|
return falseStr;
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2011-04-05 13:07:03 +00:00
|
|
|
}
|
|
|
|
|
2014-10-08 18:10:51 +00:00
|
|
|
bool SampleWindow::getRawTitle(SkString* title) {
|
|
|
|
return curr_title(this, title);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-10-08 18:10:51 +00:00
|
|
|
void SampleWindow::updateTitle() {
|
2011-12-27 22:33:50 +00:00
|
|
|
SkString title;
|
2014-10-08 18:10:51 +00:00
|
|
|
if (!this->getRawTitle(&title)) {
|
2008-12-17 15:59:43 +00:00
|
|
|
title.set("<unknown>");
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
title.prepend(gDeviceTypePrefix[fDeviceType]);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-04-03 14:52:48 +00:00
|
|
|
if (gSampleWindow->getThreads()) {
|
|
|
|
title.prependf("[T%d] ", gSampleWindow->getThreads());
|
|
|
|
}
|
|
|
|
|
2016-10-11 19:20:08 +00:00
|
|
|
if (gSkUseAnalyticAA) {
|
2017-01-13 15:13:13 +00:00
|
|
|
if (gSkForceAnalyticAA) {
|
|
|
|
title.prepend("<FAAA> ");
|
|
|
|
} else {
|
|
|
|
title.prepend("<AAA> ");
|
|
|
|
}
|
2016-10-11 19:20:08 +00:00
|
|
|
}
|
2013-12-06 20:14:55 +00:00
|
|
|
if (fTilingMode != kNo_Tiling) {
|
|
|
|
title.prependf("<T: %s> ", gTilingInfo[fTilingMode].label);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
if (fAnimating) {
|
|
|
|
title.prepend("<A> ");
|
|
|
|
}
|
2009-08-14 16:08:38 +00:00
|
|
|
if (fRotate) {
|
|
|
|
title.prepend("<R> ");
|
|
|
|
}
|
2011-09-08 18:48:12 +00:00
|
|
|
if (fPerspAnim) {
|
|
|
|
title.prepend("<K> ");
|
|
|
|
}
|
2015-08-31 19:39:41 +00:00
|
|
|
if (this->getSurfaceProps().flags() & SkSurfaceProps::kUseDeviceIndependentFonts_Flag) {
|
|
|
|
title.prepend("<DIF> ");
|
2014-10-06 19:29:56 +00:00
|
|
|
}
|
2016-01-08 16:23:19 +00:00
|
|
|
if (fUsePicture) {
|
|
|
|
title.prepend("<P> ");
|
2016-01-05 08:04:32 +00:00
|
|
|
}
|
2016-07-08 15:43:27 +00:00
|
|
|
if (fUseDeferredCanvas) {
|
|
|
|
title.prepend("<E> ");
|
|
|
|
}
|
2011-04-05 13:07:03 +00:00
|
|
|
|
|
|
|
title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
|
|
|
|
title.prepend(trystate_str(fAAState, "AA ", "aa "));
|
2015-03-16 17:08:34 +00:00
|
|
|
title.prepend(gFilterQualityStates[fFilterQualityIndex].fLabel);
|
2013-06-03 21:26:34 +00:00
|
|
|
title.prepend(trystate_str(fSubpixelState, "S ", "s "));
|
2015-08-27 14:41:13 +00:00
|
|
|
title.prepend(fFlipAxis & kFlipAxis_X ? "X " : nullptr);
|
|
|
|
title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : nullptr);
|
2013-06-03 21:26:34 +00:00
|
|
|
title.prepend(gHintingStates[fHintingState].label);
|
2016-03-31 15:30:38 +00:00
|
|
|
title.prepend(gPixelGeometryStates[fPixelGeometryIndex].label);
|
2011-03-21 00:53:39 +00:00
|
|
|
|
2016-03-03 21:32:38 +00:00
|
|
|
if (fOffset.fX || fOffset.fY) {
|
|
|
|
title.prependf("(%.2f, %.2f) ", SkScalarToFloat(fOffset.fX), SkScalarToFloat(fOffset.fY));
|
|
|
|
}
|
2011-03-21 00:53:39 +00:00
|
|
|
if (fZoomLevel) {
|
2011-06-13 16:58:40 +00:00
|
|
|
title.prependf("{%.2f} ", SkScalarToFloat(fZoomLevel));
|
2011-03-21 00:53:39 +00:00
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
if (fMeasureFPS) {
|
2015-08-11 18:07:07 +00:00
|
|
|
title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2014-10-08 18:10:51 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-01-24 20:47:18 +00:00
|
|
|
if (IsGpuDeviceType(fDeviceType) &&
|
2014-09-05 20:34:00 +00:00
|
|
|
fDevManager &&
|
2016-07-28 22:17:34 +00:00
|
|
|
fDevManager->numColorSamples() > 0) {
|
2012-04-06 20:13:38 +00:00
|
|
|
title.appendf(" [MSAA: %d]",
|
2016-07-28 22:17:34 +00:00
|
|
|
fDevManager->numColorSamples());
|
2012-04-06 20:13:38 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-04-06 20:13:38 +00:00
|
|
|
|
2016-09-29 21:37:02 +00:00
|
|
|
title.appendf(" %s", gConfig[fColorConfigIndex].fName);
|
2016-02-15 15:48:35 +00:00
|
|
|
|
2016-05-05 19:24:31 +00:00
|
|
|
if (fDevManager && fDevManager->getColorBits() > 24) {
|
|
|
|
title.appendf(" %d bpc", fDevManager->getColorBits());
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
this->setTitle(title.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleWindow::onSizeChange() {
|
|
|
|
this->INHERITED::onSizeChange();
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkView::F2BIter iter(this);
|
|
|
|
SkView* view = iter.next();
|
|
|
|
view->setSize(this->width(), this->height());
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
// rebuild our clippath
|
|
|
|
{
|
|
|
|
const SkScalar W = this->width();
|
|
|
|
const SkScalar H = this->height();
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fClipPath.reset();
|
|
|
|
#if 0
|
|
|
|
for (SkScalar y = SK_Scalar1; y < H; y += SkIntToScalar(32)) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(SK_Scalar1, y, SkIntToScalar(30), y + SkIntToScalar(30));
|
|
|
|
for (; r.fLeft < W; r.offset(SkIntToScalar(32), 0))
|
|
|
|
fClipPath.addRect(r);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
SkRect r;
|
|
|
|
r.set(0, 0, W, H);
|
|
|
|
fClipPath.addRect(r, SkPath::kCCW_Direction);
|
|
|
|
r.set(W/4, H/4, W*3/4, H*3/4);
|
|
|
|
fClipPath.addRect(r, SkPath::kCW_Direction);
|
|
|
|
#endif
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
fZoomCenterX = SkScalarHalf(this->width());
|
|
|
|
fZoomCenterY = SkScalarHalf(this->height());
|
|
|
|
|
2011-11-08 19:00:26 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2011-06-17 13:53:05 +00:00
|
|
|
// FIXME: The first draw after a size change does not work on Android, so
|
|
|
|
// we post an invalidate.
|
2011-06-21 16:01:26 +00:00
|
|
|
this->postInvalDelay();
|
2011-06-16 14:00:15 +00:00
|
|
|
#endif
|
2008-12-17 15:59:43 +00:00
|
|
|
this->updateTitle(); // to refresh our config
|
2011-07-14 14:30:46 +00:00
|
|
|
fDevManager->windowSizeChanged(this);
|
2013-12-10 21:51:06 +00:00
|
|
|
|
|
|
|
if (fTilingMode != kNo_Tiling && SampleView::IsSampleView(view)) {
|
|
|
|
((SampleView*)view)->onTileSizeChanged(this->tileSize());
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
template <typename T> void SkTBSort(T array[], int count) {
|
|
|
|
for (int i = 1; i < count - 1; i++) {
|
|
|
|
bool didSwap = false;
|
|
|
|
for (int j = count - 1; j > i; --j) {
|
|
|
|
if (array[j] < array[j-1]) {
|
|
|
|
T tmp(array[j-1]);
|
|
|
|
array[j-1] = array[j];
|
|
|
|
array[j] = tmp;
|
|
|
|
didSwap = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!didSwap) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
for (int k = 0; k < count - 1; k++) {
|
|
|
|
SkASSERT(!(array[k+1] < array[k]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkRandom.h"
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
static void rand_rect(SkIRect* rect, SkRandom& rand) {
|
2010-12-20 18:26:13 +00:00
|
|
|
int bits = 8;
|
|
|
|
int shift = 32 - bits;
|
|
|
|
rect->set(rand.nextU() >> shift, rand.nextU() >> shift,
|
|
|
|
rand.nextU() >> shift, rand.nextU() >> shift);
|
|
|
|
rect->sort();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dumpRect(const SkIRect& r) {
|
|
|
|
SkDebugf(" { %d, %d, %d, %d },\n",
|
|
|
|
r.fLeft, r.fTop,
|
|
|
|
r.fRight, r.fBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_rects(const SkIRect rect[], int count) {
|
|
|
|
SkRegion rgn0, rgn1;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
rgn0.op(rect[i], SkRegion::kUnion_Op);
|
|
|
|
// dumpRect(rect[i]);
|
|
|
|
}
|
|
|
|
rgn1.setRects(rect, count);
|
|
|
|
|
|
|
|
if (rgn0 != rgn1) {
|
|
|
|
SkDebugf("\n");
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
dumpRect(rect[i]);
|
|
|
|
}
|
|
|
|
SkDebugf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test() {
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
const SkIRect r0[] = {
|
|
|
|
{ 0, 0, 1, 1 },
|
|
|
|
{ 2, 2, 3, 3 },
|
|
|
|
};
|
|
|
|
const SkIRect r1[] = {
|
|
|
|
{ 0, 0, 1, 3 },
|
|
|
|
{ 1, 1, 2, 2 },
|
|
|
|
{ 2, 0, 3, 3 },
|
|
|
|
};
|
|
|
|
const SkIRect r2[] = {
|
|
|
|
{ 0, 0, 1, 2 },
|
|
|
|
{ 2, 1, 3, 3 },
|
|
|
|
{ 4, 0, 5, 1 },
|
|
|
|
{ 6, 0, 7, 4 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
const SkIRect* fRects;
|
|
|
|
int fCount;
|
|
|
|
} gRecs[] = {
|
|
|
|
{ r0, SK_ARRAY_COUNT(r0) },
|
|
|
|
{ r1, SK_ARRAY_COUNT(r1) },
|
|
|
|
{ r2, SK_ARRAY_COUNT(r2) },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < SK_ARRAY_COUNT(gRecs); i++) {
|
|
|
|
test_rects(gRecs[i].fRects, gRecs[i].fCount);
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2010-12-20 18:26:13 +00:00
|
|
|
for (i = 0; i < 10000; i++) {
|
|
|
|
SkRegion rgn0, rgn1;
|
|
|
|
|
|
|
|
const int N = 8;
|
|
|
|
SkIRect rect[N];
|
|
|
|
for (int j = 0; j < N; j++) {
|
|
|
|
rand_rect(&rect[j], rand);
|
|
|
|
}
|
|
|
|
test_rects(rect, N);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
// FIXME: this should be in a header
|
|
|
|
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
|
2011-06-28 19:44:03 +00:00
|
|
|
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
|
2012-06-06 12:09:51 +00:00
|
|
|
if (false) { // avoid bit rot, suppress warning
|
|
|
|
test();
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
return new SampleWindow(hwnd, argc, argv, nullptr);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
// FIXME: this should be in a header
|
|
|
|
void get_preferred_size(int* x, int* y, int* width, int* height);
|
2008-12-17 15:59:43 +00:00
|
|
|
void get_preferred_size(int* x, int* y, int* width, int* height) {
|
|
|
|
*x = 10;
|
|
|
|
*y = 50;
|
|
|
|
*width = 640;
|
|
|
|
*height = 480;
|
|
|
|
}
|
|
|
|
|
2012-10-02 18:33:14 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
2014-10-22 20:06:00 +00:00
|
|
|
#include "SkApplication.h"
|
2014-07-22 17:15:34 +00:00
|
|
|
IOS_launch_type set_cmd_line_args(int , char *[], const char* resourceDir) {
|
2014-07-18 17:58:56 +00:00
|
|
|
SetResourcePath(resourceDir);
|
2014-07-22 17:15:34 +00:00
|
|
|
return kApplication__iOSLaunchType;
|
2012-10-02 18:33:14 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
void application_init() {
|
|
|
|
// setenv("ANDROID_ROOT", "../../../data", 0);
|
2009-12-18 21:33:39 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2008-12-17 15:59:43 +00:00
|
|
|
setenv("ANDROID_ROOT", "/android/device/data", 0);
|
2009-12-18 21:33:39 +00:00
|
|
|
#endif
|
2011-01-05 16:34:41 +00:00
|
|
|
SkGraphics::Init();
|
|
|
|
SkEvent::Init();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void application_term() {
|
2011-01-05 16:34:41 +00:00
|
|
|
SkEvent::Term();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|