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.
|
|
|
|
*/
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SampleApp.h"
|
|
|
|
|
2011-06-24 19:12:12 +00:00
|
|
|
#include "SkData.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkDevice.h"
|
|
|
|
#include "SkGraphics.h"
|
2013-04-30 02:32:41 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2009-01-06 20:16:26 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkStream.h"
|
2013-07-11 14:28:04 +00:00
|
|
|
#include "SkTSort.h"
|
2009-11-23 21:07:51 +00:00
|
|
|
#include "SkTime.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkWindow.h"
|
|
|
|
|
|
|
|
#include "SampleCode.h"
|
2011-03-24 18:35:50 +00:00
|
|
|
#include "SkTypeface.h"
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-02-14 15:11:59 +00:00
|
|
|
#include "gl/GrGLInterface.h"
|
2012-05-07 17:09:37 +00:00
|
|
|
#include "gl/GrGLUtil.h"
|
2011-08-17 13:42:46 +00:00
|
|
|
#include "GrRenderTarget.h"
|
2012-08-02 14:03:32 +00:00
|
|
|
#include "GrContext.h"
|
|
|
|
#include "SkGpuDevice.h"
|
|
|
|
#else
|
|
|
|
class GrContext;
|
|
|
|
#endif
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
#include "SkOSFile.h"
|
2011-06-21 14:44:57 +00:00
|
|
|
#include "SkPDFDevice.h"
|
|
|
|
#include "SkPDFDocument.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
#include "SkGPipe.h"
|
|
|
|
#include "SamplePipeControllers.h"
|
2012-09-18 01:52:20 +00:00
|
|
|
#include "OverView.h"
|
2012-09-14 18:42:01 +00:00
|
|
|
#include "TransitionView.h"
|
2012-06-08 15:35:03 +00:00
|
|
|
|
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) {}
|
|
|
|
virtual SkView* operator() () const SK_OVERRIDE {
|
|
|
|
return CreateSamplePictFileView(fFilename.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) {}
|
|
|
|
virtual SkView* operator() () const SK_OVERRIDE {
|
|
|
|
return CreateSamplePdfFileViewer(fFilename.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
#define PIPE_FILEx
|
|
|
|
#ifdef PIPE_FILE
|
2011-06-01 18:03:34 +00:00
|
|
|
#define FILE_PATH "/path/to/drawing.data"
|
|
|
|
#endif
|
|
|
|
|
2011-08-08 16:02:51 +00:00
|
|
|
#define PIPE_NETx
|
2011-08-08 15:37:23 +00:00
|
|
|
#ifdef PIPE_NET
|
|
|
|
#include "SkSockets.h"
|
|
|
|
SkTCPServer gServer;
|
|
|
|
#endif
|
2011-08-12 14:27:47 +00:00
|
|
|
|
2014-04-29 16:25:36 +00:00
|
|
|
#define USE_ARROWS_FOR_ZOOM false
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
#if SK_ANGLE
|
|
|
|
//#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();
|
|
|
|
}
|
|
|
|
|
2011-12-27 22:33:50 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const char* skip_until(const char* str, const char* skip) {
|
|
|
|
if (!str) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return strstr(str, skip);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* skip_past(const char* str, const char* skip) {
|
|
|
|
const char* found = skip_until(str, skip);
|
|
|
|
if (!found) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
fCurContext = NULL;
|
|
|
|
fCurIntf = NULL;
|
|
|
|
fCurRenderTarget = NULL;
|
|
|
|
fMSAASampleCount = 0;
|
|
|
|
#endif
|
|
|
|
fBackend = kNone_BackEndType;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DefaultDeviceManager() {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
SkSafeUnref(fCurIntf);
|
|
|
|
SkSafeUnref(fCurRenderTarget);
|
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
|
|
|
virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) {
|
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()) {
|
|
|
|
case kRaster_DeviceType:
|
|
|
|
// fallthrough
|
|
|
|
case kPicture_DeviceType:
|
|
|
|
// fallthrough
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
// fallthrough
|
|
|
|
case kNullGPU_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;
|
|
|
|
bool result = win->attach(fBackend, msaaSampleCount, &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
|
|
|
}
|
2012-04-06 20:13:38 +00:00
|
|
|
fMSAASampleCount = msaaSampleCount;
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
SkASSERT(NULL == fCurIntf);
|
2014-01-24 20:49:44 +00:00
|
|
|
SkAutoTUnref<const GrGLInterface> glInterface;
|
2012-04-02 19:24:21 +00:00
|
|
|
switch (win->getDeviceType()) {
|
|
|
|
case kRaster_DeviceType:
|
|
|
|
// fallthrough
|
|
|
|
case kPicture_DeviceType:
|
|
|
|
// fallthrough
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
// all these guys use the native interface
|
2014-01-24 20:49:44 +00:00
|
|
|
glInterface.reset(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:
|
2014-01-24 20:49:44 +00:00
|
|
|
glInterface.reset(GrGLCreateANGLEInterface());
|
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
|
|
|
case kNullGPU_DeviceType:
|
2014-01-24 20:49:44 +00:00
|
|
|
glInterface.reset(GrGLCreateNullInterface());
|
2012-04-02 19:24:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2011-09-16 18:51:57 +00:00
|
|
|
}
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2014-01-24 20:49:44 +00:00
|
|
|
// Currently SampleApp does not use NVPR. TODO: Provide an NVPR device type that is skipped
|
|
|
|
// when the driver doesn't support NVPR.
|
|
|
|
fCurIntf = GrGLInterfaceRemoveNVPR(glInterface.get());
|
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
SkASSERT(NULL == fCurContext);
|
2012-10-25 18:43:28 +00:00
|
|
|
fCurContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext) fCurIntf);
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
if (NULL == fCurContext || NULL == fCurIntf) {
|
|
|
|
// We need some context and interface to see results
|
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
SkSafeUnref(fCurIntf);
|
2014-01-24 20:49:44 +00:00
|
|
|
fCurContext = NULL;
|
|
|
|
fCurIntf = NULL;
|
2011-07-14 14:30:46 +00:00
|
|
|
SkDebugf("Failed to setup 3D");
|
2012-04-02 19:24:21 +00:00
|
|
|
|
|
|
|
win->detach();
|
2011-10-27 20:44:19 +00:00
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
// call windowSizeChanged to create the render target
|
2012-08-02 14:03:32 +00:00
|
|
|
this->windowSizeChanged(win);
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual void tearDownBackend(SampleWindow *win) {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
SkSafeUnref(fCurContext);
|
|
|
|
fCurContext = NULL;
|
|
|
|
|
|
|
|
SkSafeUnref(fCurIntf);
|
|
|
|
fCurIntf = NULL;
|
|
|
|
|
|
|
|
SkSafeUnref(fCurRenderTarget);
|
|
|
|
fCurRenderTarget = NULL;
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-04-10 15:56:29 +00:00
|
|
|
win->detach();
|
|
|
|
fBackend = kNone_BackEndType;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
|
2012-10-01 20:31:56 +00:00
|
|
|
virtual SkCanvas* createCanvas(SampleWindow::DeviceType dType,
|
|
|
|
SampleWindow* win) {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-01-24 20:47:18 +00:00
|
|
|
if (IsGpuDeviceType(dType) && NULL != fCurContext) {
|
2013-08-29 11:54:56 +00:00
|
|
|
SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(fCurContext, fCurRenderTarget));
|
2013-01-24 20:47:18 +00:00
|
|
|
return new SkCanvas(device);
|
|
|
|
} else
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2013-01-24 20:47:18 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void publishCanvas(SampleWindow::DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-02 19:24:21 +00:00
|
|
|
if (fCurContext) {
|
2011-07-14 14:30:46 +00:00
|
|
|
// in case we have queued drawing calls
|
2012-04-02 19:24:21 +00:00
|
|
|
fCurContext->flush();
|
|
|
|
|
2013-01-24 20:47:18 +00:00
|
|
|
if (!IsGpuDeviceType(dType)) {
|
2011-07-14 14:30:46 +00:00
|
|
|
// need to send the raster bits to the (gpu) window
|
2012-04-02 19:24:21 +00:00
|
|
|
fCurContext->setRenderTarget(fCurRenderTarget);
|
2011-07-14 14:30:46 +00:00
|
|
|
const SkBitmap& bm = win->getBitmap();
|
2012-04-02 19:24:21 +00:00
|
|
|
fCurRenderTarget->writePixels(0, 0, bm.width(), bm.height(),
|
2014-04-29 16:25:36 +00:00
|
|
|
SkImageInfo2GrPixelConfig(bm.colorType(),
|
|
|
|
bm.alphaType()),
|
2011-11-16 20:36:03 +00:00
|
|
|
bm.getPixels(),
|
|
|
|
bm.rowBytes());
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
virtual void windowSizeChanged(SampleWindow* win) {
|
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;
|
|
|
|
win->attach(fBackend, fMSAASampleCount, &attachmentInfo);
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-10-25 18:43:28 +00:00
|
|
|
GrBackendRenderTargetDesc desc;
|
2013-12-17 19:22:07 +00:00
|
|
|
desc.fWidth = SkScalarRoundToInt(win->width());
|
|
|
|
desc.fHeight = SkScalarRoundToInt(win->height());
|
2013-02-07 14:43:04 +00:00
|
|
|
desc.fConfig = kSkia8888_GrPixelConfig;
|
2013-02-05 19:50:46 +00:00
|
|
|
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
2013-03-05 20:06:05 +00:00
|
|
|
desc.fSampleCnt = attachmentInfo.fSampleCount;
|
|
|
|
desc.fStencilBits = attachmentInfo.fStencilBits;
|
2011-07-14 14:30:46 +00:00
|
|
|
GrGLint buffer;
|
2012-04-02 19:24:21 +00:00
|
|
|
GR_GL_GetIntegerv(fCurIntf, GR_GL_FRAMEBUFFER_BINDING, &buffer);
|
2011-11-07 13:29:52 +00:00
|
|
|
desc.fRenderTargetHandle = buffer;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
SkSafeUnref(fCurRenderTarget);
|
2012-10-25 18:43:28 +00:00
|
|
|
fCurRenderTarget = fCurContext->wrapBackendRenderTarget(desc);
|
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
|
|
|
}
|
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual GrContext* getGrContext() {
|
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
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2011-07-14 14:30:46 +00:00
|
|
|
}
|
2012-04-06 20:13:38 +00:00
|
|
|
|
|
|
|
virtual GrRenderTarget* getGrRenderTarget() SK_OVERRIDE {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2012-04-06 20:13:38 +00:00
|
|
|
return fCurRenderTarget;
|
2012-08-02 14:03:32 +00:00
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
2012-04-06 20:13:38 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
GrRenderTarget* fCurRenderTarget;
|
2012-08-02 14:03:32 +00:00
|
|
|
int fMSAASampleCount;
|
|
|
|
#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
|
|
|
SkFuncViewFactory::SkFuncViewFactory(SkViewCreateFunc func)
|
|
|
|
: fCreateFunc(func) {
|
|
|
|
}
|
|
|
|
|
2011-10-31 16:47:13 +00:00
|
|
|
SkView* SkFuncViewFactory::operator() () const {
|
2011-10-31 14:18:20 +00:00
|
|
|
return (*fCreateFunc)();
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "GMSampleView.h"
|
|
|
|
|
|
|
|
SkGMSampleViewFactory::SkGMSampleViewFactory(GMFactoryFunc func)
|
|
|
|
: fFunc(func) {
|
|
|
|
}
|
|
|
|
|
|
|
|
SkView* SkGMSampleViewFactory::operator() () const {
|
2014-02-07 21:13:11 +00:00
|
|
|
skiagm::GM* gm = fFunc(NULL);
|
|
|
|
gm->setMode(skiagm::GM::kSample_Mode);
|
|
|
|
return new GMSampleView(gm);
|
2011-10-31 14:18:20 +00:00
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkViewRegister* SkViewRegister::gHead;
|
2011-10-31 14:18:20 +00:00
|
|
|
SkViewRegister::SkViewRegister(SkViewFactory* fact) : fFact(fact) {
|
|
|
|
fFact->ref();
|
|
|
|
fChain = gHead;
|
|
|
|
gHead = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkViewRegister::SkViewRegister(SkViewCreateFunc func) {
|
|
|
|
fFact = new SkFuncViewFactory(func);
|
|
|
|
fChain = gHead;
|
|
|
|
gHead = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkViewRegister::SkViewRegister(GMFactoryFunc func) {
|
|
|
|
fFact = new SkGMSampleViewFactory(func);
|
|
|
|
fChain = gHead;
|
|
|
|
gHead = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
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[] = {
|
|
|
|
{SkPaint::kNo_Hinting, "Mixed", NULL },
|
|
|
|
{SkPaint::kNo_Hinting, "None", "H0 " },
|
|
|
|
{SkPaint::kSlight_Hinting, "Slight", "Hs " },
|
|
|
|
{SkPaint::kNormal_Hinting, "Normal", "Hn " },
|
|
|
|
{SkPaint::kFull_Hinting, "Full", "Hf " },
|
|
|
|
};
|
|
|
|
|
2013-12-10 16:53:13 +00:00
|
|
|
struct FilterLevelState {
|
|
|
|
SkPaint::FilterLevel fLevel;
|
|
|
|
const char* fName;
|
|
|
|
const char* fLabel;
|
|
|
|
};
|
|
|
|
static FilterLevelState gFilterLevelStates[] = {
|
|
|
|
{ SkPaint::kNone_FilterLevel, "Mixed", NULL },
|
|
|
|
{ SkPaint::kNone_FilterLevel, "None", "F0 " },
|
|
|
|
{ SkPaint::kLow_FilterLevel, "Low", "F1 " },
|
|
|
|
{ SkPaint::kMedium_FilterLevel, "Medium", "F2 " },
|
|
|
|
{ SkPaint::kHigh_FilterLevel, "High", "F3 " },
|
|
|
|
};
|
|
|
|
|
2011-04-05 13:07:03 +00:00
|
|
|
class FlagsDrawFilter : public SkDrawFilter {
|
|
|
|
public:
|
2013-12-10 16:53:13 +00:00
|
|
|
FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa,
|
|
|
|
SkOSMenu::TriState subpixel, int hinting, int filterlevel)
|
|
|
|
: fLCDState(lcd)
|
|
|
|
, fAAState(aa)
|
|
|
|
, fSubpixelState(subpixel)
|
|
|
|
, fHintingState(hinting)
|
|
|
|
, fFilterLevelIndex(filterlevel)
|
|
|
|
{
|
|
|
|
SkASSERT((unsigned)filterlevel < SK_ARRAY_COUNT(gFilterLevelStates));
|
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2012-11-26 20:26:54 +00:00
|
|
|
virtual bool filter(SkPaint* paint, Type t) {
|
2011-08-08 15:37:23 +00:00
|
|
|
if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
|
|
|
|
paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
|
2011-04-05 13:07:03 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::kMixedState != fAAState) {
|
|
|
|
paint->setAntiAlias(SkOSMenu::kOnState == fAAState);
|
2011-03-11 20:08:25 +00:00
|
|
|
}
|
2013-12-10 16:53:13 +00:00
|
|
|
if (0 != fFilterLevelIndex) {
|
|
|
|
paint->setFilterLevel(gFilterLevelStates[fFilterLevelIndex].fLevel);
|
2011-05-17 15:32:04 +00:00
|
|
|
}
|
2013-06-03 21:26:34 +00:00
|
|
|
if (SkOSMenu::kMixedState != fSubpixelState) {
|
|
|
|
paint->setSubpixelText(SkOSMenu::kOnState == fSubpixelState);
|
|
|
|
}
|
2013-06-03 21:35:03 +00:00
|
|
|
if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) {
|
2013-06-03 21:26:34 +00:00
|
|
|
paint->setHinting(gHintingStates[fHintingState].hinting);
|
2011-05-18 12:04:31 +00:00
|
|
|
}
|
2012-11-26 20:26:54 +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;
|
2013-12-10 16:53:13 +00:00
|
|
|
int fFilterLevelIndex;
|
2011-03-11 20:08:25 +00:00
|
|
|
};
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
#define MAX_ZOOM_LEVEL 8
|
|
|
|
#define MIN_ZOOM_LEVEL -8
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
static const char gCharEvtName[] = "SampleCode_Char_Event";
|
|
|
|
static const char gKeyEvtName[] = "SampleCode_Key_Event";
|
2008-12-17 15:59:43 +00:00
|
|
|
static const char gTitleEvtName[] = "SampleCode_Title_Event";
|
|
|
|
static const char gPrefSizeEvtName[] = "SampleCode_PrefSize_Event";
|
2010-12-20 18:26:13 +00:00
|
|
|
static const char gFastTextEvtName[] = "SampleCode_FastText_Event";
|
2011-11-08 15:18:10 +00:00
|
|
|
static const char gUpdateWindowTitleEvtName[] = "SampleCode_UpdateWindowTitle";
|
2010-12-20 18:26:13 +00:00
|
|
|
|
|
|
|
bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) {
|
|
|
|
if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) {
|
|
|
|
if (outUni) {
|
|
|
|
*outUni = evt.getFast32();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleCode::KeyQ(const SkEvent& evt, SkKey* outKey) {
|
|
|
|
if (evt.isType(gKeyEvtName, sizeof(gKeyEvtName) - 1)) {
|
|
|
|
if (outKey) {
|
|
|
|
*outKey = (SkKey)evt.getFast32();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
bool SampleCode::TitleQ(const SkEvent& evt) {
|
|
|
|
return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleCode::TitleR(SkEvent* evt, const char title[]) {
|
|
|
|
SkASSERT(evt && TitleQ(*evt));
|
|
|
|
evt->setString(gTitleEvtName, title);
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
bool SampleCode::RequestTitle(SkView* view, SkString* title) {
|
|
|
|
SkEvent evt(gTitleEvtName);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
title->set(evt.findString(gTitleEvtName));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleCode::PrefSizeQ(const SkEvent& evt) {
|
|
|
|
return evt.isType(gPrefSizeEvtName, sizeof(gPrefSizeEvtName) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleCode::PrefSizeR(SkEvent* evt, SkScalar width, SkScalar height) {
|
|
|
|
SkASSERT(evt && PrefSizeQ(*evt));
|
|
|
|
SkScalar size[2];
|
|
|
|
size[0] = width;
|
|
|
|
size[1] = height;
|
|
|
|
evt->setScalars(gPrefSizeEvtName, 2, size);
|
|
|
|
}
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
bool SampleCode::FastTextQ(const SkEvent& evt) {
|
|
|
|
return evt.isType(gFastTextEvtName, sizeof(gFastTextEvtName) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-23 21:07:51 +00:00
|
|
|
static SkMSec gAnimTime;
|
2010-12-20 18:26:13 +00:00
|
|
|
static SkMSec gAnimTimePrev;
|
|
|
|
|
2009-11-23 21:07:51 +00:00
|
|
|
SkMSec SampleCode::GetAnimTime() { return gAnimTime; }
|
2010-12-20 18:26:13 +00:00
|
|
|
SkMSec SampleCode::GetAnimTimeDelta() { return gAnimTime - gAnimTimePrev; }
|
|
|
|
SkScalar SampleCode::GetAnimSecondsDelta() {
|
|
|
|
return SkDoubleToScalar(GetAnimTimeDelta() / 1000.0);
|
|
|
|
}
|
2009-11-23 21:07:51 +00:00
|
|
|
|
|
|
|
SkScalar SampleCode::GetAnimScalar(SkScalar speed, SkScalar period) {
|
2010-12-20 18:26:13 +00:00
|
|
|
// since gAnimTime can be up to 32 bits, we can't convert it to a float
|
|
|
|
// or we'll lose the low bits. Hence we use doubles for the intermediate
|
|
|
|
// calculations
|
|
|
|
double seconds = (double)gAnimTime / 1000.0;
|
|
|
|
double value = SkScalarToDouble(speed) * seconds;
|
2009-11-23 21:07:51 +00:00
|
|
|
if (period) {
|
2010-12-20 18:26:13 +00:00
|
|
|
value = ::fmod(value, SkScalarToDouble(period));
|
2009-11-23 21:07:51 +00:00
|
|
|
}
|
2010-12-20 18:26:13 +00:00
|
|
|
return SkDoubleToScalar(value);
|
2009-11-23 21:07:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 14:44:37 +00:00
|
|
|
SkScalar SampleCode::GetAnimSinScalar(SkScalar amplitude,
|
|
|
|
SkScalar periodInSec,
|
|
|
|
SkScalar phaseInSec) {
|
|
|
|
if (!periodInSec) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
double t = (double)gAnimTime / 1000.0 + phaseInSec;
|
|
|
|
t *= SkScalarToFloat(2 * SK_ScalarPI) / periodInSec;
|
|
|
|
amplitude = SK_ScalarHalf * amplitude;
|
|
|
|
return SkScalarMul(amplitude, SkDoubleToScalar(sin(t))) + amplitude;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
SK_COMPILE_ASSERT((SK_ARRAY_COUNT(gTilingInfo) == kLast_TilingMode_Enum),
|
|
|
|
Incomplete_tiling_labels);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +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
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
bool SampleWindow::zoomIn()
|
|
|
|
{
|
|
|
|
// Arbitrarily decided
|
|
|
|
if (fFatBitsScale == 25) return false;
|
|
|
|
fFatBitsScale++;
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleWindow::zoomOut()
|
|
|
|
{
|
|
|
|
if (fFatBitsScale == 1) return false;
|
|
|
|
fFatBitsScale--;
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleWindow::updatePointer(int x, int y)
|
|
|
|
{
|
|
|
|
fMouseX = x;
|
|
|
|
fMouseY = y;
|
|
|
|
if (fShowZoomer) {
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType ct) {
|
|
|
|
static const SampleWindow::DeviceType gCT[] = {
|
|
|
|
SampleWindow::kPicture_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-07-14 14:30:46 +00:00
|
|
|
SampleWindow::kGPU_DeviceType,
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
SampleWindow::kANGLE_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
2011-10-27 20:44:19 +00:00
|
|
|
SampleWindow::kRaster_DeviceType, // skip the null gpu device in normal cycling
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2011-07-14 14:30:46 +00:00
|
|
|
SampleWindow::kRaster_DeviceType
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2012-08-02 14:03:32 +00:00
|
|
|
SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array_size_mismatch);
|
2008-12-17 15:59:43 +00:00
|
|
|
return gCT[ct];
|
|
|
|
}
|
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
static void usage(const char * argv0) {
|
2013-07-11 14:28:04 +00:00
|
|
|
SkDebugf("%s [--slide sampleName] [-i resourcePath] [--msaa sampleCount] [--pictureDir dirPath] [--picture path] [--sort]\n", argv0);
|
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
SkDebugf(" [--pdfDir pdfPath]\n");
|
|
|
|
SkDebugf(" pdfPath: path to directory pdf files are read from\n");
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
2012-03-20 17:40:58 +00:00
|
|
|
SkDebugf(" sampleName: sample at which to start.\n");
|
|
|
|
SkDebugf(" resourcePath: directory that stores image resources.\n");
|
2012-04-06 20:13:38 +00:00
|
|
|
SkDebugf(" msaa: request multisampling with the given sample count.\n");
|
2012-08-01 17:58:01 +00:00
|
|
|
SkDebugf(" dirPath: path to directory skia pictures are read from\n");
|
|
|
|
SkDebugf(" path: path to skia picture\n");
|
2013-07-11 14:28:04 +00:00
|
|
|
SkDebugf(" --sort: sort samples by title, this would help to compare pdf rendering (P:foo.pdf) with skp rendering (P:foo.pdf)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
, fDevManager(NULL) {
|
2012-03-20 17:40:58 +00:00
|
|
|
|
2013-06-06 13:14:13 +00:00
|
|
|
fCurrIndex = -1;
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
this->registerPictFileSamples(argv, argc);
|
2012-08-01 17:58:01 +00:00
|
|
|
this->registerPictFileSample(argv, argc);
|
2013-07-11 14:28:04 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
this->registerPdfFileViewerSamples(argv, argc);
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
2012-03-22 14:12:15 +00:00
|
|
|
SkGMRegistyToSampleRegistry();
|
|
|
|
{
|
|
|
|
const SkViewRegister* reg = SkViewRegister::Head();
|
|
|
|
while (reg) {
|
|
|
|
*fSamples.append() = reg->factory();
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
bool sort = false;
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "--sort")) {
|
|
|
|
sort = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sort) {
|
|
|
|
// Sort samples, so foo.skp and foo.pdf are consecutive and we can quickly spot where
|
|
|
|
// skp -> pdf -> png fails.
|
|
|
|
SkTQSort(fSamples.begin(), fSamples.end() ? fSamples.end() - 1 : NULL, compareSampleTitle);
|
|
|
|
}
|
|
|
|
|
2014-01-10 14:53:49 +00:00
|
|
|
const char* resourcePath = "resources"; // same default as tests
|
2012-04-06 20:13:38 +00:00
|
|
|
fMSAASampleCount = 0;
|
2012-03-20 17:40:58 +00:00
|
|
|
|
|
|
|
const char* const commandName = argv[0];
|
|
|
|
char* const* stop = argv + argc;
|
|
|
|
for (++argv; argv < stop; ++argv) {
|
2013-09-10 19:12:07 +00:00
|
|
|
if (!strcmp(*argv, "-i") || !strcmp(*argv, "--resourcePath")) {
|
2012-03-20 17:40:58 +00:00
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
resourcePath = *argv;
|
|
|
|
}
|
2012-03-22 14:12:15 +00:00
|
|
|
} else if (strcmp(*argv, "--slide") == 0) {
|
|
|
|
argv++;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
fCurrIndex = findByTitle(*argv);
|
|
|
|
if (fCurrIndex < 0) {
|
|
|
|
fprintf(stderr, "Unknown sample \"%s\"\n", *argv);
|
2012-05-03 18:22:28 +00:00
|
|
|
listTitles();
|
2012-03-22 14:12:15 +00:00
|
|
|
}
|
2012-03-20 17:40:58 +00:00
|
|
|
}
|
2012-04-06 20:13:38 +00:00
|
|
|
} else if (strcmp(*argv, "--msaa") == 0) {
|
|
|
|
++argv;
|
|
|
|
if (argv < stop && **argv) {
|
|
|
|
fMSAASampleCount = atoi(*argv);
|
|
|
|
}
|
2012-05-03 18:22:28 +00:00
|
|
|
} else if (strcmp(*argv, "--list") == 0) {
|
|
|
|
listTitles();
|
2013-10-14 12:47:37 +00:00
|
|
|
} else if (strcmp(*argv, "--pictureDir") == 0) {
|
|
|
|
++argv; // This case is dealt with in registerPictFileSamples().
|
|
|
|
} else if (strcmp(*argv, "--picture") == 0) {
|
|
|
|
++argv; // This case is dealt with in registerPictFileSample().
|
2012-04-06 20:13:38 +00:00
|
|
|
}
|
2012-03-28 16:19:11 +00:00
|
|
|
else {
|
2012-03-22 14:12:15 +00:00
|
|
|
usage(commandName);
|
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;
|
|
|
|
}
|
|
|
|
|
2011-07-06 13:59:47 +00:00
|
|
|
gSampleWindow = this;
|
|
|
|
|
2011-06-01 18:03:34 +00:00
|
|
|
#ifdef PIPE_FILE
|
|
|
|
//Clear existing file or create file if it doesn't exist
|
|
|
|
FILE* f = fopen(FILE_PATH, "wb");
|
|
|
|
fclose(f);
|
|
|
|
#endif
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-03-30 15:18:14 +00:00
|
|
|
fDeviceType = kRaster_DeviceType;
|
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;
|
2009-11-23 20:10:41 +00:00
|
|
|
fNClip = false;
|
2008-12-17 15:59:43 +00:00
|
|
|
fAnimating = false;
|
2009-08-14 16:08:38 +00:00
|
|
|
fRotate = false;
|
2013-07-09 21:58:56 +00:00
|
|
|
fRotateAnimTime = 0;
|
2011-09-08 18:48:12 +00:00
|
|
|
fPerspAnim = false;
|
|
|
|
fPerspAnimTime = 0;
|
2010-12-20 18:26:13 +00:00
|
|
|
fRequestGrabImage = false;
|
2012-06-08 15:35:03 +00:00
|
|
|
fPipeState = SkOSMenu::kOffState;
|
2013-12-06 20:14:55 +00:00
|
|
|
fTilingMode = kNo_Tiling;
|
2011-04-22 01:59:09 +00:00
|
|
|
fMeasureFPS = 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;
|
2013-12-10 16:53:13 +00:00
|
|
|
fFilterLevelIndex = 0;
|
2011-04-05 13:07:03 +00:00
|
|
|
fFlipAxis = 0;
|
2008-12-17 15:59:43 +00:00
|
|
|
fScrollTestX = fScrollTestY = 0;
|
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
fMouseX = fMouseY = 0;
|
2011-04-08 00:38:05 +00:00
|
|
|
fFatBitsScale = 8;
|
2011-03-24 18:35:50 +00:00
|
|
|
fTypeface = SkTypeface::CreateFromTypeface(NULL, SkTypeface::kBold);
|
|
|
|
fShowZoomer = false;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
fZoomLevel = 0;
|
|
|
|
fZoomScale = SK_Scalar1;
|
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;
|
|
|
|
fPdfCanvas = NULL;
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
fTransitionNext = 6;
|
|
|
|
fTransitionPrev = 2;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
|
|
|
|
"Raster", "Picture", "OpenGL",
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
"ANGLE",
|
|
|
|
#endif
|
|
|
|
NULL);
|
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');
|
2013-12-10 16:53:13 +00:00
|
|
|
itemID = fAppMenu->appendList("FilterLevel", "FilterLevel", sinkID, fFilterLevelIndex,
|
|
|
|
gFilterLevelStates[0].fName,
|
|
|
|
gFilterLevelStates[1].fName,
|
|
|
|
gFilterLevelStates[2].fName,
|
|
|
|
gFilterLevelStates[3].fName,
|
|
|
|
gFilterLevelStates[4].fName,
|
|
|
|
NULL);
|
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,
|
|
|
|
NULL);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
|
2012-08-15 14:41:58 +00:00
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID,
|
2012-08-01 17:58:01 +00:00
|
|
|
fPipeState);
|
2012-06-08 15:35:03 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P');
|
2012-08-15 14:41:58 +00:00
|
|
|
|
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,
|
|
|
|
NULL);
|
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');
|
2012-08-01 17:58:01 +00:00
|
|
|
itemID =fAppMenu->appendList("Transition-Next", "Transition-Next", sinkID,
|
|
|
|
fTransitionNext, "Up", "Up and Right", "Right",
|
|
|
|
"Down and Right", "Down", "Down and Left",
|
2011-08-08 15:37:23 +00:00
|
|
|
"Left", "Up and Left", NULL);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'j');
|
2012-08-01 17:58:01 +00:00
|
|
|
itemID =fAppMenu->appendList("Transition-Prev", "Transition-Prev", sinkID,
|
|
|
|
fTransitionPrev, "Up", "Up and Right", "Right",
|
|
|
|
"Down and Right", "Down", "Down and Left",
|
2011-08-08 15:37:23 +00:00
|
|
|
"Left", "Up and Left", NULL);
|
2012-04-18 14:07:57 +00:00
|
|
|
fAppMenu->assignKeyEquivalentToItem(itemID, 'k');
|
|
|
|
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
|
|
|
|
2014-04-11 17:15:40 +00:00
|
|
|
this->setColorType(kN32_SkColorType);
|
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
|
|
|
|
2012-03-20 17:40:58 +00:00
|
|
|
skiagm::GM::SetResourcePath(resourcePath);
|
|
|
|
|
2011-10-31 14:18:20 +00:00
|
|
|
this->loadView((*fSamples[fCurrIndex])());
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-07-06 21:59:09 +00:00
|
|
|
fPDFData = NULL;
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
if (NULL == devManager) {
|
|
|
|
fDevManager = new DefaultDeviceManager();
|
|
|
|
} else {
|
|
|
|
devManager->ref();
|
|
|
|
fDevManager = devManager;
|
|
|
|
}
|
2012-04-06 20:13:38 +00:00
|
|
|
fDevManager->setUpBackend(this, fMSAASampleCount);
|
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);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SampleWindow::~SampleWindow() {
|
2011-06-21 14:44:57 +00:00
|
|
|
delete fPdfCanvas;
|
2011-03-24 18:35:50 +00:00
|
|
|
fTypeface->unref();
|
2011-07-06 17:56:47 +00:00
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
SkSafeUnref(fDevManager);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
static void make_filepath(SkString* path, const char* dir, const SkString& name) {
|
|
|
|
size_t len = strlen(dir);
|
|
|
|
path->set(dir);
|
|
|
|
if (len > 0 && dir[len - 1] != '/') {
|
|
|
|
path->append("/");
|
|
|
|
}
|
|
|
|
path->append(name);
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:58:01 +00:00
|
|
|
void SampleWindow::registerPictFileSample(char** argv, int argc) {
|
|
|
|
const char* pict = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "--picture")) {
|
|
|
|
i += 1;
|
|
|
|
if (i < argc) {
|
|
|
|
pict = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pict) {
|
|
|
|
SkString path(pict);
|
2013-06-06 13:14:13 +00:00
|
|
|
fCurrIndex = fSamples.count();
|
2012-08-01 17:58:01 +00:00
|
|
|
*fSamples.append() = new PictFileFactory(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
void SampleWindow::registerPictFileSamples(char** argv, int argc) {
|
|
|
|
const char* pictDir = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "--pictureDir")) {
|
|
|
|
i += 1;
|
|
|
|
if (i < argc) {
|
|
|
|
pictDir = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pictDir) {
|
|
|
|
SkOSFile::Iter iter(pictDir, "skp");
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
|
|
|
SkString path;
|
|
|
|
make_filepath(&path, pictDir, filename);
|
|
|
|
*fSamples.append() = new PictFileFactory(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
void SampleWindow::registerPdfFileViewerSamples(char** argv, int argc) {
|
|
|
|
const char* pdfDir = NULL;
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (!strcmp(argv[i], "--pdfDir")) {
|
|
|
|
i += 1;
|
|
|
|
if (i < argc) {
|
|
|
|
pdfDir = argv[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pdfDir) {
|
|
|
|
SkOSFile::Iter iter(pdfDir, "pdf");
|
|
|
|
SkString filename;
|
|
|
|
while (iter.next(&filename)) {
|
|
|
|
SkString path;
|
|
|
|
make_filepath(&path, pdfDir, filename);
|
|
|
|
*fSamples.append() = new PdfFileViewerFactory(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
|
|
|
|
|
|
|
|
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-02-13 17:14:46 +00:00
|
|
|
if (bm.allocPixels(canvas->imageInfo())) {
|
|
|
|
canvas->readPixels(&bm, 0, 0);
|
|
|
|
}
|
2009-11-23 21:46:47 +00:00
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bitmap_diff(SkCanvas* canvas, const SkBitmap& orig,
|
|
|
|
SkBitmap* diff) {
|
|
|
|
const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2009-11-23 21:46:47 +00:00
|
|
|
SkAutoLockPixels alp0(src);
|
|
|
|
SkAutoLockPixels alp1(orig);
|
|
|
|
for (int y = 0; y < src.height(); y++) {
|
|
|
|
const void* srcP = src.getAddr(0, y);
|
|
|
|
const void* origP = orig.getAddr(0, y);
|
|
|
|
size_t bytes = src.width() * src.bytesPerPixel();
|
|
|
|
if (memcmp(srcP, origP, bytes)) {
|
|
|
|
SkDebugf("---------- difference on line %d\n", y);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
static void drawText(SkCanvas* canvas, SkString string, SkScalar left, SkScalar top, SkPaint& paint)
|
|
|
|
{
|
|
|
|
SkColor desiredColor = paint.getColor();
|
|
|
|
paint.setColor(SK_ColorWHITE);
|
|
|
|
const char* c_str = string.c_str();
|
|
|
|
size_t size = string.size();
|
|
|
|
SkRect bounds;
|
|
|
|
paint.measureText(c_str, size, &bounds);
|
|
|
|
bounds.offset(left, top);
|
|
|
|
SkScalar inset = SkIntToScalar(-2);
|
|
|
|
bounds.inset(inset, inset);
|
|
|
|
canvas->drawRect(bounds, paint);
|
|
|
|
if (desiredColor != SK_ColorBLACK) {
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
|
|
|
canvas->drawText(c_str, size, left + SK_Scalar1, top + SK_Scalar1, 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
|
|
|
|
|
|
|
void SampleWindow::draw(SkCanvas* canvas) {
|
2009-11-23 21:07:51 +00:00
|
|
|
// update the animation time
|
2011-09-08 18:48:12 +00:00
|
|
|
if (!gAnimTimePrev && !gAnimTime) {
|
|
|
|
// first time make delta be 0
|
|
|
|
gAnimTime = SkTime::GetMSecs();
|
|
|
|
gAnimTimePrev = gAnimTime;
|
|
|
|
} else {
|
|
|
|
gAnimTimePrev = gAnimTime;
|
|
|
|
gAnimTime = SkTime::GetMSecs();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2009-11-23 20:10:41 +00:00
|
|
|
if (fNClip) {
|
2009-11-23 21:46:47 +00:00
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
SkBitmap orig = capture_bitmap(canvas);
|
2009-11-23 20:10:41 +00:00
|
|
|
|
|
|
|
const SkScalar w = this->width();
|
|
|
|
const SkScalar h = this->height();
|
|
|
|
const SkScalar cw = w / XCLIP_N;
|
|
|
|
const SkScalar ch = h / YCLIP_N;
|
|
|
|
for (int y = 0; y < YCLIP_N; y++) {
|
2009-11-23 21:46:47 +00:00
|
|
|
SkRect r;
|
|
|
|
r.fTop = y * ch;
|
|
|
|
r.fBottom = (y + 1) * ch;
|
|
|
|
if (y == YCLIP_N - 1) {
|
|
|
|
r.fBottom = h;
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
for (int x = 0; x < XCLIP_N; x++) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2009-11-23 21:46:47 +00:00
|
|
|
r.fLeft = x * cw;
|
|
|
|
r.fRight = (x + 1) * cw;
|
|
|
|
if (x == XCLIP_N - 1) {
|
|
|
|
r.fRight = w;
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
canvas->clipRect(r);
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2009-11-23 21:46:47 +00:00
|
|
|
SkBitmap diff;
|
|
|
|
if (bitmap_diff(canvas, orig, &diff)) {
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
} else {
|
2013-12-10 21:51:06 +00:00
|
|
|
SkSize tile = this->tileSize();
|
2013-12-06 20:14:55 +00:00
|
|
|
|
|
|
|
for (SkScalar y = 0; y < height(); y += tile.height()) {
|
|
|
|
for (SkScalar x = 0; x < width(); x += tile.width()) {
|
2012-08-17 13:29:50 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2013-12-06 20:14:55 +00:00
|
|
|
canvas->clipRect(SkRect::MakeXYWH(x, y,
|
|
|
|
tile.width(),
|
|
|
|
tile.height()));
|
2012-08-17 13:29:50 +00:00
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:19:56 +00:00
|
|
|
|
2013-12-06 20:14:55 +00:00
|
|
|
if (fTilingMode != kNo_Tiling) {
|
2012-08-17 13:29:50 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0x60FF00FF);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
2013-12-06 20:14:55 +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
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-05-25 20:50:42 +00:00
|
|
|
void SampleWindow::showZoomer(SkCanvas* canvas) {
|
2011-03-24 18:35:50 +00:00
|
|
|
int count = canvas->save();
|
|
|
|
canvas->resetMatrix();
|
|
|
|
// Ensure the mouse position is on screen.
|
2013-12-17 19:22:07 +00:00
|
|
|
int width = SkScalarRoundToInt(this->width());
|
|
|
|
int height = SkScalarRoundToInt(this->height());
|
2011-03-24 18:35:50 +00:00
|
|
|
if (fMouseX >= width) fMouseX = width - 1;
|
|
|
|
else if (fMouseX < 0) fMouseX = 0;
|
|
|
|
if (fMouseY >= height) fMouseY = height - 1;
|
|
|
|
else if (fMouseY < 0) fMouseY = 0;
|
2011-05-18 15:07:20 +00:00
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
SkBitmap bitmap = capture_bitmap(canvas);
|
2011-05-18 15:07:20 +00:00
|
|
|
bitmap.lockPixels();
|
|
|
|
|
2011-03-24 18:35:50 +00:00
|
|
|
// Find the size of the zoomed in view, forced to be odd, so the examined pixel is in the middle.
|
2011-04-08 00:38:05 +00:00
|
|
|
int zoomedWidth = (width >> 1) | 1;
|
|
|
|
int zoomedHeight = (height >> 1) | 1;
|
2011-03-24 18:35:50 +00:00
|
|
|
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);
|
|
|
|
canvas->drawBitmapRect(bitmap, &src, dest);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
SkScalar lineHeight = paint.getFontMetrics(NULL);
|
|
|
|
SkString string;
|
|
|
|
string.appendf("(%i, %i)", fMouseX, fMouseY);
|
|
|
|
SkScalar left = dest.fLeft + SkIntToScalar(3);
|
|
|
|
SkScalar i = SK_Scalar1;
|
|
|
|
drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
|
|
|
|
// Alpha
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("A: %X", SkColorGetA(color));
|
|
|
|
drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
|
|
|
|
// Red
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("R: %X", SkColorGetR(color));
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
|
|
|
|
// Green
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("G: %X", SkColorGetG(color));
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
|
|
|
|
// Blue
|
|
|
|
i += SK_Scalar1;
|
|
|
|
string.reset();
|
|
|
|
string.appendf("B: %X", SkColorGetB(color));
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
drawText(canvas, string, left, SkScalarMulAdd(lineHeight, i, dest.fTop), paint);
|
|
|
|
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;
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
|
2011-06-21 14:44:57 +00:00
|
|
|
if (fSaveToPdf) {
|
|
|
|
const SkBitmap& bmp = canvas->getDevice()->accessBitmap(false);
|
|
|
|
SkISize size = SkISize::Make(bmp.width(), bmp.height());
|
|
|
|
SkPDFDevice* pdfDevice = new SkPDFDevice(size, size,
|
|
|
|
canvas->getTotalMatrix());
|
|
|
|
fPdfCanvas = new SkCanvas(pdfDevice);
|
|
|
|
pdfDevice->unref();
|
|
|
|
canvas = fPdfCanvas;
|
2013-01-24 20:47:18 +00:00
|
|
|
} else if (kPicture_DeviceType == fDeviceType) {
|
2014-04-17 23:35:06 +00:00
|
|
|
canvas = fRecorder.beginRecording(9999, 9999, NULL, 0);
|
2011-06-21 14:44:57 +00:00
|
|
|
} else {
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2013-01-24 20:47:18 +00:00
|
|
|
if (kNullGPU_DeviceType != fDeviceType)
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2013-01-24 20:47:18 +00:00
|
|
|
{
|
|
|
|
canvas = this->INHERITED::beforeChildren(canvas);
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fUseClip) {
|
|
|
|
canvas->drawColor(0xFFFF88FF);
|
2011-10-24 12:19:46 +00:00
|
|
|
canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void paint_rgn(const SkBitmap& bm, const SkIRect& r,
|
|
|
|
const SkRegion& rgn) {
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
SkRegion inval(rgn);
|
|
|
|
|
|
|
|
inval.translate(r.fLeft, r.fTop);
|
|
|
|
canvas.clipRegion(inval);
|
|
|
|
canvas.drawColor(0xFFFF8080);
|
|
|
|
}
|
2011-06-24 16:04:50 +00:00
|
|
|
#include "SkData.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
void SampleWindow::afterChildren(SkCanvas* orig) {
|
2011-06-21 14:44:57 +00:00
|
|
|
if (fSaveToPdf) {
|
|
|
|
fSaveToPdf = false;
|
|
|
|
if (fShowZoomer) {
|
|
|
|
showZoomer(fPdfCanvas);
|
|
|
|
}
|
|
|
|
SkString name;
|
|
|
|
name.printf("%s.pdf", this->getTitle());
|
|
|
|
SkPDFDocument doc;
|
|
|
|
SkPDFDevice* device = static_cast<SkPDFDevice*>(fPdfCanvas->getDevice());
|
|
|
|
doc.appendPage(device);
|
2011-11-08 19:00:26 +00:00
|
|
|
#ifdef SK_BUILD_FOR_ANDROID
|
2011-06-21 14:44:57 +00:00
|
|
|
name.prepend("/sdcard/");
|
|
|
|
#endif
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-24 16:04:50 +00:00
|
|
|
#ifdef SK_BUILD_FOR_IOS
|
|
|
|
SkDynamicMemoryWStream mstream;
|
|
|
|
doc.emitPDF(&mstream);
|
2011-06-24 21:09:39 +00:00
|
|
|
fPDFData = mstream.copyToData();
|
2011-06-24 16:04:50 +00:00
|
|
|
#endif
|
2011-06-21 14:44:57 +00:00
|
|
|
SkFILEWStream stream(name.c_str());
|
|
|
|
if (stream.isValid()) {
|
|
|
|
doc.emitPDF(&stream);
|
|
|
|
const char* desc = "File saved from Skia SampleApp";
|
|
|
|
this->onPDFSaved(this->getTitle(), desc, name.c_str());
|
|
|
|
}
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
delete fPdfCanvas;
|
|
|
|
fPdfCanvas = NULL;
|
|
|
|
|
|
|
|
// We took over the draw calls in order to create the PDF, so we need
|
|
|
|
// to redraw.
|
|
|
|
this->inval(NULL);
|
|
|
|
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
|
|
|
|
2013-08-29 11:54:56 +00:00
|
|
|
SkBaseDevice* device = orig->getDevice();
|
2011-04-05 17:08:27 +00:00
|
|
|
SkBitmap bmp;
|
2014-04-11 17:15:40 +00:00
|
|
|
if (device->accessBitmap(false).copyTo(&bmp, kN32_SkColorType)) {
|
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++);
|
2011-04-05 17:08:27 +00:00
|
|
|
SkImageEncoder::EncodeFile(name.c_str(), bmp,
|
2010-12-20 18:26:13 +00:00
|
|
|
SkImageEncoder::kPNG_Type, 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
if (kPicture_DeviceType == fDeviceType) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> picture(fRecorder.endRecording());
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
if (true) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkPicture* pict = new SkPicture(*picture);
|
2011-12-08 19:36:00 +00:00
|
|
|
this->installDrawFilter(orig);
|
2011-07-14 14:30:46 +00:00
|
|
|
orig->drawPicture(*pict);
|
|
|
|
pict->unref();
|
|
|
|
} else if (true) {
|
|
|
|
SkDynamicMemoryWStream ostream;
|
2014-04-13 19:09:42 +00:00
|
|
|
picture->serialize(&ostream);
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
SkAutoDataUnref data(ostream.copyToData());
|
2012-07-10 17:30:58 +00:00
|
|
|
SkMemoryStream istream(data->data(), data->size());
|
2013-06-28 21:32:00 +00:00
|
|
|
SkAutoTUnref<SkPicture> pict(SkPicture::CreateFromStream(&istream));
|
|
|
|
if (pict.get() != NULL) {
|
|
|
|
orig->drawPicture(*pict.get());
|
|
|
|
}
|
2011-07-14 14:30:46 +00:00
|
|
|
} else {
|
2014-04-13 19:09:42 +00:00
|
|
|
picture->draw(orig);
|
2011-07-14 14:30:46 +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
|
2012-12-10 14:12:55 +00:00
|
|
|
if (fMeasureFPS && fMeasureFPS_StartTime) {
|
|
|
|
fMeasureFPS_Time += SkTime::GetMSecs() - fMeasureFPS_StartTime;
|
2011-04-25 14:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// if ((fScrollTestX | fScrollTestY) != 0)
|
2010-12-20 18:26:13 +00:00
|
|
|
if (false) {
|
2008-12-17 15:59:43 +00:00
|
|
|
const SkBitmap& bm = orig->getDevice()->accessBitmap(true);
|
|
|
|
int dx = fScrollTestX * 7;
|
|
|
|
int dy = fScrollTestY * 7;
|
|
|
|
SkIRect r;
|
|
|
|
SkRegion inval;
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
r.set(50, 50, 50+100, 50+100);
|
|
|
|
bm.scrollRect(&r, dx, dy, &inval);
|
|
|
|
paint_rgn(bm, r, inval);
|
2011-08-12 14:27:47 +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) {
|
2013-07-09 21:58:56 +00:00
|
|
|
fRotateAnimTime += SampleCode::GetAnimSecondsDelta();
|
|
|
|
|
2009-08-14 16:08:38 +00:00
|
|
|
SkScalar cx = this->width() / 2;
|
|
|
|
SkScalar cy = this->height() / 2;
|
|
|
|
canvas->translate(cx, cy);
|
2013-07-09 21:58:56 +00:00
|
|
|
canvas->rotate(fRotateAnimTime * 10);
|
2009-08-14 16:08:38 +00:00
|
|
|
canvas->translate(-cx, -cy);
|
|
|
|
}
|
2013-07-09 21:58:56 +00:00
|
|
|
|
2011-09-08 18:48:12 +00:00
|
|
|
if (fPerspAnim) {
|
2011-09-16 18:51:57 +00:00
|
|
|
fPerspAnimTime += SampleCode::GetAnimSecondsDelta();
|
|
|
|
|
|
|
|
static const SkScalar gAnimPeriod = 10 * SK_Scalar1;
|
|
|
|
static const SkScalar gAnimMag = SK_Scalar1 / 1000;
|
|
|
|
SkScalar t = SkScalarMod(fPerspAnimTime, gAnimPeriod);
|
|
|
|
if (SkScalarFloorToInt(SkScalarDiv(fPerspAnimTime, gAnimPeriod)) & 0x1) {
|
|
|
|
t = gAnimPeriod - t;
|
|
|
|
}
|
|
|
|
t = 2 * t - gAnimPeriod;
|
|
|
|
t = SkScalarMul(SkScalarDiv(t, gAnimPeriod), gAnimMag);
|
|
|
|
SkMatrix m;
|
|
|
|
m.reset();
|
|
|
|
m.setPerspY(t);
|
2011-09-08 18:48:12 +00:00
|
|
|
canvas->concat(m);
|
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-12-08 19:36:00 +00:00
|
|
|
this->installDrawFilter(canvas);
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
if (fMeasureFPS) {
|
2011-04-22 14:10:48 +00:00
|
|
|
if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
|
2012-12-10 14:12:55 +00:00
|
|
|
fMeasureFPS_StartTime = SkTime::GetMSecs();
|
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) {
|
2011-09-08 18:48:12 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
}
|
2009-08-14 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
|
2011-03-11 20:08:25 +00:00
|
|
|
canvas->setDrawFilter(NULL);
|
2009-08-14 16:08:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-16 22:03:38 +00:00
|
|
|
static SkColorType gColorTypeCycle[] = {
|
|
|
|
kUnknown_SkColorType, // none -> none
|
|
|
|
kUnknown_SkColorType, // a8 -> none
|
2014-04-29 16:25:36 +00:00
|
|
|
kN32_SkColorType, // 565 -> 8888
|
2014-04-11 17:15:40 +00:00
|
|
|
kN32_SkColorType, // 4444 -> 8888
|
2014-02-16 22:03:38 +00:00
|
|
|
kRGB_565_SkColorType, // 8888 -> 565
|
|
|
|
kRGB_565_SkColorType, // 8888 -> 565
|
|
|
|
kUnknown_SkColorType, // index8 -> none
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2014-02-17 02:55:57 +00:00
|
|
|
static SkColorType cycle_colortypes(SkColorType c) {
|
2014-02-16 22:03:38 +00:00
|
|
|
return gColorTypeCycle[c];
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
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
|
|
|
|
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();
|
2011-03-21 00:53:39 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
}
|
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();
|
2012-08-01 17:58:01 +00:00
|
|
|
this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(),
|
2011-08-08 15:37:23 +00:00
|
|
|
fTransitionPrev));
|
2011-06-15 16:49:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleWindow::nextSample() {
|
2009-11-03 04:00:48 +00:00
|
|
|
fCurrIndex = (fCurrIndex + 1) % fSamples.count();
|
2012-08-01 17:58:01 +00:00
|
|
|
this->loadView(create_transition(curr_view(this), (*fSamples[fCurrIndex])(),
|
2011-08-08 15:37:23 +00:00
|
|
|
fTransitionNext));
|
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();
|
2011-10-31 14:18:20 +00:00
|
|
|
this->loadView(create_transition(curr_view(this),(*fSamples[fCurrIndex])(), 6));
|
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() {
|
2012-08-01 17:58:01 +00:00
|
|
|
this->loadView(create_transition(curr_view(this),
|
|
|
|
create_overview(fSamples.count(), fSamples.begin()),
|
2011-08-08 15:37:23 +00:00
|
|
|
4));
|
|
|
|
}
|
|
|
|
|
2011-12-08 19:36:00 +00:00
|
|
|
void SampleWindow::installDrawFilter(SkCanvas* canvas) {
|
2013-12-10 16:53:13 +00:00
|
|
|
canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fSubpixelState,
|
|
|
|
fHintingState, fFilterLevelIndex))->unref();
|
2011-12-08 19:36:00 +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
|
|
|
|
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;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (evt.isType("replace-transition-view")) {
|
|
|
|
this->loadView((SkView*)SkEventSink::FindSink(evt.getFast32()));
|
2011-08-08 15:37:23 +00:00
|
|
|
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)) {
|
|
|
|
this->inval(NULL);
|
|
|
|
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
|
|
|
}
|
2012-06-08 15:35:03 +00:00
|
|
|
if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) {
|
2011-08-12 14:27:47 +00:00
|
|
|
#ifdef PIPE_NET
|
2012-06-08 15:35:03 +00:00
|
|
|
if (!fPipeState != SkOSMenu::kOnState)
|
2011-08-12 14:27:47 +00:00
|
|
|
gServer.disconnectAll();
|
|
|
|
#endif
|
2012-06-08 15:35:03 +00:00
|
|
|
(void)SampleView::SetUsePipe(curr_view(this), fPipeState);
|
2011-08-12 14:27:47 +00:00
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
2011-08-02 13:39:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Slide Show", NULL)) {
|
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) ||
|
2013-12-10 16:53:13 +00:00
|
|
|
SkOSMenu::FindListIndex(evt, "FilterLevel", &fFilterLevelIndex) ||
|
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) ||
|
|
|
|
SkOSMenu::FindSwitchState(evt, "Magnify", &fMagnify) ||
|
|
|
|
SkOSMenu::FindListIndex(evt, "Transition-Next", &fTransitionNext) ||
|
2013-12-10 21:51:06 +00:00
|
|
|
SkOSMenu::FindListIndex(evt, "Transition-Prev", &fTransitionPrev)) {
|
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkOSMenu::FindListIndex(evt, "Tiling", &fTilingMode)) {
|
|
|
|
if (SampleView::IsSampleView(curr_view(this))) {
|
|
|
|
((SampleView*)curr_view(this))->onTileSizeChanged(this->tileSize());
|
|
|
|
}
|
2011-08-02 13:39:12 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Flip X", NULL)) {
|
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;
|
|
|
|
}
|
2011-08-12 14:27:47 +00:00
|
|
|
if (SkOSMenu::FindSwitchState(evt, "Flip Y", NULL)) {
|
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")) {
|
|
|
|
query->setFast32(this->getGrContext() != NULL);
|
|
|
|
return true;
|
|
|
|
}
|
2010-12-20 18:26:13 +00:00
|
|
|
return this->INHERITED::onQuery(query);
|
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
#if 0 // UNUSED
|
2008-12-23 16:49:54 +00:00
|
|
|
static void cleanup_for_filename(SkString* name) {
|
|
|
|
char* str = name->writable_str();
|
2009-12-18 21:33:39 +00:00
|
|
|
for (size_t i = 0; i < name->size(); i++) {
|
2008-12-23 16:49:54 +00:00
|
|
|
switch (str[i]) {
|
|
|
|
case ':': str[i] = '-'; break;
|
|
|
|
case '/': str[i] = '-'; break;
|
|
|
|
case ' ': str[i] = '_'; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-06 12:09:51 +00:00
|
|
|
#endif
|
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) {
|
|
|
|
if ((dx | dy) == 0) {
|
|
|
|
fScrollTestX = fScrollTestY = 0;
|
|
|
|
} else {
|
|
|
|
fScrollTestX += dx;
|
|
|
|
fScrollTestY += dy;
|
|
|
|
}
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-23 16:49:54 +00:00
|
|
|
switch (uni) {
|
2012-11-15 15:56:38 +00:00
|
|
|
case 'B':
|
2013-12-11 17:05:23 +00:00
|
|
|
post_event_to_sink(SkNEW_ARGS(SkEvent, ("PictFileView::toggleBBox")), curr_view(this));
|
|
|
|
// Cannot call updateTitle() synchronously, because the toggleBBox event is still in
|
|
|
|
// the queue.
|
|
|
|
post_event_to_sink(SkNEW_ARGS(SkEvent, (gUpdateWindowTitleEvtName)), this);
|
2012-11-15 15:56:38 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
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;
|
2010-12-20 18:26:13 +00:00
|
|
|
case 'g':
|
|
|
|
fRequestGrabImage = true;
|
|
|
|
this->inval(NULL);
|
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));
|
|
|
|
this->inval(NULL);
|
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;
|
2013-07-09 21:58:56 +00:00
|
|
|
fRotateAnimTime = 0;
|
2011-04-22 01:59:09 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2011-09-08 18:48:12 +00:00
|
|
|
case 'k':
|
|
|
|
fPerspAnim = !fPerspAnim;
|
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-27 20:44:19 +00:00
|
|
|
case '\\':
|
2012-04-02 19:24:21 +00:00
|
|
|
this->setDeviceType(kNullGPU_DeviceType);
|
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
2011-10-27 20:44:19 +00:00
|
|
|
return true;
|
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;
|
|
|
|
grContext->getResourceCacheUsage(NULL, &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;
|
|
|
|
|
|
|
|
fDevManager->tearDownBackend(this);
|
|
|
|
|
|
|
|
fDeviceType = type;
|
|
|
|
|
2012-04-06 20:13:38 +00:00
|
|
|
fDevManager->setUpBackend(this, fMSAASampleCount);
|
2012-04-02 19:24:21 +00:00
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
2011-11-07 15:43:57 +00:00
|
|
|
void SampleWindow::toggleFPS() {
|
|
|
|
fMeasureFPS = !fMeasureFPS;
|
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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:
|
2011-03-21 00:53:39 +00:00
|
|
|
if (USE_ARROWS_FOR_ZOOM) {
|
2013-05-15 15:07:32 +00:00
|
|
|
this->changeZoomLevel(1.f / 32.f);
|
2011-03-21 00:53:39 +00:00
|
|
|
} else {
|
|
|
|
fNClip = !fNClip;
|
|
|
|
this->inval(NULL);
|
2011-06-13 16:58:40 +00:00
|
|
|
this->updateTitle();
|
2011-03-21 00:53:39 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
return true;
|
|
|
|
case kDown_SkKey:
|
2011-03-21 00:53:39 +00:00
|
|
|
if (USE_ARROWS_FOR_ZOOM) {
|
2013-05-15 15:07:32 +00:00
|
|
|
this->changeZoomLevel(-1.f / 32.f);
|
2011-03-21 00:53:39 +00:00
|
|
|
} else {
|
2014-02-17 02:55:57 +00:00
|
|
|
this->setColorType(cycle_colortypes(this->getBitmap().colorType()));
|
2011-06-13 16:58:40 +00:00
|
|
|
this->updateTitle();
|
2011-03-21 00:53:39 +00:00
|
|
|
}
|
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;
|
2008-12-17 15:59:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
this->inval(NULL);
|
|
|
|
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-06-08 15:35:03 +00:00
|
|
|
(void)SampleView::SetUsePipe(view, fPipeState);
|
2013-12-10 21:51:06 +00:00
|
|
|
if (SampleView::IsSampleView(view)) {
|
|
|
|
SampleView* sampleView = (SampleView*)view;
|
|
|
|
sampleView->requestMenu(fSlideMenu);
|
|
|
|
sampleView->onTileSizeChanged(this->tileSize());
|
|
|
|
}
|
2012-04-18 14:07:57 +00:00
|
|
|
this->onUpdateMenu(fSlideMenu);
|
2008-12-17 15:59:43 +00:00
|
|
|
this->updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* gConfigNames[] = {
|
|
|
|
"unknown config",
|
|
|
|
"A8",
|
|
|
|
"Index8",
|
|
|
|
"565",
|
|
|
|
"4444",
|
|
|
|
"8888"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* configToString(SkBitmap::Config c) {
|
|
|
|
return gConfigNames[c];
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
static const char* gDeviceTypePrefix[] = {
|
2008-12-17 15:59:43 +00:00
|
|
|
"raster: ",
|
|
|
|
"picture: ",
|
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
|
2011-10-27 20:44:19 +00:00
|
|
|
"null-gl: "
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_SUPPORT_GPU
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
2012-08-02 14:03:32 +00:00
|
|
|
SK_COMPILE_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;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
void SampleWindow::updateTitle() {
|
2011-12-27 22:33:50 +00:00
|
|
|
SkView* view = curr_view(this);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2011-12-27 22:33:50 +00:00
|
|
|
SkString title;
|
|
|
|
if (!curr_title(this, &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
|
|
|
|
|
|
|
title.prepend(" ");
|
|
|
|
title.prepend(configToString(this->getBitmap().config()));
|
2011-01-18 20:57:22 +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> ");
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
if (fNClip) {
|
|
|
|
title.prepend("<C> ");
|
|
|
|
}
|
2011-09-08 18:48:12 +00:00
|
|
|
if (fPerspAnim) {
|
|
|
|
title.prepend("<K> ");
|
|
|
|
}
|
2011-04-05 13:07:03 +00:00
|
|
|
|
|
|
|
title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
|
|
|
|
title.prepend(trystate_str(fAAState, "AA ", "aa "));
|
2013-12-10 16:53:13 +00:00
|
|
|
title.prepend(gFilterLevelStates[fFilterLevelIndex].fLabel);
|
2013-06-03 21:26:34 +00:00
|
|
|
title.prepend(trystate_str(fSubpixelState, "S ", "s "));
|
2011-04-05 13:07:03 +00:00
|
|
|
title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL);
|
|
|
|
title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
|
2013-06-03 21:26:34 +00:00
|
|
|
title.prepend(gHintingStates[fHintingState].label);
|
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) {
|
2012-09-10 11:52:52 +00:00
|
|
|
title.appendf(" %8.3f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2011-05-12 22:08:24 +00:00
|
|
|
if (SampleView::IsSampleView(view)) {
|
2012-06-08 15:35:03 +00:00
|
|
|
switch (fPipeState) {
|
|
|
|
case SkOSMenu::kOnState:
|
|
|
|
title.prepend("<Pipe> ");
|
|
|
|
break;
|
|
|
|
case SkOSMenu::kMixedState:
|
|
|
|
title.prepend("<Tiled Pipe> ");
|
|
|
|
break;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-05-12 22:08:24 +00:00
|
|
|
title.prepend("! ");
|
|
|
|
}
|
2011-04-22 01:59:09 +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) &&
|
2012-04-10 13:34:11 +00:00
|
|
|
NULL != fDevManager &&
|
2013-01-24 20:47:18 +00:00
|
|
|
fDevManager->getGrRenderTarget() &&
|
2012-04-06 20:13:38 +00:00
|
|
|
fDevManager->getGrRenderTarget()->numSamples() > 0) {
|
|
|
|
title.appendf(" [MSAA: %d]",
|
|
|
|
fDevManager->getGrRenderTarget()->numSamples());
|
|
|
|
}
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif
|
2012-04-06 20:13:38 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-12 22:08:24 +00:00
|
|
|
static const char is_sample_view_tag[] = "sample-is-sample-view";
|
2011-04-22 01:59:09 +00:00
|
|
|
static const char repeat_count_tag[] = "sample-set-repeat-count";
|
2011-05-11 05:58:58 +00:00
|
|
|
static const char set_use_pipe_tag[] = "sample-set-use-pipe";
|
2011-04-22 01:59:09 +00:00
|
|
|
|
2011-05-12 22:08:24 +00:00
|
|
|
bool SampleView::IsSampleView(SkView* view) {
|
|
|
|
SkEvent evt(is_sample_view_tag);
|
|
|
|
return view->doQuery(&evt);
|
|
|
|
}
|
|
|
|
|
2011-04-22 14:10:48 +00:00
|
|
|
bool SampleView::SetRepeatDraw(SkView* view, int count) {
|
2011-04-22 01:59:09 +00:00
|
|
|
SkEvent evt(repeat_count_tag);
|
|
|
|
evt.setFast32(count);
|
2011-04-22 14:10:48 +00:00
|
|
|
return view->doEvent(evt);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) {
|
|
|
|
SkEvent evt;
|
|
|
|
evt.setS32(set_use_pipe_tag, state);
|
2011-05-11 05:58:58 +00:00
|
|
|
return view->doEvent(evt);
|
|
|
|
}
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
bool SampleView::onEvent(const SkEvent& evt) {
|
|
|
|
if (evt.isType(repeat_count_tag)) {
|
|
|
|
fRepeatCount = evt.getFast32();
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-08 16:17:50 +00:00
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
int32_t pipeHolder;
|
|
|
|
if (evt.findS32(set_use_pipe_tag, &pipeHolder)) {
|
|
|
|
fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder);
|
2011-05-11 05:58:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-08 16:17:50 +00:00
|
|
|
|
|
|
|
if (evt.isType("debug-hit-test")) {
|
|
|
|
fDebugHitTest = true;
|
|
|
|
evt.findS32("debug-hit-test-x", &fDebugHitTestLoc.fX);
|
|
|
|
evt.findS32("debug-hit-test-y", &fDebugHitTestLoc.fY);
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
return this->INHERITED::onEvent(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleView::onQuery(SkEvent* evt) {
|
2011-05-12 22:08:24 +00:00
|
|
|
if (evt->isType(is_sample_view_tag)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-22 01:59:09 +00:00
|
|
|
return this->INHERITED::onQuery(evt);
|
|
|
|
}
|
|
|
|
|
2011-05-04 14:32:04 +00:00
|
|
|
|
|
|
|
class SimplePC : public SkGPipeController {
|
|
|
|
public:
|
|
|
|
SimplePC(SkCanvas* target);
|
|
|
|
~SimplePC();
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-05-04 14:32:04 +00:00
|
|
|
virtual void* requestBlock(size_t minRequest, size_t* actual);
|
|
|
|
virtual void notifyWritten(size_t bytes);
|
|
|
|
|
|
|
|
private:
|
2011-05-05 14:03:48 +00:00
|
|
|
SkGPipeReader fReader;
|
|
|
|
void* fBlock;
|
|
|
|
size_t fBlockSize;
|
|
|
|
size_t fBytesWritten;
|
|
|
|
int fAtomsWritten;
|
2011-05-04 14:32:04 +00:00
|
|
|
SkGPipeReader::Status fStatus;
|
|
|
|
|
|
|
|
size_t fTotalWritten;
|
|
|
|
};
|
|
|
|
|
|
|
|
SimplePC::SimplePC(SkCanvas* target) : fReader(target) {
|
|
|
|
fBlock = NULL;
|
|
|
|
fBlockSize = fBytesWritten = 0;
|
|
|
|
fStatus = SkGPipeReader::kDone_Status;
|
|
|
|
fTotalWritten = 0;
|
2011-05-05 14:03:48 +00:00
|
|
|
fAtomsWritten = 0;
|
2013-04-30 02:32:41 +00:00
|
|
|
fReader.setBitmapDecoder(&SkImageDecoder::DecodeMemory);
|
2011-05-04 14:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SimplePC::~SimplePC() {
|
|
|
|
// SkASSERT(SkGPipeReader::kDone_Status == fStatus);
|
2011-05-11 05:58:58 +00:00
|
|
|
if (fTotalWritten) {
|
2012-06-08 15:35:03 +00:00
|
|
|
SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten,
|
|
|
|
fAtomsWritten, fStatus);
|
2011-08-08 15:37:23 +00:00
|
|
|
#ifdef PIPE_FILE
|
2012-06-08 15:35:03 +00:00
|
|
|
//File is open in append mode
|
|
|
|
FILE* f = fopen(FILE_PATH, "ab");
|
|
|
|
SkASSERT(f != NULL);
|
|
|
|
fwrite((const char*)fBlock + fBytesWritten, 1, bytes, f);
|
|
|
|
fclose(f);
|
2011-08-08 15:37:23 +00:00
|
|
|
#endif
|
|
|
|
#ifdef PIPE_NET
|
2012-06-08 15:35:03 +00:00
|
|
|
if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done
|
|
|
|
gServer.acceptConnections();
|
|
|
|
gServer.writePacket(fBlock, fTotalWritten);
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
#endif
|
2011-05-11 05:58:58 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
sk_free(fBlock);
|
2011-05-04 14:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void* SimplePC::requestBlock(size_t minRequest, size_t* actual) {
|
|
|
|
sk_free(fBlock);
|
|
|
|
|
|
|
|
fBlockSize = minRequest * 4;
|
|
|
|
fBlock = sk_malloc_throw(fBlockSize);
|
|
|
|
fBytesWritten = 0;
|
|
|
|
*actual = fBlockSize;
|
|
|
|
return fBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SimplePC::notifyWritten(size_t bytes) {
|
|
|
|
SkASSERT(fBytesWritten + bytes <= fBlockSize);
|
|
|
|
fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes);
|
|
|
|
SkASSERT(SkGPipeReader::kError_Status != fStatus);
|
|
|
|
fBytesWritten += bytes;
|
|
|
|
fTotalWritten += bytes;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
fAtomsWritten += 1;
|
2011-05-04 14:32:04 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
void SampleView::draw(SkCanvas* canvas) {
|
2012-06-08 15:35:03 +00:00
|
|
|
if (SkOSMenu::kOffState == fPipeState) {
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
} else {
|
2011-08-08 15:37:23 +00:00
|
|
|
SkGPipeWriter writer;
|
|
|
|
SimplePC controller(canvas);
|
2012-06-08 15:35:03 +00:00
|
|
|
TiledPipeController tc(canvas->getDevice()->accessBitmap(false),
|
2013-04-30 02:32:41 +00:00
|
|
|
&SkImageDecoder::DecodeMemory,
|
2012-06-08 15:35:03 +00:00
|
|
|
&canvas->getTotalMatrix());
|
|
|
|
SkGPipeController* pc;
|
|
|
|
if (SkOSMenu::kMixedState == fPipeState) {
|
|
|
|
pc = &tc;
|
|
|
|
} else {
|
|
|
|
pc = &controller;
|
|
|
|
}
|
2011-05-23 12:21:05 +00:00
|
|
|
uint32_t flags = SkGPipeWriter::kCrossProcess_Flag;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
canvas = writer.startRecording(pc, flags);
|
2011-08-08 15:37:23 +00:00
|
|
|
//Must draw before controller goes out of scope and sends data
|
|
|
|
this->INHERITED::draw(canvas);
|
2011-08-12 14:27:47 +00:00
|
|
|
//explicitly end recording to ensure writer is flushed before the memory
|
|
|
|
//is freed in the deconstructor of the controller
|
|
|
|
writer.endRecording();
|
2011-05-11 05:58:58 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
}
|
2013-01-08 16:17:50 +00:00
|
|
|
|
|
|
|
#include "SkBounder.h"
|
|
|
|
|
|
|
|
class DebugHitTestBounder : public SkBounder {
|
|
|
|
public:
|
|
|
|
DebugHitTestBounder(int x, int y) {
|
|
|
|
fLoc.set(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool onIRect(const SkIRect& bounds) SK_OVERRIDE {
|
|
|
|
if (bounds.contains(fLoc.x(), fLoc.y())) {
|
|
|
|
//
|
|
|
|
// Set a break-point here to see what was being drawn under
|
|
|
|
// the click point (just needed a line of code to stop the debugger)
|
|
|
|
//
|
|
|
|
bounds.centerX();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkIPoint fLoc;
|
|
|
|
typedef SkBounder INHERITED;
|
|
|
|
};
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
void SampleView::onDraw(SkCanvas* canvas) {
|
2011-06-01 12:42:36 +00:00
|
|
|
this->onDrawBackground(canvas);
|
|
|
|
|
2013-01-08 16:17:50 +00:00
|
|
|
DebugHitTestBounder bounder(fDebugHitTestLoc.x(), fDebugHitTestLoc.y());
|
|
|
|
if (fDebugHitTest) {
|
|
|
|
canvas->setBounder(&bounder);
|
|
|
|
}
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
for (int i = 0; i < fRepeatCount; i++) {
|
2012-08-17 13:29:50 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
this->onDrawContent(canvas);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2013-01-08 16:17:50 +00:00
|
|
|
|
|
|
|
fDebugHitTest = false;
|
|
|
|
canvas->setBounder(NULL);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SampleView::onDrawBackground(SkCanvas* canvas) {
|
2011-04-22 14:10:48 +00:00
|
|
|
canvas->drawColor(fBGColor);
|
2011-04-22 01:59:09 +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();
|
|
|
|
}
|
2011-07-14 14:30:46 +00:00
|
|
|
return new SampleWindow(hwnd, argc, argv, NULL);
|
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
|
|
|
|
void save_args(int argc, char *argv[]) {
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
// FIXME: this should be in a header
|
|
|
|
void application_init();
|
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
|
|
|
}
|
|
|
|
|
2012-06-06 12:09:51 +00:00
|
|
|
// FIXME: this should be in a header
|
|
|
|
void application_term();
|
2008-12-17 15:59:43 +00:00
|
|
|
void application_term() {
|
2011-01-05 16:34:41 +00:00
|
|
|
SkEvent::Term();
|
|
|
|
SkGraphics::Term();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|