2011-06-15 16:49:08 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2011 Skia
|
2011-06-15 16:49:08 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2012-09-29 12:40:30 +00:00
|
|
|
#ifndef SampleApp_DEFINED
|
|
|
|
#define SampleApp_DEFINED
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2012-09-29 12:40:30 +00:00
|
|
|
#include "SkOSMenu.h"
|
2011-06-15 16:49:08 +00:00
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTouchGesture.h"
|
|
|
|
#include "SkWindow.h"
|
|
|
|
|
|
|
|
class GrContext;
|
2011-07-06 17:56:47 +00:00
|
|
|
class GrRenderTarget;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
2012-09-29 12:40:30 +00:00
|
|
|
class SkData;
|
|
|
|
class SkEvent;
|
2011-06-15 16:49:08 +00:00
|
|
|
class SkPicture;
|
|
|
|
class SkTypeface;
|
2012-09-29 12:40:30 +00:00
|
|
|
class SkViewFactory;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
class SampleWindow : public SkOSWindow {
|
2011-10-31 14:18:20 +00:00
|
|
|
SkTDArray<const SkViewFactory*> fSamples;
|
2011-06-15 16:49:08 +00:00
|
|
|
public:
|
2011-07-14 14:30:46 +00:00
|
|
|
enum DeviceType {
|
|
|
|
kRaster_DeviceType,
|
|
|
|
kPicture_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2011-10-27 20:44:19 +00:00
|
|
|
kGPU_DeviceType,
|
2012-04-02 19:24:21 +00:00
|
|
|
#if SK_ANGLE
|
|
|
|
kANGLE_DeviceType,
|
2012-08-02 14:03:32 +00:00
|
|
|
#endif // SK_ANGLE
|
|
|
|
kNullGPU_DeviceType,
|
|
|
|
#endif // SK_SUPPORT_GPU
|
|
|
|
|
|
|
|
kDeviceTypeCnt
|
2011-07-14 14:30:46 +00:00
|
|
|
};
|
2013-01-24 20:47:18 +00:00
|
|
|
|
|
|
|
static bool IsGpuDeviceType(DeviceType devType) {
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
switch (devType) {
|
|
|
|
case kGPU_DeviceType:
|
|
|
|
#if SK_ANGLE
|
|
|
|
case kANGLE_DeviceType:
|
|
|
|
#endif // SK_ANGLE
|
|
|
|
case kNullGPU_DeviceType:
|
|
|
|
return true;
|
2013-01-24 22:09:06 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2013-01-24 20:47:18 +00:00
|
|
|
}
|
|
|
|
#endif // SK_SUPPORT_GPU
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
/**
|
|
|
|
* SampleApp ports can subclass this manager class if they want to:
|
|
|
|
* * filter the types of devices supported
|
2013-08-29 11:54:56 +00:00
|
|
|
* * customize plugging of SkBaseDevice objects into an SkCanvas
|
2011-07-14 14:30:46 +00:00
|
|
|
* * customize publishing the results of draw to the OS window
|
|
|
|
* * manage GrContext / GrRenderTarget lifetimes
|
|
|
|
*/
|
|
|
|
class DeviceManager : public SkRefCnt {
|
|
|
|
public:
|
2012-08-16 14:58:06 +00:00
|
|
|
SK_DECLARE_INST_COUNT(DeviceManager)
|
|
|
|
|
2012-04-06 20:13:38 +00:00
|
|
|
virtual void setUpBackend(SampleWindow* win, int msaaSampleCount) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual void tearDownBackend(SampleWindow* win) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
// called before drawing. should install correct device
|
|
|
|
// type on the canvas. Will skip drawing if returns false.
|
2012-10-01 20:31:56 +00:00
|
|
|
virtual SkCanvas* createCanvas(DeviceType dType, SampleWindow* win) = 0;
|
2011-07-14 14:30:46 +00:00
|
|
|
|
|
|
|
// called after drawing, should get the results onto the
|
|
|
|
// screen.
|
|
|
|
virtual void publishCanvas(DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) = 0;
|
|
|
|
|
|
|
|
// called when window changes size, guaranteed to be called
|
|
|
|
// at least once before first draw (after init)
|
|
|
|
virtual void windowSizeChanged(SampleWindow* win) = 0;
|
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
// return the GrContext backing gpu devices (NULL if not built with GPU support)
|
2012-04-02 19:24:21 +00:00
|
|
|
virtual GrContext* getGrContext() = 0;
|
2012-04-06 20:13:38 +00:00
|
|
|
|
2012-08-02 14:03:32 +00:00
|
|
|
// return the GrRenderTarget backing gpu devices (NULL if not built with GPU support)
|
2012-04-06 20:13:38 +00:00
|
|
|
virtual GrRenderTarget* getGrRenderTarget() = 0;
|
2012-08-16 14:58:06 +00:00
|
|
|
private:
|
|
|
|
typedef SkRefCnt INHERITED;
|
2011-07-14 14:30:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
|
2011-06-15 16:49:08 +00:00
|
|
|
virtual ~SampleWindow();
|
|
|
|
|
2012-10-01 20:31:56 +00:00
|
|
|
virtual SkCanvas* createCanvas() SK_OVERRIDE {
|
|
|
|
SkCanvas* canvas = NULL;
|
|
|
|
if (fDevManager) {
|
|
|
|
canvas = fDevManager->createCanvas(fDeviceType, this);
|
|
|
|
}
|
|
|
|
if (NULL == canvas) {
|
|
|
|
canvas = this->INHERITED::createCanvas();
|
|
|
|
}
|
|
|
|
return canvas;
|
|
|
|
}
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
virtual void draw(SkCanvas* canvas);
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
void setDeviceType(DeviceType type);
|
2011-06-15 16:49:08 +00:00
|
|
|
void toggleRendering();
|
|
|
|
void toggleSlideshow();
|
|
|
|
void toggleFPS();
|
2011-08-08 15:37:23 +00:00
|
|
|
void showOverview();
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
GrContext* getGrContext() const { return fDevManager->getGrContext(); }
|
2011-07-14 14:30:46 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void setZoomCenter(float x, float y);
|
|
|
|
void changeZoomLevel(float delta);
|
|
|
|
bool nextSample();
|
|
|
|
bool previousSample();
|
2011-06-24 16:04:50 +00:00
|
|
|
bool goToSample(int i);
|
|
|
|
SkString getSampleTitle(int i);
|
|
|
|
int sampleCount();
|
2011-06-17 12:46:17 +00:00
|
|
|
bool handleTouch(int ownerId, float x, float y,
|
|
|
|
SkView::Click::State state);
|
2011-06-21 14:44:57 +00:00
|
|
|
void saveToPdf();
|
2011-06-24 16:04:50 +00:00
|
|
|
SkData* getPDFData() { return fPDFData; }
|
2011-06-21 16:01:26 +00:00
|
|
|
void postInvalDelay();
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2012-04-02 19:24:21 +00:00
|
|
|
DeviceType getDeviceType() const { return fDeviceType; }
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
protected:
|
2013-01-08 16:17:50 +00:00
|
|
|
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE;
|
|
|
|
virtual bool onHandleKey(SkKey key) SK_OVERRIDE;
|
|
|
|
virtual bool onHandleChar(SkUnichar) SK_OVERRIDE;
|
|
|
|
virtual void onSizeChange() SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual SkCanvas* beforeChildren(SkCanvas*) SK_OVERRIDE;
|
|
|
|
virtual void afterChildren(SkCanvas*) SK_OVERRIDE;
|
|
|
|
virtual void beforeChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
|
|
|
|
virtual void afterChild(SkView* child, SkCanvas* canvas) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool onEvent(const SkEvent& evt) SK_OVERRIDE;
|
|
|
|
virtual bool onQuery(SkEvent* evt) SK_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool onDispatchClick(int x, int y, Click::State, void* owner,
|
|
|
|
unsigned modi) SK_OVERRIDE;
|
|
|
|
virtual bool onClick(Click* click) SK_OVERRIDE;
|
|
|
|
virtual Click* onFindClickHandler(SkScalar x, SkScalar y,
|
|
|
|
unsigned modi) SK_OVERRIDE;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2012-06-04 12:05:43 +00:00
|
|
|
void registerPictFileSamples(char** argv, int argc);
|
2012-08-01 17:58:01 +00:00
|
|
|
void registerPictFileSample(char** argv, int argc);
|
2012-06-04 12:05:43 +00:00
|
|
|
|
2013-07-11 14:28:04 +00:00
|
|
|
#ifdef SAMPLE_PDF_FILE_VIEWER
|
|
|
|
void registerPdfFileViewerSamples(char** argv, int argc);
|
|
|
|
#endif // SAMPLE_PDF_FILE_VIEWER
|
|
|
|
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
private:
|
2011-07-14 14:30:46 +00:00
|
|
|
class DefaultDeviceManager;
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
int fCurrIndex;
|
|
|
|
|
|
|
|
SkPicture* fPicture;
|
|
|
|
SkPath fClipPath;
|
|
|
|
|
|
|
|
SkTouchGesture fGesture;
|
|
|
|
SkScalar fZoomLevel;
|
|
|
|
SkScalar fZoomScale;
|
|
|
|
|
2011-07-14 14:30:46 +00:00
|
|
|
DeviceType fDeviceType;
|
|
|
|
DeviceManager* fDevManager;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
2011-06-21 14:44:57 +00:00
|
|
|
bool fSaveToPdf;
|
|
|
|
SkCanvas* fPdfCanvas;
|
2011-06-24 16:04:50 +00:00
|
|
|
SkData* fPDFData;
|
2011-06-21 14:44:57 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fUseClip;
|
|
|
|
bool fNClip;
|
|
|
|
bool fAnimating;
|
|
|
|
bool fRotate;
|
2013-07-09 21:58:56 +00:00
|
|
|
SkScalar fRotateAnimTime;
|
2011-09-08 18:48:12 +00:00
|
|
|
bool fPerspAnim;
|
|
|
|
SkScalar fPerspAnimTime;
|
2011-06-15 16:49:08 +00:00
|
|
|
bool fRequestGrabImage;
|
|
|
|
bool fMeasureFPS;
|
|
|
|
SkMSec fMeasureFPS_Time;
|
2012-12-10 14:12:55 +00:00
|
|
|
SkMSec fMeasureFPS_StartTime;
|
2011-08-08 15:37:23 +00:00
|
|
|
bool fMagnify;
|
2013-12-06 20:14:55 +00:00
|
|
|
int fTilingMode;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
|
|
|
|
2012-06-08 15:35:03 +00:00
|
|
|
SkOSMenu::TriState fPipeState; // Mixed uses a tiled pipe
|
|
|
|
// On uses a normal pipe
|
|
|
|
// Off uses no pipe
|
2011-08-12 14:27:47 +00:00
|
|
|
int fUsePipeMenuItemID;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
// The following are for the 'fatbits' drawing
|
|
|
|
// Latest position of the mouse.
|
|
|
|
int fMouseX, fMouseY;
|
|
|
|
int fFatBitsScale;
|
|
|
|
// Used by the text showing position and color values.
|
|
|
|
SkTypeface* fTypeface;
|
|
|
|
bool fShowZoomer;
|
2012-08-01 17:58:01 +00:00
|
|
|
|
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-06-15 16:49:08 +00:00
|
|
|
unsigned fFlipAxis;
|
|
|
|
|
2012-04-06 20:13:38 +00:00
|
|
|
int fMSAASampleCount;
|
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
int fScrollTestX, fScrollTestY;
|
|
|
|
SkScalar fZoomCenterX, fZoomCenterY;
|
|
|
|
|
2011-08-02 13:39:12 +00:00
|
|
|
//Stores global settings
|
2012-04-18 14:07:57 +00:00
|
|
|
SkOSMenu* fAppMenu; // We pass ownership to SkWindow, when we call addMenu
|
2011-08-02 13:39:12 +00:00
|
|
|
//Stores slide specific settings
|
2012-04-18 14:07:57 +00:00
|
|
|
SkOSMenu* fSlideMenu; // We pass ownership to SkWindow, when we call addMenu
|
|
|
|
|
2011-08-08 15:37:23 +00:00
|
|
|
int fTransitionNext;
|
|
|
|
int fTransitionPrev;
|
2012-04-18 14:07:57 +00:00
|
|
|
|
2011-06-15 16:49:08 +00:00
|
|
|
void loadView(SkView*);
|
|
|
|
void updateTitle();
|
|
|
|
|
|
|
|
bool zoomIn();
|
|
|
|
bool zoomOut();
|
|
|
|
void updatePointer(int x, int y);
|
2011-08-08 15:37:23 +00:00
|
|
|
void magnify(SkCanvas* canvas);
|
2011-06-15 16:49:08 +00:00
|
|
|
void showZoomer(SkCanvas* canvas);
|
2011-11-11 21:42:12 +00:00
|
|
|
void updateMatrix();
|
2011-06-15 16:49:08 +00:00
|
|
|
void postAnimatingEvent();
|
2011-12-08 19:36:00 +00:00
|
|
|
void installDrawFilter(SkCanvas*);
|
2011-12-27 22:33:50 +00:00
|
|
|
int findByTitle(const char*);
|
2012-05-03 18:22:28 +00:00
|
|
|
void listTitles();
|
2013-12-10 21:51:06 +00:00
|
|
|
SkSize tileSize() const;
|
2011-06-15 16:49:08 +00:00
|
|
|
|
|
|
|
typedef SkOSWindow INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|