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 "../private/SkTDArray.h" 12 #include "SkView.h" 13 #include "SkBitmap.h" 14 #include "SkMatrix.h" 15 #include "SkRegion.h" 16 #include "SkEvent.h" 17 #include "SkKey.h" 18 #include "SkSurfaceProps.h" 19 20 class SkSurface; 21 class SkOSMenu; 22 23 #if SK_SUPPORT_GPU 24 struct GrGLInterface; 25 class GrContext; 26 class GrRenderTarget; 27 #endif 28 29 class SkWindow : public SkView { 30 public: 31 SkWindow(); 32 virtual ~SkWindow(); 33 34 struct AttachmentInfo { AttachmentInfoAttachmentInfo35 AttachmentInfo() 36 : fSampleCount(0) 37 , fStencilBits(0) 38 , fColorBits(0) {} 39 40 int fSampleCount; 41 int fStencilBits; 42 int fColorBits; 43 }; 44 getSurfaceProps()45 SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } setSurfaceProps(const SkSurfaceProps & props)46 void setSurfaceProps(const SkSurfaceProps& props) { 47 fSurfaceProps = props; 48 } 49 info()50 SkImageInfo info() const { return fBitmap.info(); } getBitmap()51 const SkBitmap& getBitmap() const { return fBitmap; } 52 53 void resize(int width, int height); 54 void resize(const SkImageInfo&); 55 void setColorType(SkColorType, sk_sp<SkColorSpace>); 56 isDirty()57 bool isDirty() const { return !fDirtyRgn.isEmpty(); } 58 bool update(SkIRect* updateArea); 59 // does not call through to onHandleInval(), but does force the fDirtyRgn 60 // to be wide open. Call before update() to ensure we redraw everything. 61 void forceInvalAll(); 62 // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none getDirtyBounds()63 const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); } 64 65 bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0); 66 bool handleChar(SkUnichar); 67 bool handleKey(SkKey); 68 bool handleKeyUp(SkKey); 69 70 void addMenu(SkOSMenu*); getMenus()71 const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; } 72 getTitle()73 const char* getTitle() const { return fTitle.c_str(); } 74 void setTitle(const char title[]); 75 getMatrix()76 const SkMatrix& getMatrix() const { return fMatrix; } 77 void setMatrix(const SkMatrix&); 78 void preConcat(const SkMatrix&); 79 void postConcat(const SkMatrix&); 80 81 virtual sk_sp<SkSurface> makeSurface(); 82 83 #if SK_SUPPORT_GPU 84 sk_sp<SkSurface> makeGpuBackedSurface(const AttachmentInfo& attachmentInfo, 85 const GrGLInterface* , GrContext* grContext); 86 #endif 87 88 protected: 89 virtual bool onEvent(const SkEvent&); 90 virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); 91 // called if part of our bitmap is invalidated 92 virtual void onHandleInval(const SkIRect&); 93 virtual bool onHandleChar(SkUnichar); 94 virtual bool onHandleKey(SkKey); 95 virtual bool onHandleKeyUp(SkKey); onAddMenu(const SkOSMenu *)96 virtual void onAddMenu(const SkOSMenu*) {} onUpdateMenu(const SkOSMenu *)97 virtual void onUpdateMenu(const SkOSMenu*) {} onSetTitle(const char title[])98 virtual void onSetTitle(const char title[]) {} 99 100 // overrides from SkView 101 virtual bool handleInval(const SkRect*); 102 virtual bool onGetFocusView(SkView** focus) const; 103 virtual bool onSetFocusView(SkView* focus); 104 105 private: 106 SkSurfaceProps fSurfaceProps; 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 #error Android does not support SkOSWindow and SampleApp. Please use Viewer instead. 131 #elif defined(SK_BUILD_FOR_UNIX) 132 #include "SkOSWindow_Unix.h" 133 #elif defined(SK_BUILD_FOR_IOS) 134 #include "SkOSWindow_iOS.h" 135 #endif 136 137 #endif 138