1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 70397e9f3415b4646797f1b17e9a38b5deb864ff0reed 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkWindow.h" 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkCanvas.h" 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkOSMenu.h" 110397e9f3415b4646797f1b17e9a38b5deb864ff0reed#include "SkSurface.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkSystemEventTypes.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTime.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SK_EventDelayInval "\xd" "n" "\xa" "l" 168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 174302ae91b0c97993f7b659474a5fd305921cdc5ereedSkWindow::SkWindow() 184302ae91b0c97993f7b659474a5fd305921cdc5ereed : fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType) 1996fcdcc219d2a0d3579719b84b28bede76efba64halcanary , fFocusView(nullptr) 204302ae91b0c97993f7b659474a5fd305921cdc5ereed{ 21d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fClicks.reset(); 22d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fWaitingOnInval = false; 23f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix.reset(); 24a34be68a7eff0ae475b194f8a29975460cf3e456reed 25a34be68a7eff0ae475b194f8a29975460cf3e456reed fBitmap.allocN32Pixels(0, 0); 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 28658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgSkWindow::~SkWindow() { 29d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fClicks.deleteAll(); 30d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fMenus.deleteAll(); 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 330397e9f3415b4646797f1b17e9a38b5deb864ff0reedSkSurface* SkWindow::createSurface() { 340397e9f3415b4646797f1b17e9a38b5deb864ff0reed const SkBitmap& bm = this->getBitmap(); 354302ae91b0c97993f7b659474a5fd305921cdc5ereed return SkSurface::NewRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), &fSurfaceProps); 365957f47e8de0ff55b8c0bf84984d4915c7c72825reed@google.com} 375957f47e8de0ff55b8c0bf84984d4915c7c72825reed@google.com 38f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::setMatrix(const SkMatrix& matrix) { 39f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (fMatrix != matrix) { 40f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix = matrix; 4196fcdcc219d2a0d3579719b84b28bede76efba64halcanary this->inval(nullptr); 42f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 43f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 44f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 45f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::preConcat(const SkMatrix& matrix) { 46f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix m; 47f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com m.setConcat(fMatrix, matrix); 48f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->setMatrix(m); 49f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 50f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 51f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::postConcat(const SkMatrix& matrix) { 52f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix m; 53f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com m.setConcat(matrix, fMatrix); 54f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com this->setMatrix(m); 55f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 56f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 57a34be68a7eff0ae475b194f8a29975460cf3e456reedvoid SkWindow::resize(const SkImageInfo& info) { 58a34be68a7eff0ae475b194f8a29975460cf3e456reed if (fBitmap.info() != info) { 59a34be68a7eff0ae475b194f8a29975460cf3e456reed fBitmap.allocPixels(info); 6096fcdcc219d2a0d3579719b84b28bede76efba64halcanary this->inval(nullptr); 61d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 62a34be68a7eff0ae475b194f8a29975460cf3e456reed this->setSize(SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height())); 63a34be68a7eff0ae475b194f8a29975460cf3e456reed} 64a34be68a7eff0ae475b194f8a29975460cf3e456reed 65a34be68a7eff0ae475b194f8a29975460cf3e456reedvoid SkWindow::resize(int width, int height) { 66a34be68a7eff0ae475b194f8a29975460cf3e456reed this->resize(fBitmap.info().makeWH(width, height)); 67a34be68a7eff0ae475b194f8a29975460cf3e456reed} 68a34be68a7eff0ae475b194f8a29975460cf3e456reed 69a34be68a7eff0ae475b194f8a29975460cf3e456reedvoid SkWindow::setColorType(SkColorType ct, SkColorProfileType pt) { 70a34be68a7eff0ae475b194f8a29975460cf3e456reed const SkImageInfo& info = fBitmap.info(); 71a34be68a7eff0ae475b194f8a29975460cf3e456reed this->resize(SkImageInfo::Make(info.width(), info.height(), ct, kPremul_SkAlphaType, pt)); 728a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 738a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 74658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::handleInval(const SkRect* localR) { 75658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org SkIRect ir; 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 77f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (localR) { 78f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkRect devR; 79f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com SkMatrix inverse; 80f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com if (!fMatrix.invert(&inverse)) { 81f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com return false; 82f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 83f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com fMatrix.mapRect(&devR, *localR); 84f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com devR.round(&ir); 85f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } else { 86f9bb7a8e2052d21e6a7f48d5b73d2ef97637a09ereed@google.com ir.set(0, 0, 87e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com SkScalarRoundToInt(this->width()), 88e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com SkScalarRoundToInt(this->height())); 89f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com } 90d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fDirtyRgn.op(ir, SkRegion::kUnion_Op); 918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 92d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com this->onHandleInval(ir); 93d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 948a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 96f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.comvoid SkWindow::forceInvalAll() { 97261b8e2ca1cf22303ad95267f0bdc6e87e1bbe70reed@google.com fDirtyRgn.setRect(0, 0, 98e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com SkScalarCeilToInt(this->width()), 99e1ca705cac4b946993f6cbf798e2a0ba27e739f3reed@google.com SkScalarCeilToInt(this->height())); 100f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com} 101f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 1028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 1038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comextern bool gEnableControlledThrow; 1048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 106658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::update(SkIRect* updateArea) { 107658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org if (!fDirtyRgn.isEmpty()) { 1080397e9f3415b4646797f1b17e9a38b5deb864ff0reed SkAutoTUnref<SkSurface> surface(this->createSurface()); 1090397e9f3415b4646797f1b17e9a38b5deb864ff0reed SkCanvas* canvas = surface->getCanvas(); 110ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com 111ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com canvas->clipRegion(fDirtyRgn); 112030dc847dc497b011c417dc6694e8b6de290895fjoshualitt if (updateArea) { 113d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com *updateArea = fDirtyRgn.getBounds(); 114030dc847dc497b011c417dc6694e8b6de290895fjoshualitt } 1158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 116ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com SkAutoCanvasRestore acr(canvas, true); 117ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com canvas->concat(fMatrix); 118f2b98d67dcb6fcb3120feede9c72016fc7b3ead8reed@android.com 119d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com // empty this now, so we can correctly record any inval calls that 120d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com // might be made during the draw call. 121d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fDirtyRgn.setEmpty(); 1228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 1238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 124d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com gEnableControlledThrow = true; 1258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_BUILD_FOR_WIN32 127d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com //try { 128ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com this->draw(canvas); 129d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com //} 130d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com //catch (...) { 131d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com //} 1328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#else 133ce9dce0d8116cbbcbebdc1ad8329059c35baf4c0robertphillips@google.com this->draw(canvas); 1348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifdef SK_SIMULATE_FAILED_MALLOC 136d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com gEnableControlledThrow = false; 1378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 1388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 139d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 140d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 141d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return false; 1428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 144658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::handleChar(SkUnichar uni) { 145d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (this->onHandleChar(uni)) 146d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 1478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 148d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkView* focus = this->getFocusView(); 14996fcdcc219d2a0d3579719b84b28bede76efba64halcanary if (focus == nullptr) 150d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com focus = this; 1518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 152d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkEvent evt(SK_EventType_Unichar); 153d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com evt.setFast32(uni); 154d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return focus->doEvent(evt); 1558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 157658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::handleKey(SkKey key) { 158d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (key == kNONE_SkKey) 159d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return false; 160d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 161d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (this->onHandleKey(key)) 162d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 163d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 164d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com // send an event to the focus-view 165d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com { 166d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkView* focus = this->getFocusView(); 16796fcdcc219d2a0d3579719b84b28bede76efba64halcanary if (focus == nullptr) 168d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com focus = this; 169d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 170d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com SkEvent evt(SK_EventType_Key); 171d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com evt.setFast32(key); 172d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (focus->doEvent(evt)) 173d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 174d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 175d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 176658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org if (key == kUp_SkKey || key == kDown_SkKey) { 17796fcdcc219d2a0d3579719b84b28bede76efba64halcanary if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_FocusDirection) == nullptr) 17896fcdcc219d2a0d3579719b84b28bede76efba64halcanary this->onSetFocusView(nullptr); 179d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 180d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 181d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return false; 1828a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 1838a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 184658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::handleKeyUp(SkKey key) { 1858a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (key == kNONE_SkKey) 1868a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 187d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 1888a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (this->onHandleKeyUp(key)) 1898a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 190d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 1918a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //send an event to the focus-view 1928a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com { 1938a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkView* focus = this->getFocusView(); 19496fcdcc219d2a0d3579719b84b28bede76efba64halcanary if (focus == nullptr) 1958a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com focus = this; 196d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com 1978a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com //should this one be the same? 1988a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkEvent evt(SK_EventType_KeyUp); 1998a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com evt.setFast32(key); 2008a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com if (focus->doEvent(evt)) 2018a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return true; 2028a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 2038a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2048a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2058a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 206654d72f94c855ceae34db0ee82d92844835c0d29yangsu@google.comvoid SkWindow::addMenu(SkOSMenu* menu) { 207d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com *fMenus.append() = menu; 208d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com this->onAddMenu(menu); 2098a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2110ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.comvoid SkWindow::setTitle(const char title[]) { 21296fcdcc219d2a0d3579719b84b28bede76efba64halcanary if (nullptr == title) { 2138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com title = ""; 2140ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.com } 2150ae6b245f2b79bc04f0801b08fcf05abcf98fd6creed@android.com fTitle.set(title); 2168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com this->onSetTitle(title); 2178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 219658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onEvent(const SkEvent& evt) { 220658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org if (evt.isType(SK_EventDelayInval)) { 221658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org for (SkRegion::Iterator iter(fDirtyRgn); !iter.done(); iter.next()) 222d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com this->onHandleInval(iter.rect()); 223d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fWaitingOnInval = false; 224d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 225d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 226d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return this->INHERITED::onEvent(evt); 2278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2288a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 229658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onGetFocusView(SkView** focus) const { 230d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (focus) 231d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com *focus = fFocusView; 232d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 2338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 235658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onSetFocusView(SkView* focus) { 236658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.org if (fFocusView != focus) { 237d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (fFocusView) 238d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fFocusView->onFocusChange(false); 239d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com fFocusView = focus; 240d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com if (focus) 241d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com focus->onFocusChange(true); 242d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 243d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return true; 2448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 246658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgvoid SkWindow::onHandleInval(const SkIRect&) { 2478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 249658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onHandleChar(SkUnichar) { 250d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return false; 2518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 253658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onHandleKey(SkKey) { 254d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return false; 2558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 257658650c5b42653f5f7d9857252b764333331be58tfarina@chromium.orgbool SkWindow::onHandleKeyUp(SkKey) { 2588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return false; 2598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 2608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 2614d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.combool SkWindow::handleClick(int x, int y, Click::State state, void *owner, 2624d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com unsigned modifierKeys) { 2634d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com return this->onDispatchClick(x, y, state, owner, modifierKeys); 264dd0cd34067d103ace7c6739405cb7885d8ad3fb2mike@reedtribe.org} 265dd0cd34067d103ace7c6739405cb7885d8ad3fb2mike@reedtribe.org 266d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggobool SkWindow::onDispatchClick(int x, int y, Click::State state, 2674d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com void* owner, unsigned modifierKeys) { 268d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com bool handled = false; 2698a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 270d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo // First, attempt to find an existing click with this owner. 271d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo int index = -1; 272d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo for (int i = 0; i < fClicks.count(); i++) { 273d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo if (owner == fClicks[i]->fOwner) { 274d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo index = i; 275d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo break; 276d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 277d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 278d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo 279d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com switch (state) { 280d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo case Click::kDown_State: { 281d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo if (index != -1) { 282d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo delete fClicks[index]; 283d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fClicks.remove(index); 284d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 285d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo Click* click = this->findClickHandler(SkIntToScalar(x), 2864d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com SkIntToScalar(y), modifierKeys); 287d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo 288d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo if (click) { 289d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo click->fOwner = owner; 290d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo *fClicks.append() = click; 2914d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com SkView::DoClickDown(click, x, y, modifierKeys); 292d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo handled = true; 293d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 294d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo break; 295d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 296d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo case Click::kMoved_State: 297d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo if (index != -1) { 2984d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com SkView::DoClickMoved(fClicks[index], x, y, modifierKeys); 299d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo handled = true; 300d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 301d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo break; 302d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo case Click::kUp_State: 303d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo if (index != -1) { 3044d5c26de0a24f86c37c1da8b0e30d11a550ea67breed@google.com SkView::DoClickUp(fClicks[index], x, y, modifierKeys); 305d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo delete fClicks[index]; 306d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo fClicks.remove(index); 307d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo handled = true; 308d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo } 309d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo break; 310d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo default: 311d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo // Do nothing 312d3aed39ab1ad88b05b9423ee1329c227d1f8f612Scroggo break; 313d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com } 314d6176b0dcacb124539e0cfd051e6d93a9782f020rmistry@google.com return handled; 3158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com} 316c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark 317c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark#if SK_SUPPORT_GPU 318c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark 3198b3eca95ae90c15bc5520d7ee67f555358cadf77Brian Salomon#include "GrContext.h" 320c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark#include "gl/GrGLInterface.h" 321c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark#include "gl/GrGLUtil.h" 322c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark#include "SkGr.h" 323c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark 324c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclarkGrRenderTarget* SkWindow::renderTarget(const AttachmentInfo& attachmentInfo, 325c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark const GrGLInterface* interface, GrContext* grContext) { 326c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark GrBackendRenderTargetDesc desc; 327c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fWidth = SkScalarRoundToInt(this->width()); 328c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fHeight = SkScalarRoundToInt(this->height()); 329c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fConfig = kSkia8888_GrPixelConfig; 330c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 331c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fSampleCnt = attachmentInfo.fSampleCount; 332c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fStencilBits = attachmentInfo.fStencilBits; 333c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark GrGLint buffer; 334c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); 335c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark desc.fRenderTargetHandle = buffer; 336d309e7aa0efa2d5dd7e7b1af97026fcd3a047e98bsalomon return grContext->textureProvider()->wrapBackendRenderTarget(desc); 337c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark} 338c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark 339c8fcafb3f0d152fb92465451bdb2e4bd3ef37222caryclark#endif 340