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>
This commit is contained in:
Brian Osman 2017-12-01 10:52:28 -05:00 committed by Skia Commit-Bot
parent 3ac99cfaa2
commit 8ceee43de4
12 changed files with 40 additions and 134 deletions

View File

@ -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

View File

@ -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 */

View File

@ -14,6 +14,7 @@
// #include "SkPathOpsSimplifyAA.h"
// #include "SkPathStroker.h"
#include "SkPointPriv.h"
#include "SkString.h"
#include "SkView.h"
#if 0

View File

@ -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 "SkRegion.h"
#include "SkShader.h"
#include "SkUtils.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 "SkRegion.h"
#include "SkShader.h"
#include "SkString.h"
#include "SkUtils.h"
#include "SkView.h"
#include "Sk1DPathEffect.h"
#include "SkParsePath.h"
static void testparse() {

View File

@ -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;

View File

@ -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[]) {

View File

@ -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"

View File

@ -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);

View File

@ -10,6 +10,7 @@
#include "SkGraphics.h"
#include "SkPath.h"
#include "SkRandom.h"
#include "SkString.h"
#include "SkTime.h"
class PolyToPolyView : public SampleView {

View File

@ -14,6 +14,7 @@
#include "SkPath.h"
#include "SkRandom.h"
#include "SkRSXform.h"
#include "SkString.h"
#include "SkSurface.h"
#include "SkGradientShader.h"

View File

@ -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());
}
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);
sk_free(fType);
}
static size_t makeCharArray(char* buffer, size_t compact)
bool SkEvent::isType(const char type[]) const
{
size_t bits = (size_t) compact >> 1;
memcpy(buffer, &bits, sizeof(compact));
buffer[sizeof(compact)] = 0;
return strlen(buffer);
}
void SkEvent::getType(SkString* str) 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)
void SkEvent::setType(const char type[])
{
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:
size_t typeLen = strlen(type);
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)
{
setType(type.c_str());
}

View File

@ -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));
}