From f2b98d67dcb6fcb3120feede9c72016fc7b3ead8 Mon Sep 17 00:00:00 2001 From: "reed@android.com" Date: Mon, 20 Dec 2010 18:26:13 +0000 Subject: merge with changes for GPU backend git-svn-id: http://skia.googlecode.com/svn/trunk@637 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/views/SkEvent.cpp | 15 +++++++++ src/views/SkMetaData.cpp | 23 ++++++++++++++ src/views/SkTextBox.cpp | 2 +- src/views/SkView.cpp | 67 +++++++++++++++++++++----------------- src/views/SkWindow.cpp | 83 ++++++++++++++++++++++++++++++++++++------------ 5 files changed, 138 insertions(+), 52 deletions(-) (limited to 'src/views') diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp index 67549b48b5..ec4a7b47b7 100644 --- a/src/views/SkEvent.cpp +++ b/src/views/SkEvent.cpp @@ -536,6 +536,21 @@ void SkEvent::ServiceQueueTimer() SkEvent::SignalQueueTimer(time); } +int SkEvent::CountEventsOnQueue() { + SkEvent_Globals& globals = *(SkEvent_Globals*)SkGlobals::Find(SK_Event_GlobalsTag, create_globals); + globals.fEventMutex.acquire(); + + int count = 0; + const SkEvent* evt = globals.fEventQHead; + while (evt) { + count += 1; + evt = evt->fNextEvent; + } + globals.fEventMutex.release(); + + return count; +} + //////////////////////////////////////////////////////////////// void SkEvent::Init() diff --git a/src/views/SkMetaData.cpp b/src/views/SkMetaData.cpp index c366bd3fee..c871efb136 100644 --- a/src/views/SkMetaData.cpp +++ b/src/views/SkMetaData.cpp @@ -89,6 +89,10 @@ void SkMetaData::setBool(const char name[], bool value) (void)this->set(name, &value, sizeof(bool), kBool_Type, 1); } +void SkMetaData::setData(const char name[], const void* data, size_t byteCount) { + (void)this->set(name, data, sizeof(char), kData_Type, byteCount); +} + void* SkMetaData::set(const char name[], const void* data, size_t dataSize, Type type, int count) { SkASSERT(name); @@ -129,6 +133,9 @@ void* SkMetaData::set(const char name[], const void* data, size_t dataSize, Type case kBool_Type: rec->fData.fBool = *(const bool*)rec->data(); break; + case kData_Type: + rec->fData.fPtr = rec->data(); + break; default: SkASSERT(!"bad type"); break; @@ -213,6 +220,18 @@ bool SkMetaData::findBool(const char name[], bool* value) const return false; } +const void* SkMetaData::findData(const char name[], size_t* length) const { + const Rec* rec = this->find(name, kData_Type); + if (rec) { + SkASSERT(rec->fDataLen == sizeof(char)); + if (length) { + *length = rec->fDataCount; + } + return rec->data(); + } + return NULL; +} + const SkMetaData::Rec* SkMetaData::find(const char name[], Type type) const { const Rec* rec = fRec; @@ -272,6 +291,10 @@ bool SkMetaData::removeBool(const char name[]) return this->remove(name, kBool_Type); } +bool SkMetaData::removeData(const char name[]) { + return this->remove(name, kData_Type); +} + /////////////////////////////////////////////////////////////////////////////////// SkMetaData::Iter::Iter(const SkMetaData& metadata) diff --git a/src/views/SkTextBox.cpp b/src/views/SkTextBox.cpp index df7de986fa..0e31ac68e4 100644 --- a/src/views/SkTextBox.cpp +++ b/src/views/SkTextBox.cpp @@ -16,7 +16,7 @@ */ #include "SkTextBox.h" -#include "../src/core/SkGlyphCache.h" +#include "../core/SkGlyphCache.h" #include "SkUtils.h" #include "SkAutoKern.h" diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp index 652eb85025..7969d3d23c 100644 --- a/src/views/SkView.cpp +++ b/src/views/SkView.cpp @@ -49,6 +49,10 @@ void SkView::setFocusableP(bool pred) this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); } +void SkView::setClipToBounds(bool pred) { + this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); +} + void SkView::setSize(SkScalar width, SkScalar height) { width = SkMaxScalar(0, width); @@ -87,12 +91,16 @@ void SkView::draw(SkCanvas* canvas) { SkRect r; r.set(fLoc.fX, fLoc.fY, fLoc.fX + fWidth, fLoc.fY + fHeight); - if (canvas->quickReject(r, SkCanvas::kBW_EdgeType)) - return; + if (this->isClipToBounds() && + canvas->quickReject(r, SkCanvas::kBW_EdgeType)) { + return; + } SkAutoCanvasRestore as(canvas, true); - canvas->clipRect(r); + if (this->isClipToBounds()) { + canvas->clipRect(r); + } canvas->translate(fLoc.fX, fLoc.fY); if (fParent) { @@ -119,37 +127,36 @@ void SkView::draw(SkCanvas* canvas) } } -void SkView::inval(SkRect* rect) -{ - if (!this->isVisible()) - return; - - SkRect bounds; - - this->getLocalBounds(&bounds); - if (rect && !bounds.intersect(*rect)) - return; - - rect = &bounds; +void SkView::inval(SkRect* rect) { SkView* view = this; + SkRect storage; - for (;;) - { - if (view->handleInval(bounds)) - break; + for (;;) { + if (!view->isVisible()) { + return; + } + if (view->isClipToBounds()) { + SkRect bounds; + view->getLocalBounds(&bounds); + if (rect && !bounds.intersect(*rect)) { + return; + } + storage = bounds; + rect = &storage; + } + if (view->handleInval(rect)) { + return; + } - SkRect parentR; SkView* parent = view->fParent; + if (parent == NULL) { + return; + } - if (parent == NULL || !parent->isVisible()) - break; - - bounds.offset(view->fLoc.fX, view->fLoc.fY); - parent->getLocalBounds(&parentR); - if (!bounds.intersect(parentR)) - return; - - view = parent; + if (rect) { + rect->offset(view->fLoc.fX, view->fLoc.fY); + } + view = parent; } } @@ -456,7 +463,7 @@ bool SkView::onClick(Click*) { return false; } -bool SkView::handleInval(const SkRect& r) { +bool SkView::handleInval(const SkRect*) { return false; } diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp index b63b81a1c0..dbc1eea242 100644 --- a/src/views/SkWindow.cpp +++ b/src/views/SkWindow.cpp @@ -1,5 +1,6 @@ #include "SkWindow.h" #include "SkCanvas.h" +#include "SkDevice.h" #include "SkOSMenu.h" #include "SkSystemEventTypes.h" #include "SkTime.h" @@ -48,6 +49,8 @@ SkWindow::SkWindow() : fFocusView(NULL) #else fConfig = SkBitmap::kARGB_8888_Config; #endif + + fMatrix.reset(); } SkWindow::~SkWindow() @@ -57,6 +60,25 @@ SkWindow::~SkWindow() fMenus.deleteAll(); } +void SkWindow::setMatrix(const SkMatrix& matrix) { + if (fMatrix != matrix) { + fMatrix = matrix; + this->inval(NULL); + } +} + +void SkWindow::preConcat(const SkMatrix& matrix) { + SkMatrix m; + m.setConcat(fMatrix, matrix); + this->setMatrix(m); +} + +void SkWindow::postConcat(const SkMatrix& matrix) { + SkMatrix m; + m.setConcat(matrix, fMatrix); + this->setMatrix(m); +} + void SkWindow::setConfig(SkBitmap::Config config) { this->resize(fBitmap.width(), fBitmap.height(), config); @@ -72,6 +94,7 @@ void SkWindow::resize(int width, int height, SkBitmap::Config config) fConfig = config; fBitmap.setConfig(config, width, height); fBitmap.allocPixels(); + fBitmap.setIsOpaque(true); this->setSize(SkIntToScalar(width), SkIntToScalar(height)); this->inval(NULL); @@ -88,25 +111,31 @@ void SkWindow::eraseRGB(U8CPU r, U8CPU g, U8CPU b) fBitmap.eraseRGB(r, g, b); } -bool SkWindow::handleInval(const SkRect& r) +bool SkWindow::handleInval(const SkRect* localR) { SkIRect ir; - r.round(&ir); + if (localR) { + SkRect devR; + SkMatrix inverse; + if (!fMatrix.invert(&inverse)) { + return false; + } + fMatrix.mapRect(&devR, *localR); + devR.round(&ir); + } else { + ir.set(0, 0, this->width(), this->height()); + } fDirtyRgn.op(ir, SkRegion::kUnion_Op); -#ifdef SK_BUILD_FOR_WIN32xxxx - if (!fWaitingOnInval) - { - fWaitingOnInval = true; - (new SkEvent(SK_EventDelayInval))->post(this->getSinkID(), 10); - } -#else this->onHandleInval(ir); -#endif return true; } +void SkWindow::forceInvalAll() { + fDirtyRgn.setRect(0, 0, this->width(), this->height()); +} + #if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) #include #include @@ -117,7 +146,7 @@ bool SkWindow::handleInval(const SkRect& r) extern bool gEnableControlledThrow; #endif -bool SkWindow::update(SkIRect* updateArea) +bool SkWindow::update(SkIRect* updateArea, SkCanvas* canvas) { if (!fDirtyRgn.isEmpty()) { @@ -134,37 +163,49 @@ bool SkWindow::update(SkIRect* updateArea) bm.setPixels(buffer); #endif - SkCanvas canvas(bm); + SkCanvas rasterCanvas; + SkDevice* device; - canvas.clipRegion(fDirtyRgn); + if (NULL == canvas) { + canvas = &rasterCanvas; + device = new SkDevice(canvas, bm, false); + canvas->setDevice(device)->unref(); + } else { + canvas->setBitmapDevice(bm); + } + + canvas->clipRegion(fDirtyRgn); if (updateArea) *updateArea = fDirtyRgn.getBounds(); + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(fMatrix); + // empty this now, so we can correctly record any inval calls that // might be made during the draw call. fDirtyRgn.setEmpty(); #ifdef TEST_BOUNDER test_bounder b(bm); - canvas.setBounder(&b); + canvas->setBounder(&b); #endif #ifdef SK_SIMULATE_FAILED_MALLOC gEnableControlledThrow = true; #endif #ifdef SK_BUILD_FOR_WIN32 - try { - this->draw(&canvas); - } - catch (...) { - } + //try { + this->draw(canvas); + //} + //catch (...) { + //} #else - this->draw(&canvas); + this->draw(canvas); #endif #ifdef SK_SIMULATE_FAILED_MALLOC gEnableControlledThrow = false; #endif #ifdef TEST_BOUNDER - canvas.setBounder(NULL); + canvas->setBounder(NULL); #endif #if defined(SK_BUILD_FOR_WINCE) && defined(USE_GX_SCREEN) -- cgit v1.2.3