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"
|
2011-06-16 19:10:39 +00:00
|
|
|
#include "SkGpuDevice.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
#include "SkGraphics.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"
|
|
|
|
#include "SkStream.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"
|
2010-12-22 21:39:39 +00:00
|
|
|
#include "GrContext.h"
|
2011-03-24 18:35:50 +00:00
|
|
|
#include "SkTypeface.h"
|
2010-12-20 18:26:13 +00:00
|
|
|
|
2011-06-16 15:31:26 +00:00
|
|
|
#include "GrGLInterface.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
#include "SkPDFDevice.h"
|
|
|
|
#include "SkPDFDocument.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
#define TEST_GPIPE
|
2011-06-01 18:03:34 +00:00
|
|
|
|
|
|
|
#ifdef TEST_GPIPE
|
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 15:37:23 +00:00
|
|
|
#define PIPE_NET
|
|
|
|
#ifdef PIPE_NET
|
|
|
|
#include "SkSockets.h"
|
|
|
|
SkTCPServer gServer;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
#define USE_ARROWS_FOR_ZOOM true
|
2010-12-20 18:26:13 +00:00
|
|
|
//#define DEFAULT_TO_GPU
|
|
|
|
|
2009-12-18 21:33:39 +00:00
|
|
|
extern SkView* create_overview(int, const SkViewFactory[]);
|
2011-08-08 15:37:23 +00:00
|
|
|
extern SkView* create_transition(SkView*, SkView*, int);
|
2009-11-03 04:00:48 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#define ANIMATING_EVENTTYPE "nextSample"
|
|
|
|
#define ANIMATING_DELAY 750
|
|
|
|
|
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;
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
///////////////
|
|
|
|
class SampleWindow::DefaultDeviceManager : public SampleWindow::DeviceManager {
|
|
|
|
public:
|
|
|
|
|
|
|
|
DefaultDeviceManager() {
|
|
|
|
fGrRenderTarget = NULL;
|
|
|
|
fGrContext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~DefaultDeviceManager() {
|
|
|
|
SkSafeUnref(fGrRenderTarget);
|
|
|
|
SkSafeUnref(fGrContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void init(SampleWindow* win) {
|
|
|
|
win->attachGL();
|
|
|
|
if (NULL == fGrContext) {
|
|
|
|
fGrContext = GrContext::Create(kOpenGL_Shaders_GrEngine, NULL);
|
|
|
|
}
|
|
|
|
if (NULL == fGrContext) {
|
|
|
|
SkDebugf("Failed to setup 3D");
|
|
|
|
win->detachGL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool supportsDeviceType(SampleWindow::DeviceType dType) {
|
|
|
|
switch (dType) {
|
|
|
|
case kRaster_DeviceType:
|
|
|
|
case kPicture_DeviceType: // fallthru
|
|
|
|
return true;
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
return NULL != fGrContext && NULL != fGrRenderTarget;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool prepareCanvas(SampleWindow::DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) {
|
|
|
|
if (kGPU_DeviceType == dType) {
|
|
|
|
if (fGrContext) {
|
|
|
|
canvas->setDevice(new SkGpuDevice(fGrContext,
|
|
|
|
fGrRenderTarget))->unref();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void publishCanvas(SampleWindow::DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) {
|
|
|
|
if (fGrContext) {
|
|
|
|
// in case we have queued drawing calls
|
|
|
|
fGrContext->flush();
|
|
|
|
if (dType != kGPU_DeviceType) {
|
|
|
|
// need to send the raster bits to the (gpu) window
|
|
|
|
fGrContext->setRenderTarget(fGrRenderTarget);
|
|
|
|
const SkBitmap& bm = win->getBitmap();
|
|
|
|
fGrContext->writePixels(0, 0, bm.width(), bm.height(),
|
|
|
|
kRGBA_8888_GrPixelConfig, bm.getPixels(),
|
|
|
|
bm.rowBytes());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
win->presentGL();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void windowSizeChanged(SampleWindow* win) {
|
|
|
|
if (fGrContext) {
|
|
|
|
win->attachGL();
|
|
|
|
|
|
|
|
GrPlatformSurfaceDesc desc;
|
|
|
|
desc.reset();
|
|
|
|
desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType;
|
|
|
|
desc.fWidth = SkScalarRound(win->width());
|
|
|
|
desc.fHeight = SkScalarRound(win->height());
|
|
|
|
desc.fConfig = kRGBA_8888_GrPixelConfig;
|
2011-07-29 20:29:05 +00:00
|
|
|
GR_GL_GetIntegerv(GR_GL_STENCIL_BITS, &desc.fStencilBits);
|
|
|
|
GR_GL_GetIntegerv(GR_GL_SAMPLES, &desc.fSampleCnt);
|
2011-07-14 14:30:46 +00:00
|
|
|
GrGLint buffer;
|
|
|
|
GR_GL_GetIntegerv(GR_GL_FRAMEBUFFER_BINDING, &buffer);
|
|
|
|
desc.fPlatformRenderTarget = buffer;
|
|
|
|
|
|
|
|
SkSafeUnref(fGrRenderTarget);
|
|
|
|
fGrRenderTarget = static_cast<GrRenderTarget*>(
|
|
|
|
fGrContext->createPlatformSurface(desc));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GrContext* getGrContext() {
|
|
|
|
return fGrContext;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
GrContext* fGrContext;
|
|
|
|
GrRenderTarget* fGrRenderTarget;
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
//////////////////
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
SkViewRegister* SkViewRegister::gHead;
|
|
|
|
SkViewRegister::SkViewRegister(SkViewFactory fact) : fFact(fact) {
|
|
|
|
static bool gOnce;
|
|
|
|
if (!gOnce) {
|
|
|
|
gHead = NULL;
|
|
|
|
gOnce = true;
|
|
|
|
}
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fChain = gHead;
|
|
|
|
gHead = this;
|
|
|
|
}
|
|
|
|
|
2011-07-06 17:56:47 +00:00
|
|
|
#if 0
|
2011-03-11 20:08:25 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
#include <CoreFoundation/CFURLAccess.h>
|
|
|
|
|
|
|
|
static void testpdf() {
|
|
|
|
CFStringRef path = CFStringCreateWithCString(NULL, "/test.pdf",
|
|
|
|
kCFStringEncodingUTF8);
|
|
|
|
CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path,
|
|
|
|
kCFURLPOSIXPathStyle,
|
|
|
|
false);
|
|
|
|
CFRelease(path);
|
|
|
|
CGRect box = CGRectMake(0, 0, 8*72, 10*72);
|
|
|
|
CGContextRef cg = CGPDFContextCreateWithURL(url, &box, NULL);
|
|
|
|
CFRelease(url);
|
|
|
|
|
|
|
|
CGContextBeginPage(cg, &box);
|
|
|
|
CGRect r = CGRectMake(10, 10, 40 + 0.5, 50 + 0.5);
|
|
|
|
CGContextFillEllipseInRect(cg, r);
|
|
|
|
CGContextEndPage(cg);
|
|
|
|
CGContextRelease(cg);
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.setConfig(SkBitmap::kA8_Config, 64, 64);
|
|
|
|
bm.allocPixels();
|
|
|
|
bm.eraseColor(0);
|
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
class FlagsDrawFilter : public SkDrawFilter {
|
|
|
|
public:
|
2011-08-08 15:37:23 +00:00
|
|
|
FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa, SkOSMenu::TriState filter,
|
|
|
|
SkOSMenu::TriState hinting) :
|
2011-05-18 12:04:31 +00:00
|
|
|
fLCDState(lcd), fAAState(aa), fFilterState(filter), fHintingState(hinting) {}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-04-08 00:38:05 +00:00
|
|
|
virtual void 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
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::kMixedState != fFilterState) {
|
|
|
|
paint->setFilterBitmap(SkOSMenu::kOnState == fFilterState);
|
2011-05-17 15:32:04 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::kMixedState != fHintingState) {
|
|
|
|
paint->setHinting(SkOSMenu::kOnState == fHintingState ?
|
2011-05-18 12:04:31 +00:00
|
|
|
SkPaint::kNormal_Hinting :
|
|
|
|
SkPaint::kSlight_Hinting);
|
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-08-08 15:37:23 +00:00
|
|
|
SkOSMenu::TriState fLCDState;
|
|
|
|
SkOSMenu::TriState fAAState;
|
|
|
|
SkOSMenu::TriState fFilterState;
|
|
|
|
SkOSMenu::TriState fHintingState;
|
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";
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-07-06 13:59:47 +00:00
|
|
|
GrContext* SampleCode::GetGr() {
|
|
|
|
return gSampleWindow ? gSampleWindow->getGrContext() : NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
static SkView* curr_view(SkWindow* wind) {
|
|
|
|
SkView::F2BIter iter(wind);
|
|
|
|
return iter.next();
|
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void SampleWindow::setZoomCenter(float x, float y)
|
|
|
|
{
|
|
|
|
fZoomCenterX = SkFloatToScalar(x);
|
|
|
|
fZoomCenterY = SkFloatToScalar(y);
|
|
|
|
}
|
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,
|
|
|
|
SampleWindow::kGPU_DeviceType,
|
|
|
|
SampleWindow::kRaster_DeviceType
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
return gCT[ct];
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* devManager) : INHERITED(hwnd) {
|
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
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
fPicture = NULL;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
#ifdef DEFAULT_TO_GPU
|
2011-07-14 14:30:46 +00:00
|
|
|
fDeviceType = kGPU_DeviceType;
|
2010-12-20 18:26:13 +00:00
|
|
|
#else
|
2011-07-14 14:30:46 +00:00
|
|
|
fDeviceType = kRaster_DeviceType;
|
2010-12-20 18:26:13 +00:00
|
|
|
#endif
|
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
|
|
|
fRepeatDrawing = false;
|
|
|
|
fAnimating = false;
|
2009-08-14 16:08:38 +00:00
|
|
|
fRotate = false;
|
|
|
|
fScale = false;
|
2010-12-20 18:26:13 +00:00
|
|
|
fRequestGrabImage = false;
|
2011-05-11 05:58:58 +00:00
|
|
|
fUsePipe = false;
|
2011-04-22 01:59:09 +00:00
|
|
|
fMeasureFPS = false;
|
2011-08-08 15:37:23 +00:00
|
|
|
fLCDState = SkOSMenu::kMixedState;
|
|
|
|
fAAState = SkOSMenu::kMixedState;
|
|
|
|
fFilterState = SkOSMenu::kMixedState;
|
|
|
|
fHintingState = SkOSMenu::kMixedState;
|
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;
|
2011-08-02 13:39:12 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
fZoomLevel = 0;
|
|
|
|
fZoomScale = SK_Scalar1;
|
2011-08-08 15:37:23 +00:00
|
|
|
|
|
|
|
fMagnify = false;
|
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
fSaveToPdf = false;
|
|
|
|
fPdfCanvas = NULL;
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
fTransitionNext = 6;
|
|
|
|
fTransitionPrev = 2;
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
int sinkID = this->getSinkID();
|
|
|
|
fAppMenu.setTitle("Global Settings");
|
2011-08-08 15:37:23 +00:00
|
|
|
int itemID;
|
|
|
|
|
|
|
|
itemID =fAppMenu.appendList("Device Type", "Device Type", sinkID, 0, "Raster", "Picture", "OpenGL", NULL);
|
|
|
|
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');
|
|
|
|
itemID = fAppMenu.appendTriState("Filter", "Filter", sinkID, fFilterState);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'n');
|
|
|
|
itemID = fAppMenu.appendTriState("Hinting", "Hinting", sinkID, fHintingState);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'h');
|
|
|
|
itemID = fAppMenu.appendSwitch("Pipe", "Pipe" , sinkID, fUsePipe);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'p');
|
|
|
|
itemID = fAppMenu.appendSwitch("Slide Show", "Slide Show" , sinkID, false);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'a');
|
|
|
|
itemID = fAppMenu.appendSwitch("Clip", "Clip" , sinkID, fUseClip);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'c');
|
|
|
|
itemID = fAppMenu.appendSwitch("Measure FPS", "Measure FPS" , sinkID, fMeasureFPS);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'f');
|
|
|
|
itemID = fAppMenu.appendSwitch("Flip X", "Flip X" , sinkID, false);
|
|
|
|
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');
|
|
|
|
itemID =fAppMenu.appendList("Transition-Next", "Transition-Next", sinkID,
|
|
|
|
fTransitionNext, "Up", "Up and Right", "Right",
|
|
|
|
"Down and Right", "Down", "Down and Left",
|
|
|
|
"Left", "Up and Left", NULL);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'j');
|
|
|
|
itemID =fAppMenu.appendList("Transition-Prev", "Transition-Prev", sinkID,
|
|
|
|
fTransitionPrev, "Up", "Up and Right", "Right",
|
|
|
|
"Down and Right", "Down", "Down and Left",
|
|
|
|
"Left", "Up and Left", NULL);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'k');
|
|
|
|
itemID = fAppMenu.appendAction("Save to PDF", sinkID);
|
|
|
|
fAppMenu.assignKeyEquivalentToItem(itemID, 'e');
|
2011-08-02 13:39:12 +00:00
|
|
|
|
|
|
|
this->addMenu(&fAppMenu);
|
|
|
|
this->addMenu(&fSlideMenu);
|
|
|
|
|
2011-01-05 16:34:41 +00:00
|
|
|
// this->setConfig(SkBitmap::kRGB_565_Config);
|
|
|
|
this->setConfig(SkBitmap::kARGB_8888_Config);
|
|
|
|
this->setVisibleP(true);
|
2010-12-20 18:26:13 +00:00
|
|
|
this->setClipToBounds(false);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2009-11-03 04:00:48 +00:00
|
|
|
{
|
|
|
|
const SkViewRegister* reg = SkViewRegister::Head();
|
|
|
|
while (reg) {
|
|
|
|
*fSamples.append() = reg->factory();
|
|
|
|
reg = reg->next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fCurrIndex = 0;
|
2011-06-28 19:44:03 +00:00
|
|
|
if (argc > 1) {
|
|
|
|
int i, count = fSamples.count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
SkString title = getSampleTitle(i);
|
|
|
|
if (title.equals(argv[1])) {
|
|
|
|
fCurrIndex = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == count) {
|
|
|
|
fprintf(stderr, "Unknown sample \"%s\"\n", argv[1]);
|
|
|
|
}
|
|
|
|
}
|
2009-11-04 19:40:25 +00:00
|
|
|
this->loadView(fSamples[fCurrIndex]());
|
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;
|
|
|
|
}
|
|
|
|
fDevManager->init(this);
|
|
|
|
|
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();
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SampleWindow::~SampleWindow() {
|
|
|
|
delete fPicture;
|
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
|
|
|
}
|
|
|
|
|
2009-11-23 21:46:47 +00:00
|
|
|
static SkBitmap capture_bitmap(SkCanvas* canvas) {
|
|
|
|
SkBitmap bm;
|
|
|
|
const SkBitmap& src = canvas->getDevice()->accessBitmap(false);
|
|
|
|
src.copyTo(&bm, src.config());
|
|
|
|
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) {
|
2011-07-14 14:30:46 +00:00
|
|
|
if (!fDevManager->prepareCanvas(fDeviceType, canvas, this)) {
|
|
|
|
return;
|
|
|
|
}
|
2009-11-23 21:07:51 +00:00
|
|
|
// update the animation time
|
2010-12-20 18:26:13 +00:00
|
|
|
gAnimTimePrev = gAnimTime;
|
2009-11-23 21:07:51 +00:00
|
|
|
gAnimTime = SkTime::GetMSecs();
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
SkScalar cx = fZoomCenterX;
|
|
|
|
SkScalar cy = fZoomCenterY;
|
2011-04-05 13:07:03 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
if (fZoomLevel) {
|
|
|
|
SkMatrix m;
|
|
|
|
SkPoint center;
|
|
|
|
m = canvas->getTotalMatrix();//.invert(&m);
|
|
|
|
m.mapXY(cx, cy, ¢er);
|
|
|
|
cx = center.fX;
|
|
|
|
cy = center.fY;
|
2011-03-29 20:52:23 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
m.setTranslate(-cx, -cy);
|
|
|
|
m.postScale(fZoomScale, fZoomScale);
|
|
|
|
m.postTranslate(cx, cy);
|
2011-03-29 20:52:23 +00:00
|
|
|
|
2011-03-21 00:53:39 +00:00
|
|
|
canvas->concat(m);
|
|
|
|
}
|
2011-03-29 20:52:23 +00:00
|
|
|
|
2011-04-05 13:07:03 +00:00
|
|
|
if (fFlipAxis) {
|
|
|
|
SkMatrix m;
|
|
|
|
m.setTranslate(cx, cy);
|
|
|
|
if (fFlipAxis & kFlipAxis_X) {
|
|
|
|
m.preScale(-SK_Scalar1, SK_Scalar1);
|
|
|
|
}
|
|
|
|
if (fFlipAxis & kFlipAxis_Y) {
|
|
|
|
m.preScale(SK_Scalar1, -SK_Scalar1);
|
|
|
|
}
|
|
|
|
m.preTranslate(-cx, -cy);
|
|
|
|
canvas->concat(m);
|
|
|
|
}
|
2011-08-02 13:39:12 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
// Apply any gesture matrix
|
|
|
|
if (true) {
|
|
|
|
const SkMatrix& localM = fGesture.localM();
|
|
|
|
if (localM.getType() & SkMatrix::kScale_Mask) {
|
|
|
|
canvas->setExternalMatrix(&localM);
|
|
|
|
}
|
|
|
|
canvas->concat(localM);
|
|
|
|
canvas->concat(fGesture.globalM());
|
2011-03-29 20:52:23 +00:00
|
|
|
|
2011-03-16 12:10:02 +00:00
|
|
|
if (fGesture.isActive()) {
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
2011-08-02 13:39:12 +00:00
|
|
|
|
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 {
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
}
|
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);
|
|
|
|
}
|
2011-08-02 13:39:12 +00:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
SkMatrix m = canvas->getTotalMatrix();
|
|
|
|
m.invert(&m);
|
|
|
|
SkPoint offset, center;
|
|
|
|
m.mapXY(fMouseX - clipW/2, fMouseY - clipH/2, &offset);
|
|
|
|
m.mapXY(fMouseX, fMouseY, ¢er);
|
|
|
|
|
|
|
|
r.set(0, 0, clipW * m.getScaleX(), clipH * m.getScaleX());
|
|
|
|
r.offset(offset.fX, offset.fY);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(0xFF66AAEE);
|
|
|
|
paint.setStyle(SkPaint::kStroke_Style);
|
|
|
|
paint.setStrokeWidth(10.0 * m.getScaleX());
|
|
|
|
//lense offset
|
|
|
|
//canvas->translate(0, -250);
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
canvas->clipRect(r);
|
|
|
|
|
|
|
|
m = canvas->getTotalMatrix();
|
|
|
|
m.setTranslate(-center.fX, -center.fY);
|
|
|
|
m.postScale(0.5 * fFatBitsScale, 0.5 * fFatBitsScale);
|
|
|
|
m.postTranslate(center.fX, center.fY);
|
|
|
|
canvas->concat(m);
|
|
|
|
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
|
|
|
|
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.
|
2011-04-14 17:53:24 +00:00
|
|
|
int width = SkScalarRound(this->width());
|
|
|
|
int height = SkScalarRound(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) {
|
|
|
|
if (fRepeatDrawing) {
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
|
|
|
|
static void reverseRedAndBlue(const SkBitmap& bm) {
|
|
|
|
SkASSERT(bm.config() == SkBitmap::kARGB_8888_Config);
|
|
|
|
uint8_t* p = (uint8_t*)bm.getPixels();
|
|
|
|
uint8_t* stop = p + bm.getSize();
|
|
|
|
while (p < stop) {
|
|
|
|
// swap red/blue (to go from ARGB(int) to RGBA(memory) and premultiply
|
|
|
|
unsigned scale = SkAlpha255To256(p[3]);
|
|
|
|
unsigned r = p[2];
|
|
|
|
unsigned b = p[0];
|
|
|
|
p[0] = SkAlphaMul(r, scale);
|
|
|
|
p[1] = SkAlphaMul(p[1], scale);
|
|
|
|
p[2] = SkAlphaMul(b, scale);
|
|
|
|
p += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
} else {
|
2011-07-14 14:30:46 +00:00
|
|
|
switch (fDeviceType) {
|
|
|
|
case kRaster_DeviceType:
|
|
|
|
case kGPU_DeviceType:
|
2010-12-20 18:26:13 +00:00
|
|
|
canvas = this->INHERITED::beforeChildren(canvas);
|
2011-06-21 14:44:57 +00:00
|
|
|
break;
|
2011-07-14 14:30:46 +00:00
|
|
|
case kPicture_DeviceType:
|
2011-06-21 14:44:57 +00:00
|
|
|
fPicture = new SkPicture;
|
|
|
|
canvas = fPicture->beginRecording(9999, 9999);
|
|
|
|
break;
|
2010-12-22 21:39:39 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fUseClip) {
|
|
|
|
canvas->drawColor(0xFFFF88FF);
|
|
|
|
canvas->clipPath(fClipPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
#ifdef ANDROID
|
|
|
|
name.prepend("/sdcard/");
|
|
|
|
#endif
|
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());
|
|
|
|
}
|
2011-06-24 16:04:50 +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;
|
|
|
|
}
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
if (fRequestGrabImage) {
|
|
|
|
fRequestGrabImage = false;
|
2011-01-18 20:57:22 +00:00
|
|
|
|
2011-07-06 17:56:47 +00:00
|
|
|
SkDevice* device = orig->getDevice();
|
2011-04-05 17:08:27 +00:00
|
|
|
SkBitmap bmp;
|
|
|
|
if (device->accessBitmap(false).copyTo(&bmp, SkBitmap::kARGB_8888_Config)) {
|
2010-12-20 18:26:13 +00:00
|
|
|
static int gSampleGrabCounter;
|
|
|
|
SkString name;
|
|
|
|
name.printf("sample_grab_%d", 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) {
|
|
|
|
if (true) {
|
|
|
|
SkPicture* pict = new SkPicture(*fPicture);
|
|
|
|
fPicture->unref();
|
|
|
|
orig->drawPicture(*pict);
|
|
|
|
pict->unref();
|
|
|
|
} else if (true) {
|
|
|
|
SkDynamicMemoryWStream ostream;
|
|
|
|
fPicture->serialize(&ostream);
|
|
|
|
fPicture->unref();
|
|
|
|
|
|
|
|
SkAutoDataUnref data(ostream.copyToData());
|
|
|
|
SkMemoryStream istream(data.data(), data.size());
|
|
|
|
SkPicture pict(&istream);
|
|
|
|
orig->drawPicture(pict);
|
|
|
|
} else {
|
|
|
|
fPicture->draw(orig);
|
|
|
|
fPicture->unref();
|
|
|
|
}
|
|
|
|
fPicture = NULL;
|
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
|
|
|
|
if (fMeasureFPS && fMeasureFPS_Time) {
|
|
|
|
fMeasureFPS_Time = SkTime::GetMSecs() - fMeasureFPS_Time;
|
|
|
|
this->updateTitle();
|
2011-06-21 16:01:26 +00:00
|
|
|
this->postInvalDelay();
|
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-04-22 01:59:09 +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 (fScale) {
|
|
|
|
SkScalar scale = SK_Scalar1 * 7 / 10;
|
|
|
|
SkScalar cx = this->width() / 2;
|
|
|
|
SkScalar cy = this->height() / 2;
|
|
|
|
canvas->translate(cx, cy);
|
|
|
|
canvas->scale(scale, scale);
|
|
|
|
canvas->translate(-cx, -cy);
|
|
|
|
}
|
|
|
|
if (fRotate) {
|
|
|
|
SkScalar cx = this->width() / 2;
|
|
|
|
SkScalar cy = this->height() / 2;
|
|
|
|
canvas->translate(cx, cy);
|
|
|
|
canvas->rotate(SkIntToScalar(30));
|
|
|
|
canvas->translate(-cx, -cy);
|
|
|
|
}
|
2011-03-11 20:08:25 +00:00
|
|
|
|
2011-05-18 12:04:31 +00:00
|
|
|
canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState,
|
|
|
|
fFilterState, fHintingState))->unref();
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
if (fMeasureFPS) {
|
2011-04-22 14:10:48 +00:00
|
|
|
fMeasureFPS_Time = 0; // 0 means the child is not aware of repeat-draw
|
|
|
|
if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
|
|
|
|
fMeasureFPS_Time = SkTime::GetMSecs();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
(void)SampleView::SetRepeatDraw(child, 1);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2011-05-11 05:58:58 +00:00
|
|
|
(void)SampleView::SetUsePipe(child, fUsePipe);
|
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
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
static SkBitmap::Config gConfigCycle[] = {
|
|
|
|
SkBitmap::kNo_Config, // none -> none
|
|
|
|
SkBitmap::kNo_Config, // a1 -> none
|
|
|
|
SkBitmap::kNo_Config, // a8 -> none
|
|
|
|
SkBitmap::kNo_Config, // index8 -> none
|
|
|
|
SkBitmap::kARGB_4444_Config, // 565 -> 4444
|
|
|
|
SkBitmap::kARGB_8888_Config, // 4444 -> 8888
|
|
|
|
SkBitmap::kRGB_565_Config // 8888 -> 565
|
|
|
|
};
|
|
|
|
|
|
|
|
static SkBitmap::Config cycle_configs(SkBitmap::Config c) {
|
|
|
|
return gConfigCycle[c];
|
|
|
|
}
|
|
|
|
|
2011-06-13 16:58:40 +00:00
|
|
|
void SampleWindow::changeZoomLevel(float delta) {
|
|
|
|
fZoomLevel += SkFloatToScalar(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-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();
|
2011-08-08 15:37:23 +00:00
|
|
|
this->loadView(create_transition(curr_view(this), fSamples[fCurrIndex](),
|
|
|
|
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();
|
2011-08-08 15:37:23 +00:00
|
|
|
this->loadView(create_transition(curr_view(this), fSamples[fCurrIndex](),
|
|
|
|
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-08-08 15:37:23 +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) {
|
|
|
|
SkView* view = fSamples[i]();
|
|
|
|
SkString title;
|
2011-08-08 15:37:23 +00:00
|
|
|
SampleCode::RequestTitle(view, &title);
|
2011-06-24 16:04:50 +00:00
|
|
|
view->unref();
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SampleWindow::sampleCount() {
|
|
|
|
return fSamples.count();
|
|
|
|
}
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
void SampleWindow::showOverview() {
|
|
|
|
this->loadView(create_transition(curr_view(this),
|
|
|
|
create_overview(fSamples.count(), fSamples.begin()),
|
|
|
|
4));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
bool SampleWindow::onEvent(const SkEvent& evt) {
|
|
|
|
if (evt.isType(ANIMATING_EVENTTYPE)) {
|
|
|
|
if (fAnimating) {
|
|
|
|
this->nextSample();
|
|
|
|
this->postAnimatingEvent();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (evt.isType("unref-transition-view")) {
|
|
|
|
SkEventSink::FindSink(evt.getFast32())->unref();
|
|
|
|
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;
|
|
|
|
if (SkOSMenu::FindListIndex(&evt, "Device Type", &selected)) {
|
|
|
|
this->setDeviceType((DeviceType)selected);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkOSMenu::FindSwitchState(&evt, "Pipe", NULL)) {
|
|
|
|
this->togglePipe();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkOSMenu::FindSwitchState(&evt, "Slide Show", NULL)) {
|
|
|
|
this->toggleSlideshow();
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
if (SkOSMenu::FindTriState(&evt, "AA", &fAAState) ||
|
|
|
|
SkOSMenu::FindTriState(&evt, "LCD", &fLCDState) ||
|
|
|
|
SkOSMenu::FindTriState(&evt, "Filter", &fFilterState) ||
|
|
|
|
SkOSMenu::FindTriState(&evt, "Hinting", &fHintingState) ||
|
|
|
|
SkOSMenu::FindSwitchState(&evt, "Clip", &fUseClip) ||
|
|
|
|
SkOSMenu::FindSwitchState(&evt, "Zoomer", &fShowZoomer) ||
|
|
|
|
SkOSMenu::FindSwitchState(&evt, "Magnify", &fMagnify) ||
|
|
|
|
SkOSMenu::FindSwitchState(&evt, "Measure FPS", &fMeasureFPS) ||
|
|
|
|
SkOSMenu::FindListIndex(&evt, "Transition-Next", &fTransitionNext) ||
|
|
|
|
SkOSMenu::FindListIndex(&evt, "Transition-Prev", &fTransitionPrev)) {
|
2011-08-02 13:39:12 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkOSMenu::FindSwitchState(&evt, "Flip X", NULL)) {
|
|
|
|
fFlipAxis ^= kFlipAxis_X;
|
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (SkOSMenu::FindSwitchState(&evt, "Flip Y", NULL)) {
|
|
|
|
fFlipAxis ^= kFlipAxis_Y;
|
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
if (SkOSMenu::FindAction(&evt,"Save to PDF")) {
|
|
|
|
this->saveToPdf();
|
|
|
|
return true;
|
|
|
|
}
|
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")) {
|
|
|
|
SkView* view = fSamples[query->getFast32()]();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-08 15:37:23 +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) {
|
2010-12-20 18:26:13 +00:00
|
|
|
case 'd':
|
|
|
|
SkGraphics::SetFontCacheUsed(0);
|
|
|
|
return true;
|
|
|
|
case 'g':
|
|
|
|
fRequestGrabImage = true;
|
|
|
|
this->inval(NULL);
|
|
|
|
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;
|
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
|
|
|
case 's':
|
|
|
|
fScale = !fScale;
|
|
|
|
this->inval(NULL);
|
|
|
|
this->updateTitle();
|
|
|
|
return true;
|
2008-12-23 16:49:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
|
|
|
|
if (fAppMenu.handleKeyEquivalent(uni)|| fSlideMenu.handleKeyEquivalent(uni)) {
|
|
|
|
this->onUpdateMenu(&fAppMenu);
|
|
|
|
this->onUpdateMenu(&fSlideMenu);
|
|
|
|
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) {
|
|
|
|
if (type != fDeviceType && fDevManager->supportsDeviceType(fDeviceType))
|
|
|
|
fDeviceType = type;
|
|
|
|
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() {
|
2011-07-14 14:30:46 +00:00
|
|
|
DeviceType origDevType = fDeviceType;
|
|
|
|
do {
|
|
|
|
fDeviceType = cycle_devicetype(fDeviceType);
|
|
|
|
} while (origDevType != fDeviceType &&
|
|
|
|
!fDevManager->supportsDeviceType(fDeviceType));
|
2011-06-15 16:49:08 +00:00
|
|
|
this->updateTitle();
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
void SampleWindow::togglePipe() {
|
|
|
|
fUsePipe = !fUsePipe;
|
2011-08-08 15:37:23 +00:00
|
|
|
#ifdef PIPE_NET
|
|
|
|
if (!fUsePipe)
|
|
|
|
gServer.disconnectAll();
|
|
|
|
#endif
|
2011-08-02 13:39:12 +00:00
|
|
|
this->updateTitle();
|
2011-08-08 15:37:23 +00:00
|
|
|
this->inval(NULL);
|
2011-08-02 13:39:12 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2011-06-15 16:49:08 +00:00
|
|
|
toggleRendering();
|
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) {
|
2011-06-13 16:58:40 +00:00
|
|
|
this->changeZoomLevel(1.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) {
|
2011-06-13 16:58:40 +00:00
|
|
|
this->changeZoomLevel(-1.f);
|
2011-03-21 00:53:39 +00:00
|
|
|
} else {
|
|
|
|
this->setConfig(cycle_configs(this->getBitmap().config()));
|
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 kOK_SkKey:
|
2010-12-20 18:26:13 +00:00
|
|
|
if (false) {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkDebugfDumper dumper;
|
|
|
|
SkDumpCanvas dc(&dumper);
|
|
|
|
this->draw(&dc);
|
|
|
|
} else {
|
|
|
|
fRepeatDrawing = !fRepeatDrawing;
|
|
|
|
if (fRepeatDrawing) {
|
|
|
|
this->inval(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
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,
|
|
|
|
void* owner) {
|
2011-03-24 18:35:50 +00:00
|
|
|
if (Click::kMoved_State == state) {
|
|
|
|
updatePointer(x, y);
|
|
|
|
}
|
2011-03-21 00:53:39 +00:00
|
|
|
int w = SkScalarRound(this->width());
|
|
|
|
int h = SkScalarRound(this->height());
|
|
|
|
|
|
|
|
// check for the resize-box
|
|
|
|
if (w - x < 16 && h - y < 16) {
|
|
|
|
return false; // let the OS handle the click
|
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
|
|
|
|
}
|
|
|
|
else {
|
2011-06-22 13:26:56 +00:00
|
|
|
return this->INHERITED::onDispatchClick(x, y, state, owner);
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SkView::Click* SampleWindow::onFindClickHandler(SkScalar x, SkScalar y) {
|
|
|
|
return new GestureClick(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleWindow::onClick(Click* click) {
|
|
|
|
if (GestureClick::IsGesture(click)) {
|
|
|
|
float x = SkScalarToFloat(click->fCurr.fX);
|
|
|
|
float y = SkScalarToFloat(click->fCurr.fY);
|
2011-08-08 15:37:23 +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-03-16 12:10:02 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
break;
|
|
|
|
case SkView::Click::kUp_State:
|
2011-06-22 13:26:56 +00:00
|
|
|
fGesture.touchEnd(click->fOwner);
|
2011-03-16 12:10:02 +00:00
|
|
|
this->inval(NULL);
|
|
|
|
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();
|
|
|
|
}
|
2011-01-18 20:57:22 +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
|
|
|
|
fSlideMenu.reset();
|
|
|
|
if (SampleView::IsSampleView(view))
|
2011-08-08 15:37:23 +00:00
|
|
|
((SampleView*)view)->requestMenu(&fSlideMenu);
|
2011-08-02 13:39:12 +00:00
|
|
|
this->onUpdateMenu(&fSlideMenu);
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
this->updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* gConfigNames[] = {
|
|
|
|
"unknown config",
|
|
|
|
"A1",
|
|
|
|
"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: ",
|
|
|
|
"opengl: "
|
|
|
|
};
|
|
|
|
|
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() {
|
|
|
|
SkString title;
|
|
|
|
|
|
|
|
SkView::F2BIter iter(this);
|
|
|
|
SkView* view = iter.next();
|
|
|
|
SkEvent evt(gTitleEvtName);
|
|
|
|
if (view->doQuery(&evt)) {
|
|
|
|
title.set(evt.findString(gTitleEvtName));
|
|
|
|
}
|
|
|
|
if (title.size() == 0) {
|
|
|
|
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
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
if (fAnimating) {
|
|
|
|
title.prepend("<A> ");
|
|
|
|
}
|
2009-08-14 16:08:38 +00:00
|
|
|
if (fScale) {
|
|
|
|
title.prepend("<S> ");
|
|
|
|
}
|
|
|
|
if (fRotate) {
|
|
|
|
title.prepend("<R> ");
|
|
|
|
}
|
2009-11-23 20:10:41 +00:00
|
|
|
if (fNClip) {
|
|
|
|
title.prepend("<C> ");
|
|
|
|
}
|
2011-04-05 13:07:03 +00:00
|
|
|
|
|
|
|
title.prepend(trystate_str(fLCDState, "LCD ", "lcd "));
|
|
|
|
title.prepend(trystate_str(fAAState, "AA ", "aa "));
|
2011-05-18 12:04:31 +00:00
|
|
|
title.prepend(trystate_str(fFilterState, "H ", "h "));
|
2011-04-05 13:07:03 +00:00
|
|
|
title.prepend(fFlipAxis & kFlipAxis_X ? "X " : NULL);
|
|
|
|
title.prepend(fFlipAxis & kFlipAxis_Y ? "Y " : NULL);
|
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
|
|
|
}
|
2011-04-22 01:59:09 +00:00
|
|
|
|
|
|
|
if (fMeasureFPS) {
|
2011-05-18 20:10:31 +00:00
|
|
|
title.appendf(" %6.1f ms", fMeasureFPS_Time / (float)FPS_REPEAT_MULTIPLIER);
|
2011-04-22 01:59:09 +00:00
|
|
|
}
|
2011-05-12 22:08:24 +00:00
|
|
|
if (fUsePipe && SampleView::IsSampleView(view)) {
|
|
|
|
title.prepend("<P> ");
|
|
|
|
}
|
|
|
|
if (SampleView::IsSampleView(view)) {
|
|
|
|
title.prepend("! ");
|
|
|
|
}
|
2011-04-22 01:59:09 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
this->setTitle(title.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleWindow::onSizeChange() {
|
|
|
|
this->INHERITED::onSizeChange();
|
2011-07-06 17:56:47 +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-06-16 15:31:26 +00:00
|
|
|
#ifdef 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);
|
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
|
|
|
}
|
|
|
|
|
2011-05-11 05:58:58 +00:00
|
|
|
bool SampleView::SetUsePipe(SkView* view, bool pred) {
|
|
|
|
SkEvent evt(set_use_pipe_tag);
|
|
|
|
evt.setFast32(pred);
|
|
|
|
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;
|
|
|
|
}
|
2011-05-11 05:58:58 +00:00
|
|
|
if (evt.isType(set_use_pipe_tag)) {
|
|
|
|
fUsePipe = !!evt.getFast32();
|
|
|
|
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-02 18:55:39 +00:00
|
|
|
#ifdef TEST_GPIPE
|
|
|
|
#include "SkGPipe.h"
|
2011-05-04 14:32:04 +00:00
|
|
|
|
|
|
|
class SimplePC : public SkGPipeController {
|
|
|
|
public:
|
|
|
|
SimplePC(SkCanvas* target);
|
|
|
|
~SimplePC();
|
2011-08-08 15:37:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User this method to halt/restart pipe
|
|
|
|
*/
|
|
|
|
void setWriteToPipe(bool writeToPipe) { fWriteToPipe = writeToPipe; }
|
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;
|
2011-08-08 15:37:23 +00:00
|
|
|
bool fWriteToPipe;
|
2011-05-04 14:32:04 +00:00
|
|
|
|
|
|
|
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;
|
2011-08-08 15:37:23 +00:00
|
|
|
fWriteToPipe = true;
|
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) {
|
|
|
|
SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten,
|
2011-08-08 15:37:23 +00:00
|
|
|
fAtomsWritten, fStatus);
|
|
|
|
|
|
|
|
if (fWriteToPipe) {
|
|
|
|
#ifdef PIPE_FILE
|
|
|
|
//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);
|
|
|
|
#endif
|
|
|
|
#ifdef PIPE_NET
|
|
|
|
if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done
|
|
|
|
gServer.acceptConnections();
|
|
|
|
gServer.writePacket(fBlock, fTotalWritten);
|
|
|
|
}
|
|
|
|
#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;
|
2011-08-08 15:37:23 +00:00
|
|
|
|
2011-05-05 14:03:48 +00:00
|
|
|
fAtomsWritten += 1;
|
2011-05-04 14:32:04 +00:00
|
|
|
}
|
|
|
|
|
2011-05-02 18:55:39 +00:00
|
|
|
#endif
|
2011-05-02 17:33:45 +00:00
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
void SampleView::draw(SkCanvas* canvas) {
|
2011-05-11 05:58:58 +00:00
|
|
|
if (fUsePipe) {
|
2011-08-08 15:37:23 +00:00
|
|
|
SkGPipeWriter writer;
|
|
|
|
SimplePC controller(canvas);
|
2011-05-23 12:21:05 +00:00
|
|
|
uint32_t flags = SkGPipeWriter::kCrossProcess_Flag;
|
|
|
|
canvas = writer.startRecording(&controller, flags);
|
2011-08-08 15:37:23 +00:00
|
|
|
//Must draw before controller goes out of scope and sends data
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
controller.setWriteToPipe(fUsePipe);
|
2011-05-11 05:58:58 +00:00
|
|
|
}
|
2011-08-08 15:37:23 +00:00
|
|
|
else {
|
|
|
|
this->INHERITED::draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void SampleView::onDraw(SkCanvas* canvas) {
|
2011-06-01 12:42:36 +00:00
|
|
|
this->onDrawBackground(canvas);
|
|
|
|
|
2011-04-22 01:59:09 +00:00
|
|
|
for (int i = 0; i < fRepeatCount; i++) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
this->onDrawContent(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
static void rand_rect(SkIRect* rect, SkRandom& rand) {
|
|
|
|
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
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
SkRandom rand;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 19:44:03 +00:00
|
|
|
SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
|
2010-12-20 18:26:13 +00:00
|
|
|
// test();
|
2011-07-14 14:30:46 +00:00
|
|
|
return new SampleWindow(hwnd, argc, argv, NULL);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void application_init() {
|
|
|
|
// setenv("ANDROID_ROOT", "../../../data", 0);
|
2009-12-18 21:33:39 +00:00
|
|
|
#ifdef SK_BUILD_FOR_MAC
|
2008-12-17 15:59:43 +00:00
|
|
|
setenv("ANDROID_ROOT", "/android/device/data", 0);
|
2009-12-18 21:33:39 +00:00
|
|
|
#endif
|
2011-01-05 16:34:41 +00:00
|
|
|
SkGraphics::Init();
|
|
|
|
SkEvent::Init();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void application_term() {
|
2011-01-05 16:34:41 +00:00
|
|
|
SkEvent::Term();
|
|
|
|
SkGraphics::Term();
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|