diff options
author | Brian Osman <brianosman@google.com> | 2017-12-01 10:52:28 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-01 17:12:49 +0000 |
commit | 8ceee43de49b314fff58852c2d89ed3885ae71ee (patch) | |
tree | c3046b938bd7c026c84f164b785f749472629f80 | |
parent | 3ac99cfaa2d434c71d9c82fc234fadd55fe96394 (diff) |
Remove more views code, just to simplify things
Bug: skia:
Change-Id: Ie31a3c764e4f88f2b08f4198bd253841a2d8c264
Reviewed-on: https://skia-review.googlesource.com/79100
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
-rw-r--r-- | include/views/SkEvent.h | 28 | ||||
-rw-r--r-- | include/views/SkView.h | 12 | ||||
-rw-r--r-- | samplecode/SampleAAGeometry.cpp | 1 | ||||
-rw-r--r-- | samplecode/SampleArc.cpp | 17 | ||||
-rw-r--r-- | samplecode/SampleCamera.cpp | 3 | ||||
-rw-r--r-- | samplecode/SampleCode.cpp | 5 | ||||
-rw-r--r-- | samplecode/SampleFilter2.cpp | 7 | ||||
-rw-r--r-- | samplecode/SampleMegaStroke.cpp | 4 | ||||
-rw-r--r-- | samplecode/SamplePolyToPoly.cpp | 1 | ||||
-rw-r--r-- | samplecode/SampleXfer.cpp | 1 | ||||
-rw-r--r-- | src/views/SkEvent.cpp | 85 | ||||
-rw-r--r-- | src/views/SkView.cpp | 8 |
12 files changed, 39 insertions, 133 deletions
diff --git a/include/views/SkEvent.h b/include/views/SkEvent.h index aad3f58f3a..a2ccb0c748 100644 --- a/include/views/SkEvent.h +++ b/include/views/SkEvent.h @@ -9,7 +9,6 @@ #define SkEvent_DEFINED #include "SkMetaData.h" -#include "SkString.h" /** Unique 32bit id used to identify an instance of SkEventSink. When events are posted, they are posted to a specific sinkID. When it is time to dispatch the @@ -27,35 +26,18 @@ typedef uint32_t SkEventSinkID; */ class SkEvent { public: - /** - * Function pointer that takes an event, returns true if it "handled" it. - */ - typedef bool (*Proc)(const SkEvent& evt); - SkEvent(); - explicit SkEvent(const SkString& type); explicit SkEvent(const char type[]); SkEvent(const SkEvent& src); ~SkEvent(); - /** Copy the event's type into the specified SkString parameter */ - void getType(SkString* str) const; - - /** Returns true if the event's type matches exactly the specified type (case sensitive) */ - bool isType(const SkString& str) const; - /** Returns true if the event's type matches exactly the specified type (case sensitive) */ - bool isType(const char type[], size_t len = 0) const; + bool isType(const char type[]) const; /** * Set the event's type to the specified string. */ - void setType(const SkString&); - - /** - * Set the event's type to the specified string. - */ - void setType(const char type[], size_t len = 0); + void setType(const char type[]); /** * Return the event's unnamed 32bit field. Default value is 0 @@ -123,8 +105,6 @@ public: return fMeta.setScalars(name, count, values); } /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */ - void setString(const char name[], const SkString& value) { fMeta.setString(name, value.c_str()); } - /** Add/replace the named string field to the event. In XML use the subelement <data name=... string=... */ void setString(const char name[], const char value[]) { fMeta.setString(name, value); } /** Add/replace the named pointer field to the event. There is no XML equivalent for this call */ void setPtr(const char name[], void* value) { fMeta.setPtr(name, value); } @@ -142,10 +122,10 @@ public: private: SkMetaData fMeta; - mutable char* fType; // may be characters with low bit set to know that it is not a pointer + char* fType; uint32_t f32; - void initialize(const char* type, size_t typeLen); + void initialize(const char* type); }; #endif diff --git a/include/views/SkView.h b/include/views/SkView.h index 9a84af832d..785f0cddbd 100644 --- a/include/views/SkView.h +++ b/include/views/SkView.h @@ -26,20 +26,12 @@ class SkView : public SkEventSink { public: enum Flag_Shift { kVisible_Shift, - kEnabled_Shift, - kFocusable_Shift, - kFlexH_Shift, - kFlexV_Shift, kNoClip_Shift, kFlagShiftCount }; enum Flag_Mask { kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible - kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled - kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus - kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable - kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount) @@ -58,13 +50,9 @@ public: /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags */ int isVisible() const { return fFlags & kVisible_Mask; } - int isEnabled() const { return fFlags & kEnabled_Mask; } - int isFocusable() const { return fFlags & kFocusable_Mask; } int isClipToBounds() const { return !(fFlags & kNoClip_Mask); } /** Helper to set/clear the view's kVisible_Mask flag */ void setVisibleP(bool); - void setEnabledP(bool); - void setFocusableP(bool); void setClipToBounds(bool); /** Return the view's width */ diff --git a/samplecode/SampleAAGeometry.cpp b/samplecode/SampleAAGeometry.cpp index 3d5426e637..75657a1883 100644 --- a/samplecode/SampleAAGeometry.cpp +++ b/samplecode/SampleAAGeometry.cpp @@ -14,6 +14,7 @@ // #include "SkPathOpsSimplifyAA.h" // #include "SkPathStroker.h" #include "SkPointPriv.h" +#include "SkString.h" #include "SkView.h" #if 0 diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index 2073060645..b3b1cfefaf 100644 --- a/samplecode/SampleArc.cpp +++ b/samplecode/SampleArc.cpp @@ -7,22 +7,23 @@ #include "SampleCode.h" #include "SkAnimTimer.h" -#include "SkView.h" #include "SkCanvas.h" +#include "SkColorFilter.h" +#include "SkColorPriv.h" +#include "SkCornerPathEffect.h" #include "SkDrawable.h" #include "SkGradientShader.h" +#include "SkLayerRasterizer.h" #include "SkPath.h" +#include "SkPathMeasure.h" +#include "SkPictureRecorder.h" +#include "SkRandom.h" #include "SkRegion.h" #include "SkShader.h" +#include "SkString.h" #include "SkUtils.h" +#include "SkView.h" #include "Sk1DPathEffect.h" -#include "SkCornerPathEffect.h" -#include "SkPathMeasure.h" -#include "SkPictureRecorder.h" -#include "SkRandom.h" -#include "SkColorPriv.h" -#include "SkColorFilter.h" -#include "SkLayerRasterizer.h" #include "SkParsePath.h" static void testparse() { diff --git a/samplecode/SampleCamera.cpp b/samplecode/SampleCamera.cpp index 85b854eced..fdba40375a 100644 --- a/samplecode/SampleCamera.cpp +++ b/samplecode/SampleCamera.cpp @@ -14,10 +14,11 @@ #include "SkEmbossMaskFilter.h" #include "SkGradientShader.h" #include "SkPath.h" +#include "SkRandom.h" #include "SkRegion.h" #include "SkShader.h" +#include "SkString.h" #include "SkUtils.h" -#include "SkRandom.h" class CameraView : public SampleView { SkTArray<sk_sp<SkShader>> fShaders; diff --git a/samplecode/SampleCode.cpp b/samplecode/SampleCode.cpp index 252ca2a670..62021069ca 100644 --- a/samplecode/SampleCode.cpp +++ b/samplecode/SampleCode.cpp @@ -7,6 +7,7 @@ #include "SampleCode.h" #include "SkCanvas.h" +#include "SkString.h" #if SK_SUPPORT_GPU # include "GrContext.h" @@ -17,7 +18,7 @@ class GrContext; ////////////////////////////////////////////////////////////////////////////// bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) { - if (evt.isType(gCharEvtName, sizeof(gCharEvtName) - 1)) { + if (evt.isType(gCharEvtName)) { if (outUni) { *outUni = evt.getFast32(); } @@ -27,7 +28,7 @@ bool SampleCode::CharQ(const SkEvent& evt, SkUnichar* outUni) { } bool SampleCode::TitleQ(const SkEvent& evt) { - return evt.isType(gTitleEvtName, sizeof(gTitleEvtName) - 1); + return evt.isType(gTitleEvtName); } void SampleCode::TitleR(SkEvent* evt, const char title[]) { diff --git a/samplecode/SampleFilter2.cpp b/samplecode/SampleFilter2.cpp index e6134bdb22..72beb06f4b 100644 --- a/samplecode/SampleFilter2.cpp +++ b/samplecode/SampleFilter2.cpp @@ -9,15 +9,16 @@ #include "SampleCode.h" #include "SkView.h" #include "SkCanvas.h" +#include "SkColorFilter.h" +#include "SkColorPriv.h" #include "SkGradientShader.h" #include "SkGraphics.h" #include "SkPath.h" #include "SkRegion.h" #include "SkShader.h" -#include "SkUtils.h" -#include "SkColorPriv.h" -#include "SkColorFilter.h" +#include "SkString.h" #include "SkTime.h" +#include "SkUtils.h" static const char* gNames[] = { "/skimages/background_01.png" diff --git a/samplecode/SampleMegaStroke.cpp b/samplecode/SampleMegaStroke.cpp index d85915600a..a7c2e544fc 100644 --- a/samplecode/SampleMegaStroke.cpp +++ b/samplecode/SampleMegaStroke.cpp @@ -37,9 +37,7 @@ protected: if (SampleCode::CharQ(*evt, &uni)) { fClip.set(0, 0, 950, 600); } - SkString str; - evt->getType(&str); - if (str == SkString("SampleCode_Key_Event")) { + if (evt->isType("SampleCode_Key_Event")) { fClip.set(0, 0, 950, 600); } return this->INHERITED::onQuery(evt); diff --git a/samplecode/SamplePolyToPoly.cpp b/samplecode/SamplePolyToPoly.cpp index 3cfba5ebdb..dd63a78536 100644 --- a/samplecode/SamplePolyToPoly.cpp +++ b/samplecode/SamplePolyToPoly.cpp @@ -10,6 +10,7 @@ #include "SkGraphics.h" #include "SkPath.h" #include "SkRandom.h" +#include "SkString.h" #include "SkTime.h" class PolyToPolyView : public SampleView { diff --git a/samplecode/SampleXfer.cpp b/samplecode/SampleXfer.cpp index 074613c441..d459274dc9 100644 --- a/samplecode/SampleXfer.cpp +++ b/samplecode/SampleXfer.cpp @@ -14,6 +14,7 @@ #include "SkPath.h" #include "SkRandom.h" #include "SkRSXform.h" +#include "SkString.h" #include "SkSurface.h" #include "SkGradientShader.h" diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp index c2b800fe9e..6ead33ec7f 100644 --- a/src/views/SkEvent.cpp +++ b/src/views/SkEvent.cpp @@ -7,103 +7,44 @@ #include "SkEvent.h" -void SkEvent::initialize(const char* type, size_t typeLen) { +void SkEvent::initialize(const char* type) { fType = nullptr; - setType(type, typeLen); + setType(type); f32 = 0; } SkEvent::SkEvent() { - initialize("", 0); + initialize(""); } SkEvent::SkEvent(const SkEvent& src) { *this = src; - if (((size_t) fType & 1) == 0) - setType(src.fType); -} - -SkEvent::SkEvent(const SkString& type) -{ - initialize(type.c_str(), type.size()); + setType(src.fType); } SkEvent::SkEvent(const char type[]) { SkASSERT(type); - initialize(type, strlen(type)); + initialize(type); } SkEvent::~SkEvent() { - if (((size_t) fType & 1) == 0) - sk_free((void*) fType); -} - -static size_t makeCharArray(char* buffer, size_t compact) -{ - size_t bits = (size_t) compact >> 1; - memcpy(buffer, &bits, sizeof(compact)); - buffer[sizeof(compact)] = 0; - return strlen(buffer); + sk_free(fType); } -void SkEvent::getType(SkString* str) const +bool SkEvent::isType(const char type[]) const { - if (str) - { - if ((size_t) fType & 1) // not a pointer - { - char chars[sizeof(size_t) + 1]; - size_t len = makeCharArray(chars, (size_t) fType); - str->set(chars, len); - } - else - str->set(fType); - } -} - -bool SkEvent::isType(const SkString& str) const -{ - return this->isType(str.c_str(), str.size()); -} - -bool SkEvent::isType(const char type[], size_t typeLen) const -{ - if (typeLen == 0) - typeLen = strlen(type); - if ((size_t) fType & 1) { // not a pointer - char chars[sizeof(size_t) + 1]; - size_t len = makeCharArray(chars, (size_t) fType); - return len == typeLen && strncmp(chars, type, typeLen) == 0; - } + size_t typeLen = strlen(type); return strncmp(fType, type, typeLen) == 0 && fType[typeLen] == 0; } -void SkEvent::setType(const char type[], size_t typeLen) -{ - if (typeLen == 0) - typeLen = strlen(type); - if (typeLen <= sizeof(fType)) { - size_t slot = 0; - memcpy(&slot, type, typeLen); - if (slot << 1 >> 1 != slot) - goto useCharStar; - slot <<= 1; - slot |= 1; - fType = (char*) slot; - } else { -useCharStar: - fType = (char*) sk_malloc_throw(typeLen + 1); - SkASSERT(((size_t) fType & 1) == 0); - memcpy(fType, type, typeLen); - fType[typeLen] = 0; - } -} - -void SkEvent::setType(const SkString& type) +void SkEvent::setType(const char type[]) { - setType(type.c_str()); + size_t typeLen = strlen(type); + fType = (char*) sk_malloc_throw(typeLen + 1); + memcpy(fType, type, typeLen); + fType[typeLen] = 0; } diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp index 4608c44406..6c9098848c 100644 --- a/src/views/SkView.cpp +++ b/src/views/SkView.cpp @@ -30,14 +30,6 @@ void SkView::setVisibleP(bool pred) { this->setFlags(SkSetClearShift(fFlags, pred, kVisible_Shift)); } -void SkView::setEnabledP(bool pred) { - this->setFlags(SkSetClearShift(fFlags, pred, kEnabled_Shift)); -} - -void SkView::setFocusableP(bool pred) { - this->setFlags(SkSetClearShift(fFlags, pred, kFocusable_Shift)); -} - void SkView::setClipToBounds(bool pred) { this->setFlags(SkSetClearShift(fFlags, !pred, kNoClip_Shift)); } |