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