OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkWindow.h" | 8 #include "SkWindow.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkOSMenu.h" | 10 #include "SkOSMenu.h" |
11 #include "SkSurface.h" | 11 #include "SkSurface.h" |
12 #include "SkSystemEventTypes.h" | 12 #include "SkSystemEventTypes.h" |
13 #include "SkTime.h" | 13 #include "SkTime.h" |
14 | 14 |
15 #define SK_EventDelayInval "\xd" "n" "\xa" "l" | 15 #define SK_EventDelayInval "\xd" "n" "\xa" "l" |
16 | 16 |
17 SkWindow::SkWindow() | 17 SkWindow::SkWindow() |
18 : fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) | 18 : fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) |
19 , fFocusView(NULL) | 19 , fFocusView(nullptr) |
20 { | 20 { |
21 fClicks.reset(); | 21 fClicks.reset(); |
22 fWaitingOnInval = false; | 22 fWaitingOnInval = false; |
23 fColorType = kN32_SkColorType; | 23 fColorType = kN32_SkColorType; |
24 fMatrix.reset(); | 24 fMatrix.reset(); |
25 } | 25 } |
26 | 26 |
27 SkWindow::~SkWindow() { | 27 SkWindow::~SkWindow() { |
28 fClicks.deleteAll(); | 28 fClicks.deleteAll(); |
29 fMenus.deleteAll(); | 29 fMenus.deleteAll(); |
30 } | 30 } |
31 | 31 |
32 SkSurface* SkWindow::createSurface() { | 32 SkSurface* SkWindow::createSurface() { |
33 const SkBitmap& bm = this->getBitmap(); | 33 const SkBitmap& bm = this->getBitmap(); |
34 return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(),
&fSurfaceProps); | 34 return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(),
&fSurfaceProps); |
35 } | 35 } |
36 | 36 |
37 void SkWindow::setMatrix(const SkMatrix& matrix) { | 37 void SkWindow::setMatrix(const SkMatrix& matrix) { |
38 if (fMatrix != matrix) { | 38 if (fMatrix != matrix) { |
39 fMatrix = matrix; | 39 fMatrix = matrix; |
40 this->inval(NULL); | 40 this->inval(nullptr); |
41 } | 41 } |
42 } | 42 } |
43 | 43 |
44 void SkWindow::preConcat(const SkMatrix& matrix) { | 44 void SkWindow::preConcat(const SkMatrix& matrix) { |
45 SkMatrix m; | 45 SkMatrix m; |
46 m.setConcat(fMatrix, matrix); | 46 m.setConcat(fMatrix, matrix); |
47 this->setMatrix(m); | 47 this->setMatrix(m); |
48 } | 48 } |
49 | 49 |
50 void SkWindow::postConcat(const SkMatrix& matrix) { | 50 void SkWindow::postConcat(const SkMatrix& matrix) { |
51 SkMatrix m; | 51 SkMatrix m; |
52 m.setConcat(matrix, fMatrix); | 52 m.setConcat(matrix, fMatrix); |
53 this->setMatrix(m); | 53 this->setMatrix(m); |
54 } | 54 } |
55 | 55 |
56 void SkWindow::setColorType(SkColorType ct) { | 56 void SkWindow::setColorType(SkColorType ct) { |
57 this->resize(fBitmap.width(), fBitmap.height(), ct); | 57 this->resize(fBitmap.width(), fBitmap.height(), ct); |
58 } | 58 } |
59 | 59 |
60 void SkWindow::resize(int width, int height, SkColorType ct) { | 60 void SkWindow::resize(int width, int height, SkColorType ct) { |
61 if (ct == kUnknown_SkColorType) | 61 if (ct == kUnknown_SkColorType) |
62 ct = fColorType; | 62 ct = fColorType; |
63 | 63 |
64 if (width != fBitmap.width() || height != fBitmap.height() || ct != fColorTy
pe) { | 64 if (width != fBitmap.width() || height != fBitmap.height() || ct != fColorTy
pe) { |
65 fColorType = ct; | 65 fColorType = ct; |
66 fBitmap.allocPixels(SkImageInfo::Make(width, height, | 66 fBitmap.allocPixels(SkImageInfo::Make(width, height, |
67 ct, kPremul_SkAlphaType)); | 67 ct, kPremul_SkAlphaType)); |
68 | 68 |
69 this->setSize(SkIntToScalar(width), SkIntToScalar(height)); | 69 this->setSize(SkIntToScalar(width), SkIntToScalar(height)); |
70 this->inval(NULL); | 70 this->inval(nullptr); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 bool SkWindow::handleInval(const SkRect* localR) { | 74 bool SkWindow::handleInval(const SkRect* localR) { |
75 SkIRect ir; | 75 SkIRect ir; |
76 | 76 |
77 if (localR) { | 77 if (localR) { |
78 SkRect devR; | 78 SkRect devR; |
79 SkMatrix inverse; | 79 SkMatrix inverse; |
80 if (!fMatrix.invert(&inverse)) { | 80 if (!fMatrix.invert(&inverse)) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return true; | 139 return true; |
140 } | 140 } |
141 return false; | 141 return false; |
142 } | 142 } |
143 | 143 |
144 bool SkWindow::handleChar(SkUnichar uni) { | 144 bool SkWindow::handleChar(SkUnichar uni) { |
145 if (this->onHandleChar(uni)) | 145 if (this->onHandleChar(uni)) |
146 return true; | 146 return true; |
147 | 147 |
148 SkView* focus = this->getFocusView(); | 148 SkView* focus = this->getFocusView(); |
149 if (focus == NULL) | 149 if (focus == nullptr) |
150 focus = this; | 150 focus = this; |
151 | 151 |
152 SkEvent evt(SK_EventType_Unichar); | 152 SkEvent evt(SK_EventType_Unichar); |
153 evt.setFast32(uni); | 153 evt.setFast32(uni); |
154 return focus->doEvent(evt); | 154 return focus->doEvent(evt); |
155 } | 155 } |
156 | 156 |
157 bool SkWindow::handleKey(SkKey key) { | 157 bool SkWindow::handleKey(SkKey key) { |
158 if (key == kNONE_SkKey) | 158 if (key == kNONE_SkKey) |
159 return false; | 159 return false; |
160 | 160 |
161 if (this->onHandleKey(key)) | 161 if (this->onHandleKey(key)) |
162 return true; | 162 return true; |
163 | 163 |
164 // send an event to the focus-view | 164 // send an event to the focus-view |
165 { | 165 { |
166 SkView* focus = this->getFocusView(); | 166 SkView* focus = this->getFocusView(); |
167 if (focus == NULL) | 167 if (focus == nullptr) |
168 focus = this; | 168 focus = this; |
169 | 169 |
170 SkEvent evt(SK_EventType_Key); | 170 SkEvent evt(SK_EventType_Key); |
171 evt.setFast32(key); | 171 evt.setFast32(key); |
172 if (focus->doEvent(evt)) | 172 if (focus->doEvent(evt)) |
173 return true; | 173 return true; |
174 } | 174 } |
175 | 175 |
176 if (key == kUp_SkKey || key == kDown_SkKey) { | 176 if (key == kUp_SkKey || key == kDown_SkKey) { |
177 if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_Focu
sDirection) == NULL) | 177 if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_Focu
sDirection) == nullptr) |
178 this->onSetFocusView(NULL); | 178 this->onSetFocusView(nullptr); |
179 return true; | 179 return true; |
180 } | 180 } |
181 return false; | 181 return false; |
182 } | 182 } |
183 | 183 |
184 bool SkWindow::handleKeyUp(SkKey key) { | 184 bool SkWindow::handleKeyUp(SkKey key) { |
185 if (key == kNONE_SkKey) | 185 if (key == kNONE_SkKey) |
186 return false; | 186 return false; |
187 | 187 |
188 if (this->onHandleKeyUp(key)) | 188 if (this->onHandleKeyUp(key)) |
189 return true; | 189 return true; |
190 | 190 |
191 //send an event to the focus-view | 191 //send an event to the focus-view |
192 { | 192 { |
193 SkView* focus = this->getFocusView(); | 193 SkView* focus = this->getFocusView(); |
194 if (focus == NULL) | 194 if (focus == nullptr) |
195 focus = this; | 195 focus = this; |
196 | 196 |
197 //should this one be the same? | 197 //should this one be the same? |
198 SkEvent evt(SK_EventType_KeyUp); | 198 SkEvent evt(SK_EventType_KeyUp); |
199 evt.setFast32(key); | 199 evt.setFast32(key); |
200 if (focus->doEvent(evt)) | 200 if (focus->doEvent(evt)) |
201 return true; | 201 return true; |
202 } | 202 } |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 void SkWindow::addMenu(SkOSMenu* menu) { | 206 void SkWindow::addMenu(SkOSMenu* menu) { |
207 *fMenus.append() = menu; | 207 *fMenus.append() = menu; |
208 this->onAddMenu(menu); | 208 this->onAddMenu(menu); |
209 } | 209 } |
210 | 210 |
211 void SkWindow::setTitle(const char title[]) { | 211 void SkWindow::setTitle(const char title[]) { |
212 if (NULL == title) { | 212 if (nullptr == title) { |
213 title = ""; | 213 title = ""; |
214 } | 214 } |
215 fTitle.set(title); | 215 fTitle.set(title); |
216 this->onSetTitle(title); | 216 this->onSetTitle(title); |
217 } | 217 } |
218 | 218 |
219 bool SkWindow::onEvent(const SkEvent& evt) { | 219 bool SkWindow::onEvent(const SkEvent& evt) { |
220 if (evt.isType(SK_EventDelayInval)) { | 220 if (evt.isType(SK_EventDelayInval)) { |
221 for (SkRegion::Iterator iter(fDirtyRgn); !iter.done(); iter.next()) | 221 for (SkRegion::Iterator iter(fDirtyRgn); !iter.done(); iter.next()) |
222 this->onHandleInval(iter.rect()); | 222 this->onHandleInval(iter.rect()); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; | 329 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
330 desc.fSampleCnt = attachmentInfo.fSampleCount; | 330 desc.fSampleCnt = attachmentInfo.fSampleCount; |
331 desc.fStencilBits = attachmentInfo.fStencilBits; | 331 desc.fStencilBits = attachmentInfo.fStencilBits; |
332 GrGLint buffer; | 332 GrGLint buffer; |
333 GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); | 333 GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); |
334 desc.fRenderTargetHandle = buffer; | 334 desc.fRenderTargetHandle = buffer; |
335 return grContext->textureProvider()->wrapBackendRenderTarget(desc); | 335 return grContext->textureProvider()->wrapBackendRenderTarget(desc); |
336 } | 336 } |
337 | 337 |
338 #endif | 338 #endif |
OLD | NEW |