1 /* 2 * Copyright 2006 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkWindow_DEFINED 9 #define SkWindow_DEFINED 10 11 #include "SkView.h" 12 #include "SkBitmap.h" 13 #include "SkMatrix.h" 14 #include "SkRegion.h" 15 #include "SkEvent.h" 16 #include "SkKey.h" 17 #include "SkSurfaceProps.h" 18 #include "SkTDArray.h" 19 20 #ifdef SK_BUILD_FOR_WINCEx 21 #define SHOW_FPS 22 #endif 23 //#define USE_GX_SCREEN 24 25 class SkSurface; 26 class SkOSMenu; 27 28 #if SK_SUPPORT_GPU 29 struct GrGLInterface; 30 class GrContext; 31 class GrRenderTarget; 32 #endif 33 34 class SkWindow : public SkView { 35 public: 36 SkWindow(); 37 virtual ~SkWindow(); 38 39 struct AttachmentInfo { 40 int fSampleCount; 41 int fStencilBits; 42 }; 43 getSurfaceProps()44 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } setSurfaceProps(const SkSurfaceProps & props)45 void setSurfaceProps(const SkSurfaceProps& props) { 46 fSurfaceProps = props; 47 } 48 getBitmap()49 const SkBitmap& getBitmap() const { return fBitmap; } 50 51 void setColorType(SkColorType); 52 void resize(int width, int height, SkColorType = kUnknown_SkColorType); 53 isDirty()54 bool isDirty() const { return !fDirtyRgn.isEmpty(); } 55 bool update(SkIRect* updateArea); 56 // does not call through to onHandleInval(), but does force the fDirtyRgn 57 // to be wide open. Call before update() to ensure we redraw everything. 58 void forceInvalAll(); 59 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none getDirtyBounds()60 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); } 61 62 bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0); 63 bool handleChar(SkUnichar); 64 bool handleKey(SkKey); 65 bool handleKeyUp(SkKey); 66 67 void addMenu(SkOSMenu*); getMenus()68 const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; } 69 getTitle()70 const char* getTitle() const { return fTitle.c_str(); } 71 void setTitle(const char title[]); 72 getMatrix()73 const SkMatrix& getMatrix() const { return fMatrix; } 74 void setMatrix(const SkMatrix&); 75 void preConcat(const SkMatrix&); 76 void postConcat(const SkMatrix&); 77 78 virtual SkSurface* createSurface(); 79 onPDFSaved(const char title[],const char desc[],const char path[])80 virtual void onPDFSaved(const char title[], const char desc[], 81 const char path[]) {} 82 protected: 83 virtual bool onEvent(const SkEvent&); 84 virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); 85 // called if part of our bitmap is invalidated 86 virtual void onHandleInval(const SkIRect&); 87 virtual bool onHandleChar(SkUnichar); 88 virtual bool onHandleKey(SkKey); 89 virtual bool onHandleKeyUp(SkKey); onAddMenu(const SkOSMenu *)90 virtual void onAddMenu(const SkOSMenu*) {}; onUpdateMenu(const SkOSMenu *)91 virtual void onUpdateMenu(const SkOSMenu*) {}; onSetTitle(const char title[])92 virtual void onSetTitle(const char title[]) {} 93 94 // overrides from SkView 95 virtual bool handleInval(const SkRect*); 96 virtual bool onGetFocusView(SkView** focus) const; 97 virtual bool onSetFocusView(SkView* focus); 98 99 #if SK_SUPPORT_GPU 100 GrRenderTarget* renderTarget(const AttachmentInfo& attachmentInfo, 101 const GrGLInterface* , GrContext* grContext); 102 #endif 103 104 private: 105 SkSurfaceProps fSurfaceProps; 106 SkColorType fColorType; 107 SkBitmap fBitmap; 108 SkRegion fDirtyRgn; 109 110 SkTDArray<Click*> fClicks; // to track clicks 111 112 SkTDArray<SkOSMenu*> fMenus; 113 114 SkView* fFocusView; 115 bool fWaitingOnInval; 116 117 SkString fTitle; 118 SkMatrix fMatrix; 119 120 typedef SkView INHERITED; 121 }; 122 123 //////////////////////////////////////////////////////////////////////////////// 124 125 #if defined(SK_BUILD_FOR_MAC) 126 #include "SkOSWindow_Mac.h" 127 #elif defined(SK_BUILD_FOR_WIN) 128 #include "SkOSWindow_Win.h" 129 #elif defined(SK_BUILD_FOR_ANDROID) 130 #include "SkOSWindow_Android.h" 131 #elif defined(SK_BUILD_FOR_UNIX) 132 #include "SkOSWindow_Unix.h" 133 #elif defined(SK_BUILD_FOR_SDL) 134 #include "SkOSWindow_SDL.h" 135 #elif defined(SK_BUILD_FOR_IOS) 136 #include "SkOSWindow_iOS.h" 137 #endif 138 139 #endif 140