reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkWindow_DEFINED |
| 9 | #define SkWindow_DEFINED |
| 10 | |
| 11 | #include "SkView.h" |
| 12 | #include "SkBitmap.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 13 | #include "SkMatrix.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 14 | #include "SkRegion.h" |
| 15 | #include "SkEvent.h" |
| 16 | #include "SkKey.h" |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 17 | #include "SkSurfaceProps.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | #include "SkTDArray.h" |
| 19 | |
reed | 0397e9f | 2014-09-18 11:29:01 -0700 | [diff] [blame] | 20 | class SkSurface; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | class SkOSMenu; |
| 22 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 23 | #if SK_SUPPORT_GPU |
| 24 | struct GrGLInterface; |
| 25 | class GrContext; |
| 26 | class GrRenderTarget; |
| 27 | #endif |
| 28 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 29 | class SkWindow : public SkView { |
| 30 | public: |
| 31 | SkWindow(); |
| 32 | virtual ~SkWindow(); |
| 33 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 34 | struct AttachmentInfo { |
| 35 | int fSampleCount; |
| 36 | int fStencilBits; |
| 37 | }; |
| 38 | |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 39 | SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; } |
| 40 | void setSurfaceProps(const SkSurfaceProps& props) { |
| 41 | fSurfaceProps = props; |
| 42 | } |
| 43 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 44 | const SkBitmap& getBitmap() const { return fBitmap; } |
| 45 | |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 46 | void setColorType(SkColorType); |
commit-bot@chromium.org | b45c56e | 2014-02-18 23:32:05 +0000 | [diff] [blame] | 47 | void resize(int width, int height, SkColorType = kUnknown_SkColorType); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | |
| 49 | bool isDirty() const { return !fDirtyRgn.isEmpty(); } |
reed@google.com | aa400ee | 2012-09-27 21:03:49 +0000 | [diff] [blame] | 50 | bool update(SkIRect* updateArea); |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 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 | |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 57 | bool handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 58 | bool handleChar(SkUnichar); |
| 59 | bool handleKey(SkKey); |
| 60 | bool handleKeyUp(SkKey); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 61 | |
| 62 | void addMenu(SkOSMenu*); |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 63 | const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 64 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 65 | const char* getTitle() const { return fTitle.c_str(); } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 66 | void setTitle(const char title[]); |
| 67 | |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 68 | const SkMatrix& getMatrix() const { return fMatrix; } |
| 69 | void setMatrix(const SkMatrix&); |
| 70 | void preConcat(const SkMatrix&); |
| 71 | void postConcat(const SkMatrix&); |
| 72 | |
reed | 0397e9f | 2014-09-18 11:29:01 -0700 | [diff] [blame] | 73 | virtual SkSurface* createSurface(); |
reed@google.com | 5957f47 | 2012-10-01 20:31:56 +0000 | [diff] [blame] | 74 | |
Scroggo | 8ac0d54 | 2011-06-21 14:44:57 +0000 | [diff] [blame] | 75 | virtual void onPDFSaved(const char title[], const char desc[], |
| 76 | const char path[]) {} |
joshualitt | da7b843 | 2015-05-27 09:19:03 -0700 | [diff] [blame] | 77 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | protected: |
| 79 | virtual bool onEvent(const SkEvent&); |
reed@google.com | 4d5c26d | 2013-01-08 16:17:50 +0000 | [diff] [blame] | 80 | virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 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); |
yangsu@google.com | 654d72f | 2011-08-01 17:27:33 +0000 | [diff] [blame] | 86 | virtual void onAddMenu(const SkOSMenu*) {}; |
| 87 | virtual void onUpdateMenu(const SkOSMenu*) {}; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 88 | virtual void onSetTitle(const char title[]) {} |
| 89 | |
| 90 | // overrides from SkView |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 91 | virtual bool handleInval(const SkRect*); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 92 | virtual bool onGetFocusView(SkView** focus) const; |
| 93 | virtual bool onSetFocusView(SkView* focus); |
| 94 | |
caryclark | c8fcafb | 2015-01-30 12:37:02 -0800 | [diff] [blame] | 95 | #if SK_SUPPORT_GPU |
| 96 | GrRenderTarget* renderTarget(const AttachmentInfo& attachmentInfo, |
| 97 | const GrGLInterface* , GrContext* grContext); |
| 98 | #endif |
| 99 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 100 | private: |
reed | 4302ae9 | 2014-10-06 12:29:56 -0700 | [diff] [blame] | 101 | SkSurfaceProps fSurfaceProps; |
commit-bot@chromium.org | e24ad23 | 2014-02-16 22:03:38 +0000 | [diff] [blame] | 102 | SkColorType fColorType; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 103 | SkBitmap fBitmap; |
| 104 | SkRegion fDirtyRgn; |
Scroggo | d3aed39 | 2011-06-22 13:26:56 +0000 | [diff] [blame] | 105 | |
| 106 | SkTDArray<Click*> fClicks; // to track clicks |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 107 | |
| 108 | SkTDArray<SkOSMenu*> fMenus; |
| 109 | |
| 110 | SkView* fFocusView; |
| 111 | bool fWaitingOnInval; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 112 | |
reed@android.com | 0ae6b24 | 2008-12-23 16:49:54 +0000 | [diff] [blame] | 113 | SkString fTitle; |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 114 | SkMatrix fMatrix; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 115 | |
| 116 | typedef SkView INHERITED; |
| 117 | }; |
| 118 | |
tfarina@chromium.org | e229e92 | 2012-09-27 13:44:57 +0000 | [diff] [blame] | 119 | //////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 120 | |
bungeman | 3ac6b75 | 2015-07-29 13:37:27 -0700 | [diff] [blame^] | 121 | #if defined(SK_USE_SDL) |
| 122 | #include "SkOSWindow_SDL.h" |
| 123 | #elif defined(SK_BUILD_FOR_MAC) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 124 | #include "SkOSWindow_Mac.h" |
| 125 | #elif defined(SK_BUILD_FOR_WIN) |
| 126 | #include "SkOSWindow_Win.h" |
djsollen@google.com | 56c6977 | 2011-11-08 19:00:26 +0000 | [diff] [blame] | 127 | #elif defined(SK_BUILD_FOR_ANDROID) |
Scroggo | f33d153 | 2011-05-31 17:10:21 +0000 | [diff] [blame] | 128 | #include "SkOSWindow_Android.h" |
scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame] | 129 | #elif defined(SK_BUILD_FOR_UNIX) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | #include "SkOSWindow_Unix.h" |
reed@android.com | f2b98d6 | 2010-12-20 18:26:13 +0000 | [diff] [blame] | 131 | #elif defined(SK_BUILD_FOR_IOS) |
| 132 | #include "SkOSWindow_iOS.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 133 | #endif |
| 134 | |
| 135 | #endif |