2011-07-28 18:26:00 +04:00
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
/*
|
2011-07-28 18:26:00 +04:00
|
|
|
* Copyright 2011 Skia
|
2011-06-15 20:49:08 +04:00
|
|
|
*
|
2011-07-28 18:26:00 +04:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-06-15 20:49:08 +04:00
|
|
|
*/
|
|
|
|
|
2011-07-28 18:26:00 +04:00
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
#ifndef SampleWindow_DEFINED
|
|
|
|
#define SampleWindow_DEFINED
|
|
|
|
|
|
|
|
#include "SkWindow.h"
|
|
|
|
|
|
|
|
#include "SampleCode.h"
|
|
|
|
#include "SkPath.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkTouchGesture.h"
|
|
|
|
#include "SkWindow.h"
|
2011-08-02 17:39:12 +04:00
|
|
|
#include "SkOSMenu.h"
|
2011-06-15 20:49:08 +04:00
|
|
|
|
|
|
|
class GrContext;
|
2011-07-06 21:56:47 +04:00
|
|
|
class GrRenderTarget;
|
2011-06-15 20:49:08 +04:00
|
|
|
|
|
|
|
class SkEvent;
|
|
|
|
class SkCanvas;
|
|
|
|
class SkPicture;
|
|
|
|
class SkTypeface;
|
2011-06-24 20:04:50 +04:00
|
|
|
class SkData;
|
2011-06-15 20:49:08 +04:00
|
|
|
|
|
|
|
class SampleWindow : public SkOSWindow {
|
2011-10-31 18:18:20 +04:00
|
|
|
SkTDArray<const SkViewFactory*> fSamples;
|
2011-06-15 20:49:08 +04:00
|
|
|
public:
|
2011-07-14 18:30:46 +04:00
|
|
|
enum DeviceType {
|
|
|
|
kRaster_DeviceType,
|
|
|
|
kPicture_DeviceType,
|
2011-10-28 00:44:19 +04:00
|
|
|
kGPU_DeviceType,
|
|
|
|
kNullGPU_DeviceType
|
2011-07-14 18:30:46 +04:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* SampleApp ports can subclass this manager class if they want to:
|
|
|
|
* * filter the types of devices supported
|
|
|
|
* * customize plugging of SkDevice objects into an SkCanvas
|
|
|
|
* * customize publishing the results of draw to the OS window
|
|
|
|
* * manage GrContext / GrRenderTarget lifetimes
|
|
|
|
*/
|
|
|
|
class DeviceManager : public SkRefCnt {
|
|
|
|
public:
|
|
|
|
// called at end of SampleWindow cons
|
|
|
|
virtual void init(SampleWindow* win) = 0;
|
|
|
|
|
|
|
|
// called when selecting a new device type
|
|
|
|
// can disallow a device type by returning false.
|
|
|
|
virtual bool supportsDeviceType(DeviceType dType) = 0;
|
|
|
|
|
|
|
|
// called before drawing. should install correct device
|
|
|
|
// type on the canvas. Will skip drawing if returns false.
|
|
|
|
virtual bool prepareCanvas(DeviceType dType,
|
|
|
|
SkCanvas* canvas,
|
|
|
|
SampleWindow* win) = 0;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// return the GrContext backing gpu devices
|
2011-10-28 00:44:19 +04:00
|
|
|
virtual GrContext* getGrContext(DeviceType dType) = 0;
|
2011-07-14 18:30:46 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
SampleWindow(void* hwnd, int argc, char** argv, DeviceManager*);
|
2011-06-15 20:49:08 +04:00
|
|
|
virtual ~SampleWindow();
|
|
|
|
|
|
|
|
virtual void draw(SkCanvas* canvas);
|
|
|
|
|
2011-08-02 17:39:12 +04:00
|
|
|
void setDeviceType(DeviceType type);
|
2011-06-15 20:49:08 +04:00
|
|
|
void toggleRendering();
|
|
|
|
void toggleSlideshow();
|
|
|
|
void toggleFPS();
|
2011-08-08 19:37:23 +04:00
|
|
|
void showOverview();
|
2011-07-14 18:30:46 +04:00
|
|
|
|
2011-10-28 00:44:19 +04:00
|
|
|
GrContext* getGrContext() const { return fDevManager->getGrContext(fDeviceType); }
|
2011-07-14 18:30:46 +04:00
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
void setZoomCenter(float x, float y);
|
|
|
|
void changeZoomLevel(float delta);
|
|
|
|
bool nextSample();
|
|
|
|
bool previousSample();
|
2011-06-24 20:04:50 +04:00
|
|
|
bool goToSample(int i);
|
|
|
|
SkString getSampleTitle(int i);
|
|
|
|
int sampleCount();
|
2011-06-17 16:46:17 +04:00
|
|
|
bool handleTouch(int ownerId, float x, float y,
|
|
|
|
SkView::Click::State state);
|
2011-06-21 18:44:57 +04:00
|
|
|
void saveToPdf();
|
2011-06-24 20:04:50 +04:00
|
|
|
SkData* getPDFData() { return fPDFData; }
|
2011-06-21 20:01:26 +04:00
|
|
|
void postInvalDelay();
|
2011-06-15 20:49:08 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void onDraw(SkCanvas* canvas);
|
|
|
|
virtual bool onHandleKey(SkKey key);
|
|
|
|
virtual bool onHandleChar(SkUnichar);
|
|
|
|
virtual void onSizeChange();
|
|
|
|
|
|
|
|
virtual SkCanvas* beforeChildren(SkCanvas*);
|
|
|
|
virtual void afterChildren(SkCanvas*);
|
|
|
|
virtual void beforeChild(SkView* child, SkCanvas* canvas);
|
|
|
|
virtual void afterChild(SkView* child, SkCanvas* canvas);
|
|
|
|
|
|
|
|
virtual bool onEvent(const SkEvent& evt);
|
|
|
|
virtual bool onQuery(SkEvent* evt);
|
|
|
|
|
2011-06-22 17:26:56 +04:00
|
|
|
virtual bool onDispatchClick(int x, int y, Click::State, void* owner);
|
2011-06-15 20:49:08 +04:00
|
|
|
virtual bool onClick(Click* click);
|
|
|
|
virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
|
|
|
|
|
|
|
|
private:
|
2011-07-14 18:30:46 +04:00
|
|
|
class DefaultDeviceManager;
|
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
int fCurrIndex;
|
|
|
|
|
|
|
|
SkPicture* fPicture;
|
|
|
|
SkPath fClipPath;
|
|
|
|
|
|
|
|
SkTouchGesture fGesture;
|
|
|
|
SkScalar fZoomLevel;
|
|
|
|
SkScalar fZoomScale;
|
|
|
|
|
2011-07-14 18:30:46 +04:00
|
|
|
DeviceType fDeviceType;
|
|
|
|
DeviceManager* fDevManager;
|
2011-06-15 20:49:08 +04:00
|
|
|
|
2011-06-21 18:44:57 +04:00
|
|
|
bool fSaveToPdf;
|
|
|
|
SkCanvas* fPdfCanvas;
|
2011-06-24 20:04:50 +04:00
|
|
|
SkData* fPDFData;
|
2011-06-21 18:44:57 +04:00
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
bool fUseClip;
|
|
|
|
bool fNClip;
|
|
|
|
bool fRepeatDrawing;
|
|
|
|
bool fAnimating;
|
|
|
|
bool fRotate;
|
2011-09-08 22:48:12 +04:00
|
|
|
bool fPerspAnim;
|
|
|
|
SkScalar fPerspAnimTime;
|
2011-06-15 20:49:08 +04:00
|
|
|
bool fScale;
|
|
|
|
bool fRequestGrabImage;
|
|
|
|
bool fMeasureFPS;
|
|
|
|
SkMSec fMeasureFPS_Time;
|
2011-08-08 19:37:23 +04:00
|
|
|
bool fMagnify;
|
|
|
|
|
2011-08-12 18:27:47 +04:00
|
|
|
|
|
|
|
bool fUsePipe;
|
|
|
|
int fUsePipeMenuItemID;
|
|
|
|
bool fDebugger;
|
|
|
|
|
2011-06-15 20:49:08 +04: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;
|
2011-08-08 19:37:23 +04:00
|
|
|
|
|
|
|
SkOSMenu::TriState fLCDState;
|
|
|
|
SkOSMenu::TriState fAAState;
|
|
|
|
SkOSMenu::TriState fFilterState;
|
|
|
|
SkOSMenu::TriState fHintingState;
|
2011-06-15 20:49:08 +04:00
|
|
|
unsigned fFlipAxis;
|
|
|
|
|
|
|
|
int fScrollTestX, fScrollTestY;
|
|
|
|
SkScalar fZoomCenterX, fZoomCenterY;
|
|
|
|
|
2011-08-02 17:39:12 +04:00
|
|
|
//Stores global settings
|
|
|
|
SkOSMenu fAppMenu;
|
|
|
|
//Stores slide specific settings
|
|
|
|
SkOSMenu fSlideMenu;
|
2011-08-08 19:37:23 +04:00
|
|
|
int fTransitionNext;
|
|
|
|
int fTransitionPrev;
|
2011-08-02 17:39:12 +04:00
|
|
|
|
2011-06-15 20:49:08 +04:00
|
|
|
void loadView(SkView*);
|
|
|
|
void updateTitle();
|
|
|
|
|
|
|
|
bool zoomIn();
|
|
|
|
bool zoomOut();
|
|
|
|
void updatePointer(int x, int y);
|
2011-08-08 19:37:23 +04:00
|
|
|
void magnify(SkCanvas* canvas);
|
2011-06-15 20:49:08 +04:00
|
|
|
void showZoomer(SkCanvas* canvas);
|
|
|
|
|
|
|
|
void postAnimatingEvent();
|
|
|
|
|
|
|
|
typedef SkOSWindow INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|