aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/views
diff options
context:
space:
mode:
authorGravatar Brian Osman <brianosman@google.com>2017-11-22 13:23:35 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-22 18:59:44 +0000
commit4f99e58252175f01c0b9ca1a5e2fc7acec6acec3 (patch)
tree64458810ed2962bbdcb470a4f199feade2be2b03 /src/views
parentd923a71a113d97dc87b4424c25d5b5019331db24 (diff)
Remove a huge pile of views code
All of this is dead when not using the old SkWindow framework. TBR=reed@google.com Bug: skia: Change-Id: I0f6ab18987a98469bfd367d5bc10967300dfd3ca Reviewed-on: https://skia-review.googlesource.com/75384 Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/views')
-rw-r--r--src/views/SkEvent.cpp280
-rw-r--r--src/views/SkEventSink.cpp149
-rw-r--r--src/views/SkOSMenu.cpp263
-rw-r--r--src/views/SkTagList.cpp61
-rw-r--r--src/views/SkTagList.h42
-rw-r--r--src/views/SkView.cpp20
-rw-r--r--src/views/SkViewPriv.cpp104
-rw-r--r--src/views/SkViewPriv.h43
-rw-r--r--src/views/SkWindow.cpp367
-rwxr-xr-xsrc/views/ios/SkOSWindow_iOS.mm72
-rw-r--r--src/views/mac/SkEventNotifier.h13
-rw-r--r--src/views/mac/SkEventNotifier.mm68
-rw-r--r--src/views/mac/SkNSView.h51
-rw-r--r--src/views/mac/SkNSView.mm443
-rw-r--r--src/views/mac/SkOSWindow_Mac.mm107
-rw-r--r--src/views/mac/SkOptionsTableView.h39
-rw-r--r--src/views/mac/SkOptionsTableView.mm297
-rw-r--r--src/views/mac/SkTextFieldCell.h14
-rw-r--r--src/views/mac/SkTextFieldCell.m56
-rw-r--r--src/views/mac/skia_mac.mm126
-rw-r--r--src/views/unix/SkOSWindow_Unix.cpp529
-rw-r--r--src/views/unix/XkeysToSkKeys.h66
-rw-r--r--src/views/unix/skia_unix.cpp28
-rw-r--r--src/views/win/SkOSWindow_win.cpp726
-rw-r--r--src/views/win/skia_win.cpp135
25 files changed, 8 insertions, 4091 deletions
diff --git a/src/views/SkEvent.cpp b/src/views/SkEvent.cpp
index c218ee419d..8102455979 100644
--- a/src/views/SkEvent.cpp
+++ b/src/views/SkEvent.cpp
@@ -9,13 +9,10 @@
#include "SkDOM.h"
#include "SkEvent.h"
-void SkEvent::initialize(const char* type, size_t typeLen,
- SkEventSinkID targetID) {
+void SkEvent::initialize(const char* type, size_t typeLen) {
fType = nullptr;
setType(type, typeLen);
f32 = 0;
- fTargetID = targetID;
- fTargetProc = nullptr;
#ifdef SK_DEBUG
fTime = 0;
fNextEvent = nullptr;
@@ -24,7 +21,7 @@ void SkEvent::initialize(const char* type, size_t typeLen,
SkEvent::SkEvent()
{
- initialize("", 0, 0);
+ initialize("", 0);
}
SkEvent::SkEvent(const SkEvent& src)
@@ -34,15 +31,15 @@ SkEvent::SkEvent(const SkEvent& src)
setType(src.fType);
}
-SkEvent::SkEvent(const SkString& type, SkEventSinkID targetID)
+SkEvent::SkEvent(const SkString& type)
{
- initialize(type.c_str(), type.size(), targetID);
+ initialize(type.c_str(), type.size());
}
-SkEvent::SkEvent(const char type[], SkEventSinkID targetID)
+SkEvent::SkEvent(const char type[])
{
SkASSERT(type);
- initialize(type, strlen(type), targetID);
+ initialize(type, strlen(type));
}
SkEvent::~SkEvent()
@@ -245,268 +242,3 @@ void SkEvent::inflate(const SkDOM& dom, const SkDOM::Node* node)
SkDebugf("\n");
}
#endif
-
-///////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
-// #define SK_TRACE_EVENTSx
-#endif
-
-#ifdef SK_TRACE_EVENTS
- static void event_log(const char s[])
- {
- SkDEBUGF(("%s\n", s));
- }
-
- #define EVENT_LOG(s) event_log(s)
- #define EVENT_LOGN(s, n) do { SkString str(s); str.append(" "); str.appendS32(n); event_log(str.c_str()); } while (0)
-#else
- #define EVENT_LOG(s)
- #define EVENT_LOGN(s, n)
-#endif
-
-#include "SkMutex.h"
-#include "SkTime.h"
-
-class SkEvent_Globals {
-public:
- SkEvent_Globals() {
- fEventQHead = nullptr;
- fEventQTail = nullptr;
- fDelayQHead = nullptr;
- SkDEBUGCODE(fEventCounter = 0;)
- }
-
- SkMutex fEventMutex;
- SkEvent* fEventQHead, *fEventQTail;
- SkEvent* fDelayQHead;
- SkDEBUGCODE(int fEventCounter;)
-};
-
-static SkEvent_Globals& getGlobals() {
- // leak this, so we don't incure any shutdown perf hit
- static SkEvent_Globals* gGlobals = new SkEvent_Globals;
- return *gGlobals;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-void SkEvent::postDelay(SkMSec delay) {
- if (!fTargetID && !fTargetProc) {
- delete this;
- return;
- }
-
- if (delay) {
- this->postTime(GetMSecsSinceStartup() + delay);
- return;
- }
-
- SkEvent_Globals& globals = getGlobals();
-
- globals.fEventMutex.acquire();
- bool wasEmpty = SkEvent::Enqueue(this);
- globals.fEventMutex.release();
-
- // call outside of us holding the mutex
- if (wasEmpty) {
- SkEvent::SignalNonEmptyQueue();
- }
-}
-
-void SkEvent::postTime(SkMSec time) {
- if (!fTargetID && !fTargetProc) {
- delete this;
- return;
- }
-
- SkEvent_Globals& globals = getGlobals();
-
- globals.fEventMutex.acquire();
- SkMSec queueDelay = SkEvent::EnqueueTime(this, time);
- globals.fEventMutex.release();
-
- // call outside of us holding the mutex
- if ((int32_t)queueDelay != ~0) {
- SkEvent::SignalQueueTimer(queueDelay);
- }
-}
-
-bool SkEvent::Enqueue(SkEvent* evt) {
- SkEvent_Globals& globals = getGlobals();
- // gEventMutex acquired by caller
-
- SkASSERT(evt);
-
- bool wasEmpty = globals.fEventQHead == nullptr;
-
- if (globals.fEventQTail)
- globals.fEventQTail->fNextEvent = evt;
- globals.fEventQTail = evt;
- if (globals.fEventQHead == nullptr)
- globals.fEventQHead = evt;
- evt->fNextEvent = nullptr;
-
- SkDEBUGCODE(++globals.fEventCounter);
-
- return wasEmpty;
-}
-
-SkEvent* SkEvent::Dequeue() {
- SkEvent_Globals& globals = getGlobals();
- globals.fEventMutex.acquire();
-
- SkEvent* evt = globals.fEventQHead;
- if (evt) {
- SkDEBUGCODE(--globals.fEventCounter);
-
- globals.fEventQHead = evt->fNextEvent;
- if (globals.fEventQHead == nullptr) {
- globals.fEventQTail = nullptr;
- }
- }
- globals.fEventMutex.release();
-
- return evt;
-}
-
-bool SkEvent::QHasEvents() {
- SkEvent_Globals& globals = getGlobals();
-
- // this is not thread accurate, need a semaphore for that
- return globals.fEventQHead != nullptr;
-}
-
-#ifdef SK_TRACE_EVENTS
- static int gDelayDepth;
-#endif
-
-SkMSec SkEvent::EnqueueTime(SkEvent* evt, SkMSec time) {
- SkEvent_Globals& globals = getGlobals();
- // gEventMutex acquired by caller
-
- SkEvent* curr = globals.fDelayQHead;
- SkEvent* prev = nullptr;
-
- while (curr) {
- if (SkMSec_LT(time, curr->fTime)) {
- break;
- }
- prev = curr;
- curr = curr->fNextEvent;
- }
-
- evt->fTime = time;
- evt->fNextEvent = curr;
- if (prev == nullptr) {
- globals.fDelayQHead = evt;
- } else {
- prev->fNextEvent = evt;
- }
-
- SkMSec delay = globals.fDelayQHead->fTime - GetMSecsSinceStartup();
- if ((int32_t)delay <= 0) {
- delay = 1;
- }
- return delay;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-#include "SkEventSink.h"
-
-bool SkEvent::ProcessEvent() {
- std::unique_ptr<SkEvent> evt(SkEvent::Dequeue());
- bool again = false;
-
- EVENT_LOGN("ProcessEvent", (int32_t)evt);
-
- if (evt) {
- (void)SkEventSink::DoEvent(*evt);
- again = SkEvent::QHasEvents();
- }
- return again;
-}
-
-void SkEvent::ServiceQueueTimer()
-{
- SkEvent_Globals& globals = getGlobals();
-
- globals.fEventMutex.acquire();
-
- bool wasEmpty = false;
- SkMSec now = GetMSecsSinceStartup();
- SkEvent* evt = globals.fDelayQHead;
-
- while (evt)
- {
- if (SkMSec_LT(now, evt->fTime))
- break;
-
-#ifdef SK_TRACE_EVENTS
- --gDelayDepth;
- SkDebugf("dequeue-delay %s (%d)", evt->getType(), gDelayDepth);
- const char* idStr = evt->findString("id");
- if (idStr)
- SkDebugf(" (%s)", idStr);
- SkDebugf("\n");
-#endif
-
- SkEvent* next = evt->fNextEvent;
- if (SkEvent::Enqueue(evt))
- wasEmpty = true;
- evt = next;
- }
- globals.fDelayQHead = evt;
-
- SkMSec time = evt ? evt->fTime - now : 0;
-
- globals.fEventMutex.release();
-
- if (wasEmpty)
- SkEvent::SignalNonEmptyQueue();
-
- SkEvent::SignalQueueTimer(time);
-}
-
-int SkEvent::CountEventsOnQueue() {
- SkEvent_Globals& globals = getGlobals();
- globals.fEventMutex.acquire();
-
- int count = 0;
- const SkEvent* evt = globals.fEventQHead;
- while (evt) {
- count += 1;
- evt = evt->fNextEvent;
- }
- globals.fEventMutex.release();
-
- return count;
-}
-
-SkMSec SkEvent::GetMSecsSinceStartup() {
- static const double kEpoch = SkTime::GetMSecs();
- return static_cast<SkMSec>(SkTime::GetMSecs() - kEpoch);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-void SkEvent::Init() {}
-
-void SkEvent::Term() {
- SkEvent_Globals& globals = getGlobals();
-
- SkEvent* evt = globals.fEventQHead;
- while (evt) {
- SkEvent* next = evt->fNextEvent;
- delete evt;
- evt = next;
- }
-
- evt = globals.fDelayQHead;
- while (evt) {
- SkEvent* next = evt->fNextEvent;
- delete evt;
- evt = next;
- }
-}
diff --git a/src/views/SkEventSink.cpp b/src/views/SkEventSink.cpp
index cd83111f50..11af0f9623 100644
--- a/src/views/SkEventSink.cpp
+++ b/src/views/SkEventSink.cpp
@@ -8,7 +8,6 @@
#include "SkEventSink.h"
#include "SkMutex.h"
-#include "SkTagList.h"
#include "SkTime.h"
class SkEventSink_Globals {
@@ -29,7 +28,7 @@ static SkEventSink_Globals& getGlobals() {
return *gGlobals;
}
-SkEventSink::SkEventSink() : fTagHead(nullptr) {
+SkEventSink::SkEventSink() {
SkEventSink_Globals& globals = getGlobals();
globals.fSinkMutex.acquire();
@@ -44,9 +43,6 @@ SkEventSink::SkEventSink() : fTagHead(nullptr) {
SkEventSink::~SkEventSink() {
SkEventSink_Globals& globals = getGlobals();
- if (fTagHead)
- SkTagList::DeleteAll(fTagHead);
-
globals.fSinkMutex.acquire();
SkEventSink* sink = globals.fSinkHead;
@@ -87,149 +83,6 @@ bool SkEventSink::onQuery(SkEvent*) {
///////////////////////////////////////////////////////////////////////////////
-SkTagList* SkEventSink::findTagList(U8CPU tag) const {
- return fTagHead ? SkTagList::Find(fTagHead, tag) : nullptr;
-}
-
-void SkEventSink::addTagList(SkTagList* rec) {
- SkASSERT(rec);
- SkASSERT(fTagHead == nullptr || SkTagList::Find(fTagHead, rec->fTag) == nullptr);
-
- rec->fNext = fTagHead;
- fTagHead = rec;
-}
-
-void SkEventSink::removeTagList(U8CPU tag) {
- if (fTagHead) {
- SkTagList::DeleteTag(&fTagHead, tag);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-struct SkListenersTagList : SkTagList {
- SkListenersTagList(U16CPU count) : SkTagList(kListeners_SkTagList)
- {
- fExtra16 = SkToU16(count);
- fIDs = (SkEventSinkID*)sk_malloc_throw(count * sizeof(SkEventSinkID));
- }
- virtual ~SkListenersTagList()
- {
- sk_free(fIDs);
- }
-
- int countListners() const { return fExtra16; }
-
- int find(SkEventSinkID id) const
- {
- const SkEventSinkID* idptr = fIDs;
- for (int i = fExtra16 - 1; i >= 0; --i)
- if (idptr[i] == id)
- return i;
- return -1;
- }
-
- SkEventSinkID* fIDs;
-};
-
-void SkEventSink::addListenerID(SkEventSinkID id)
-{
- if (id == 0)
- return;
-
- SkListenersTagList* prev = (SkListenersTagList*)this->findTagList(kListeners_SkTagList);
- int count = 0;
-
- if (prev)
- {
- if (prev->find(id) >= 0)
- return;
- count = prev->countListners();
- }
-
- SkListenersTagList* next = new SkListenersTagList(count + 1);
-
- if (prev)
- {
- memcpy(next->fIDs, prev->fIDs, count * sizeof(SkEventSinkID));
- this->removeTagList(kListeners_SkTagList);
- }
- next->fIDs[count] = id;
- this->addTagList(next);
-}
-
-void SkEventSink::copyListeners(const SkEventSink& sink)
-{
- SkListenersTagList* sinkList = (SkListenersTagList*)sink.findTagList(kListeners_SkTagList);
- if (sinkList == nullptr)
- return;
- SkASSERT(sinkList->countListners() > 0);
- const SkEventSinkID* iter = sinkList->fIDs;
- const SkEventSinkID* stop = iter + sinkList->countListners();
- while (iter < stop)
- addListenerID(*iter++);
-}
-
-void SkEventSink::removeListenerID(SkEventSinkID id)
-{
- if (id == 0)
- return;
-
- SkListenersTagList* list = (SkListenersTagList*)this->findTagList(kListeners_SkTagList);
-
- if (list == nullptr)
- return;
-
- int index = list->find(id);
- if (index >= 0)
- {
- int count = list->countListners();
- SkASSERT(count > 0);
- if (count == 1)
- this->removeTagList(kListeners_SkTagList);
- else
- {
- // overwrite without resize/reallocating our struct (for speed)
- list->fIDs[index] = list->fIDs[count - 1];
- list->fExtra16 = SkToU16(count - 1);
- }
- }
-}
-
-bool SkEventSink::hasListeners() const
-{
- return this->findTagList(kListeners_SkTagList) != nullptr;
-}
-
-void SkEventSink::postToListeners(const SkEvent& evt, SkMSec delay) {
- SkListenersTagList* list = (SkListenersTagList*)this->findTagList(kListeners_SkTagList);
- if (list) {
- SkASSERT(list->countListners() > 0);
- const SkEventSinkID* iter = list->fIDs;
- const SkEventSinkID* stop = iter + list->countListners();
- while (iter < stop) {
- SkEvent* copy = new SkEvent(evt);
- copy->setTargetID(*iter++)->postDelay(delay);
- }
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-SkEventSink::EventResult SkEventSink::DoEvent(const SkEvent& evt) {
- SkEvent::Proc proc = evt.getTargetProc();
- if (proc) {
- return proc(evt) ? kHandled_EventResult : kNotHandled_EventResult;
- }
-
- SkEventSink* sink = SkEventSink::FindSink(evt.getTargetID());
- if (sink) {
- return sink->doEvent(evt) ? kHandled_EventResult : kNotHandled_EventResult;
- }
-
- return kSinkNotFound_EventResult;
-}
-
SkEventSink* SkEventSink::FindSink(SkEventSinkID sinkID)
{
if (sinkID == 0)
diff --git a/src/views/SkOSMenu.cpp b/src/views/SkOSMenu.cpp
deleted file mode 100644
index ec92a7b4a5..0000000000
--- a/src/views/SkOSMenu.cpp
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkAtomics.h"
-#include "SkOSMenu.h"
-#include <stdarg.h>
-
-static int gOSMenuCmd = 7000;
-
-SkOSMenu::SkOSMenu(const char title[]) {
- fTitle.set(title);
-}
-
-SkOSMenu::~SkOSMenu() {
- this->reset();
-}
-
-void SkOSMenu::reset() {
- fItems.deleteAll();
- fTitle.reset();
-}
-
-const SkOSMenu::Item* SkOSMenu::getItemByID(int itemID) const {
- for (int i = 0; i < fItems.count(); ++i) {
- if (itemID == fItems[i]->getID())
- return fItems[i];
- }
- return nullptr;
-}
-
-void SkOSMenu::getItems(const SkOSMenu::Item* items[]) const {
- if (items) {
- for (int i = 0; i < fItems.count(); ++i) {
- items[i] = fItems[i];
- }
- }
-}
-
-void SkOSMenu::assignKeyEquivalentToItem(int itemID, SkUnichar key) {
- for (int i = 0; i < fItems.count(); ++i) {
- if (itemID == fItems[i]->getID())
- fItems[i]->setKeyEquivalent(key);
- }
-}
-
-bool SkOSMenu::handleKeyEquivalent(SkUnichar key) {
- int value = 0, size = 0;
- bool state;
- SkOSMenu::TriState tristate;
- for (int i = 0; i < fItems.count(); ++i) {
- Item* item = fItems[i];
- if (item->getKeyEquivalent()== key) {
- SkString list;
- switch (item->getType()) {
- case kList_Type:
- SkOSMenu::FindListItemCount(*item->getEvent(), &size);
- SkOSMenu::FindListIndex(*item->getEvent(), item->getSlotName(), &value);
- value = (value + 1) % size;
- item->setInt(value);
- break;
- case kSwitch_Type:
- SkOSMenu::FindSwitchState(*item->getEvent(), item->getSlotName(), &state);
- item->setBool(!state);
- break;
- case kTriState_Type:
- SkOSMenu::FindTriState(*item->getEvent(), item->getSlotName(), &tristate);
- if (kOnState == tristate)
- tristate = kMixedState;
- else
- tristate = (SkOSMenu::TriState)((int)tristate + 1);
- item->setTriState(tristate);
- break;
- case kAction_Type:
- case kCustom_Type:
- case kSlider_Type:
- case kTextField_Type:
- default:
- break;
- }
- item->postEvent();
- return true;
- }
- }
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-SkOSMenu::Item::Item(const char label[], SkOSMenu::Type type,
- const char slotName[], SkEvent* evt) {
- fLabel.set(label);
- fSlotName.set(slotName);
- fType = type;
- fEvent = evt;
- fKey = 0;
- fID = sk_atomic_inc(&gOSMenuCmd);
-}
-
-void SkOSMenu::Item::setBool(bool value) const {
- SkASSERT(SkOSMenu::kSwitch_Type == fType);
- fEvent->setBool(fSlotName.c_str(), value);
-}
-
-void SkOSMenu::Item::setScalar(SkScalar value) const {
- SkASSERT(SkOSMenu::kSlider_Type == fType);
- fEvent->setScalar(fSlotName.c_str(), value);
-}
-
-void SkOSMenu::Item::setInt(int value) const {
- SkASSERT(SkOSMenu::kList_Type == fType);
- fEvent->setS32(fSlotName.c_str(), value);
-}
-
-void SkOSMenu::Item::setTriState(TriState value) const {
- SkASSERT(SkOSMenu::kTriState_Type == fType);
- fEvent->setS32(fSlotName.c_str(), value);
-}
-
-void SkOSMenu::Item::setString(const char value[]) const {
- SkASSERT(SkOSMenu::kTextField_Type == fType);
- fEvent->setString(fSlotName.c_str(), value);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-static const char* gMenuEventType = "SkOSMenuEventType";
-static const char* gSlider_Min_Scalar = "SkOSMenuSlider_Min";
-static const char* gSlider_Max_Scalar = "SkOSMenuSlider_Max";
-static const char* gDelimiter = "|";
-static const char* gList_Items_Str = "SkOSMenuList_Items";
-static const char* gList_ItemCount_S32 = "SkOSMenuList_ItemCount";
-
-int SkOSMenu::appendItem(const char label[], Type type, const char slotName[],
- SkEvent* evt) {
- SkOSMenu::Item* item = new Item(label, type, slotName, evt);
- fItems.append(1, &item);
- return item->getID();
-}
-
-int SkOSMenu::appendAction(const char label[], SkEventSinkID target) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- //Store label in event so it can be used to identify the action later
- evt->setString(label, label);
- return appendItem(label, SkOSMenu::kAction_Type, "", evt);
-}
-
-int SkOSMenu::appendList(const char label[], const char slotName[],
- SkEventSinkID target, int index, const char option[], ...) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- va_list args;
- if (option) {
- SkString str(option);
- va_start(args, option);
- int count = 1;
- for (const char* arg = va_arg(args, const char*); arg != nullptr; arg = va_arg(args, const char*)) {
- str += gDelimiter;
- str += arg;
- ++count;
- }
- va_end(args);
- evt->setString(gList_Items_Str, str);
- evt->setS32(gList_ItemCount_S32, count);
- evt->setS32(slotName, index);
- }
- return appendItem(label, SkOSMenu::kList_Type, slotName, evt);
-}
-
-int SkOSMenu::appendSlider(const char label[], const char slotName[],
- SkEventSinkID target, SkScalar min, SkScalar max,
- SkScalar defaultValue) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- evt->setScalar(gSlider_Min_Scalar, min);
- evt->setScalar(gSlider_Max_Scalar, max);
- evt->setScalar(slotName, defaultValue);
- return appendItem(label, SkOSMenu::kSlider_Type, slotName, evt);
-}
-
-int SkOSMenu::appendSwitch(const char label[], const char slotName[],
- SkEventSinkID target, bool defaultState) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- evt->setBool(slotName, defaultState);
- return appendItem(label, SkOSMenu::kSwitch_Type, slotName, evt);
-}
-
-int SkOSMenu::appendTriState(const char label[], const char slotName[],
- SkEventSinkID target, SkOSMenu::TriState defaultState) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- evt->setS32(slotName, defaultState);
- return appendItem(label, SkOSMenu::kTriState_Type, slotName, evt);
-}
-
-int SkOSMenu::appendTextField(const char label[], const char slotName[],
- SkEventSinkID target, const char placeholder[]) {
- SkEvent* evt = new SkEvent(gMenuEventType, target);
- evt->setString(slotName, placeholder);
- return appendItem(label, SkOSMenu::kTextField_Type, slotName, evt);
-}
-
-bool SkOSMenu::FindListItemCount(const SkEvent& evt, int* count) {
- return evt.isType(gMenuEventType) && evt.findS32(gList_ItemCount_S32, count);
-}
-
-bool SkOSMenu::FindListItems(const SkEvent& evt, SkString items[]) {
- if (evt.isType(gMenuEventType) && items) {
- const char* text = evt.findString(gList_Items_Str);
- if (text != nullptr) {
- SkString temp(text);
- char* token = strtok((char*)temp.c_str(), gDelimiter);
- int index = 0;
- while (token != nullptr) {
- items[index].set(token, strlen(token));
- token = strtok (nullptr, gDelimiter);
- ++index;
- }
- }
- return true;
- }
- return false;
-}
-
-bool SkOSMenu::FindSliderMin(const SkEvent& evt, SkScalar* min) {
- return evt.isType(gMenuEventType) && evt.findScalar(gSlider_Min_Scalar, min);
-}
-
-bool SkOSMenu::FindSliderMax(const SkEvent& evt, SkScalar* max) {
- return evt.isType(gMenuEventType) && evt.findScalar(gSlider_Max_Scalar, max);
-}
-
-bool SkOSMenu::FindAction(const SkEvent& evt, const char label[]) {
- return evt.isType(gMenuEventType) && evt.findString(label);
-}
-
-bool SkOSMenu::FindListIndex(const SkEvent& evt, const char slotName[], int* value) {
- return evt.isType(gMenuEventType) && evt.findS32(slotName, value);
-}
-
-bool SkOSMenu::FindSliderValue(const SkEvent& evt, const char slotName[], SkScalar* value) {
- return evt.isType(gMenuEventType) && evt.findScalar(slotName, value);
-}
-
-bool SkOSMenu::FindSwitchState(const SkEvent& evt, const char slotName[], bool* value) {
- return evt.isType(gMenuEventType) && evt.findBool(slotName, value);
-}
-
-bool SkOSMenu::FindTriState(const SkEvent& evt, const char slotName[], SkOSMenu::TriState* value) {
- return evt.isType(gMenuEventType) && evt.findS32(slotName, (int*)value);
-}
-
-bool SkOSMenu::FindText(const SkEvent& evt, const char slotName[], SkString* value) {
- if (evt.isType(gMenuEventType)) {
- const char* text = evt.findString(slotName);
- if (!text || !*text)
- return false;
- else {
- value->set(text);
- return true;
- }
- }
- return false;
-}
diff --git a/src/views/SkTagList.cpp b/src/views/SkTagList.cpp
deleted file mode 100644
index 27f3916ec6..0000000000
--- a/src/views/SkTagList.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#include "SkTagList.h"
-
-SkTagList::~SkTagList()
-{
-}
-
-SkTagList* SkTagList::Find(SkTagList* rec, U8CPU tag)
-{
- SkASSERT(tag < kSkTagListCount);
-
- while (rec != nullptr)
- {
- if (rec->fTag == tag)
- break;
- rec = rec->fNext;
- }
- return rec;
-}
-
-void SkTagList::DeleteTag(SkTagList** head, U8CPU tag)
-{
- SkASSERT(tag < kSkTagListCount);
-
- SkTagList* rec = *head;
- SkTagList* prev = nullptr;
-
- while (rec != nullptr)
- {
- SkTagList* next = rec->fNext;
-
- if (rec->fTag == tag)
- {
- if (prev)
- prev->fNext = next;
- else
- *head = next;
- delete rec;
- break;
- }
- prev = rec;
- rec = next;
- }
-}
-
-void SkTagList::DeleteAll(SkTagList* rec)
-{
- while (rec)
- {
- SkTagList* next = rec->fNext;
- delete rec;
- rec = next;
- }
-}
diff --git a/src/views/SkTagList.h b/src/views/SkTagList.h
deleted file mode 100644
index 0b158e1abe..0000000000
--- a/src/views/SkTagList.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkTagList_DEFINED
-#define SkTagList_DEFINED
-
-#include "SkTypes.h"
-
-enum SkTagListEnum {
- kListeners_SkTagList,
- kViewLayout_SkTagList,
- kViewArtist_SkTagList,
-
- kSkTagListCount
-};
-
-struct SkTagList {
- SkTagList* fNext;
- uint16_t fExtra16;
- uint8_t fExtra8;
- uint8_t fTag;
-
- SkTagList(U8CPU tag) : fTag(SkToU8(tag))
- {
- SkASSERT(tag < kSkTagListCount);
- fNext = nullptr;
- fExtra16 = 0;
- fExtra8 = 0;
- }
- virtual ~SkTagList();
-
- static SkTagList* Find(SkTagList* head, U8CPU tag);
- static void DeleteTag(SkTagList** headptr, U8CPU tag);
- static void DeleteAll(SkTagList* head);
-};
-
-#endif
diff --git a/src/views/SkView.cpp b/src/views/SkView.cpp
index 9c148dfac7..be765f1faf 100644
--- a/src/views/SkView.cpp
+++ b/src/views/SkView.cpp
@@ -70,7 +70,6 @@ void SkView::setSize(SkScalar width, SkScalar height) {
fHeight = height;
this->inval(nullptr);
this->onSizeChange();
- this->invokeLayout();
}
}
@@ -444,21 +443,7 @@ void SkView::DoClickUp(Click* click, int x, int y, unsigned modi) {
//////////////////////////////////////////////////////////////////////
-void SkView::invokeLayout() {
- SkView::Layout* layout = this->getLayout();
-
- if (layout) {
- layout->layoutChildren(this);
- }
-}
-
-void SkView::onDraw(SkCanvas* canvas) {
- Artist* artist = this->getArtist();
-
- if (artist) {
- artist->draw(this, canvas);
- }
-}
+void SkView::onDraw(SkCanvas* canvas) {}
void SkView::onSizeChange() {}
@@ -525,7 +510,6 @@ void SkView::detachFromParent() {
if (parent) {
this->detachFromParent_NoLayout();
- parent->invokeLayout();
}
}
@@ -554,7 +538,6 @@ SkView* SkView::attachChildToBack(SkView* child) {
child->inval(nullptr);
this->validate();
- this->invokeLayout();
DONE:
return child;
}
@@ -584,7 +567,6 @@ SkView* SkView::attachChildToFront(SkView* child) {
child->inval(nullptr);
this->validate();
- this->invokeLayout();
DONE:
return child;
}
diff --git a/src/views/SkViewPriv.cpp b/src/views/SkViewPriv.cpp
deleted file mode 100644
index b426ade433..0000000000
--- a/src/views/SkViewPriv.cpp
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkDOM.h"
-#include "SkViewPriv.h"
-
-//////////////////////////////////////////////////////////////////////
-
-void SkView::Artist::draw(SkView* view, SkCanvas* canvas)
-{
- SkASSERT(view && canvas);
- this->onDraw(view, canvas);
-}
-
-void SkView::Artist::inflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- SkASSERT(node);
- this->onInflate(dom, node);
-}
-
-void SkView::Artist::onInflate(const SkDOM&, const SkDOM::Node*)
-{
- // subclass should override this as needed
-}
-
-SkView::Artist* SkView::getArtist() const
-{
- Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
- SkASSERT(rec == nullptr || rec->fArtist != nullptr);
-
- return rec ? rec->fArtist : nullptr;
-}
-
-SkView::Artist* SkView::setArtist(Artist* obj)
-{
- if (obj == nullptr)
- {
- this->removeTagList(kViewArtist_SkTagList);
- }
- else // add/replace
- {
- Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
-
- if (rec)
- SkRefCnt_SafeAssign(rec->fArtist, obj);
- else
- this->addTagList(new Artist_SkTagList(obj));
- }
- return obj;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-void SkView::Layout::layoutChildren(SkView* parent)
-{
- SkASSERT(parent);
- if (parent->width() > 0 && parent->height() > 0)
- this->onLayoutChildren(parent);
-}
-
-void SkView::Layout::inflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- SkASSERT(node);
- this->onInflate(dom, node);
-}
-
-void SkView::Layout::onInflate(const SkDOM&, const SkDOM::Node*)
-{
- // subclass should override this as needed
-}
-
-SkView::Layout* SkView::getLayout() const
-{
- Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
- SkASSERT(rec == nullptr || rec->fLayout != nullptr);
-
- return rec ? rec->fLayout : nullptr;
-}
-
-SkView::Layout* SkView::setLayout(Layout* obj, bool invokeLayoutNow)
-{
- if (obj == nullptr)
- {
- this->removeTagList(kViewLayout_SkTagList);
- }
- else // add/replace
- {
- Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
-
- if (rec)
- SkRefCnt_SafeAssign(rec->fLayout, obj);
- else
- this->addTagList(new Layout_SkTagList(obj));
- }
-
- if (invokeLayoutNow)
- this->invokeLayout();
-
- return obj;
-}
diff --git a/src/views/SkViewPriv.h b/src/views/SkViewPriv.h
deleted file mode 100644
index 3b7645712c..0000000000
--- a/src/views/SkViewPriv.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#ifndef SkViewPriv_DEFINED
-#define SkViewPriv_DEFINED
-
-#include "SkView.h"
-#include "SkTagList.h"
-
-struct Layout_SkTagList : SkTagList {
- SkView::Layout* fLayout;
-
- Layout_SkTagList(SkView::Layout* layout)
- : SkTagList(kViewLayout_SkTagList), fLayout(layout)
- {
- SkASSERT(layout);
- layout->ref();
- }
- virtual ~Layout_SkTagList()
- {
- fLayout->unref();
- }
-};
-
-struct Artist_SkTagList : SkTagList {
- SkView::Artist* fArtist;
-
- Artist_SkTagList(SkView::Artist* artist)
- : SkTagList(kViewArtist_SkTagList), fArtist(artist)
- {
- SkASSERT(artist);
- artist->ref();
- }
- virtual ~Artist_SkTagList()
- {
- fArtist->unref();
- }
-};
-
-#endif
diff --git a/src/views/SkWindow.cpp b/src/views/SkWindow.cpp
deleted file mode 100644
index ba06a1f3c2..0000000000
--- a/src/views/SkWindow.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkWindow.h"
-#include "SkCanvas.h"
-#include "SkOSMenu.h"
-#include "SkSurface.h"
-#include "SkSystemEventTypes.h"
-#include "SkTime.h"
-
-#define SK_EventDelayInval "\xd" "n" "\xa" "l"
-
-SkWindow::SkWindow()
- : fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
- , fFocusView(nullptr)
-{
- fClicks.reset();
- fWaitingOnInval = false;
- fMatrix.reset();
-
- fBitmap.allocN32Pixels(0, 0);
-}
-
-SkWindow::~SkWindow() {
- fClicks.deleteAll();
- fMenus.deleteAll();
-}
-
-sk_sp<SkSurface> SkWindow::makeSurface() {
- const SkBitmap& bm = this->getBitmap();
- return SkSurface::MakeRasterDirect(bm.info(), bm.getPixels(), bm.rowBytes(), &fSurfaceProps);
-}
-
-void SkWindow::setMatrix(const SkMatrix& matrix) {
- if (fMatrix != matrix) {
- fMatrix = matrix;
- this->inval(nullptr);
- }
-}
-
-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::resize(const SkImageInfo& info) {
- if (fBitmap.info() != info) {
- fBitmap.allocPixels(info);
- this->inval(nullptr);
- }
- this->setSize(SkIntToScalar(fBitmap.width()), SkIntToScalar(fBitmap.height()));
-}
-
-void SkWindow::resize(int width, int height) {
- this->resize(fBitmap.info().makeWH(width, height));
-}
-
-void SkWindow::setColorType(SkColorType ct, sk_sp<SkColorSpace> cs) {
- const SkImageInfo& info = fBitmap.info();
- this->resize(SkImageInfo::Make(info.width(), info.height(), ct, kPremul_SkAlphaType, cs));
-}
-
-bool SkWindow::handleInval(const SkRect* localR) {
- SkIRect 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,
- SkScalarRoundToInt(this->width()),
- SkScalarRoundToInt(this->height()));
- }
- fDirtyRgn.op(ir, SkRegion::kUnion_Op);
-
- this->onHandleInval(ir);
- return true;
-}
-
-void SkWindow::forceInvalAll() {
- fDirtyRgn.setRect(0, 0,
- SkScalarCeilToInt(this->width()),
- SkScalarCeilToInt(this->height()));
-}
-
-#ifdef SK_SIMULATE_FAILED_MALLOC
-extern bool gEnableControlledThrow;
-#endif
-
-bool SkWindow::update(SkIRect* updateArea) {
- if (!fDirtyRgn.isEmpty()) {
- sk_sp<SkSurface> surface(this->makeSurface());
- SkCanvas* canvas = surface->getCanvas();
-
- 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 SK_SIMULATE_FAILED_MALLOC
- gEnableControlledThrow = true;
-#endif
-#ifdef SK_BUILD_FOR_WIN32
- //try {
- this->draw(canvas);
- //}
- //catch (...) {
- //}
-#else
- this->draw(canvas);
-#endif
-#ifdef SK_SIMULATE_FAILED_MALLOC
- gEnableControlledThrow = false;
-#endif
-
- return true;
- }
- return false;
-}
-
-bool SkWindow::handleChar(SkUnichar uni) {
- if (this->onHandleChar(uni))
- return true;
-
- SkView* focus = this->getFocusView();
- if (focus == nullptr)
- focus = this;
-
- SkEvent evt(SK_EventType_Unichar);
- evt.setFast32(uni);
- return focus->doEvent(evt);
-}
-
-bool SkWindow::handleKey(SkKey key) {
- if (key == kNONE_SkKey)
- return false;
-
- if (this->onHandleKey(key))
- return true;
-
- // send an event to the focus-view
- {
- SkView* focus = this->getFocusView();
- if (focus == nullptr)
- focus = this;
-
- SkEvent evt(SK_EventType_Key);
- evt.setFast32(key);
- if (focus->doEvent(evt))
- return true;
- }
-
- if (key == kUp_SkKey || key == kDown_SkKey) {
- if (this->moveFocus(key == kUp_SkKey ? kPrev_FocusDirection : kNext_FocusDirection) == nullptr)
- this->onSetFocusView(nullptr);
- return true;
- }
- return false;
-}
-
-bool SkWindow::handleKeyUp(SkKey key) {
- if (key == kNONE_SkKey)
- return false;
-
- if (this->onHandleKeyUp(key))
- return true;
-
- //send an event to the focus-view
- {
- SkView* focus = this->getFocusView();
- if (focus == nullptr)
- focus = this;
-
- //should this one be the same?
- SkEvent evt(SK_EventType_KeyUp);
- evt.setFast32(key);
- if (focus->doEvent(evt))
- return true;
- }
- return false;
-}
-
-void SkWindow::addMenu(SkOSMenu* menu) {
- *fMenus.append() = menu;
- this->onAddMenu(menu);
-}
-
-void SkWindow::setTitle(const char title[]) {
- if (nullptr == title) {
- title = "";
- }
- fTitle.set(title);
- this->onSetTitle(title);
-}
-
-bool SkWindow::onEvent(const SkEvent& evt) {
- if (evt.isType(SK_EventDelayInval)) {
- for (SkRegion::Iterator iter(fDirtyRgn); !iter.done(); iter.next())
- this->onHandleInval(iter.rect());
- fWaitingOnInval = false;
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-bool SkWindow::onGetFocusView(SkView** focus) const {
- if (focus)
- *focus = fFocusView;
- return true;
-}
-
-bool SkWindow::onSetFocusView(SkView* focus) {
- if (fFocusView != focus) {
- if (fFocusView)
- fFocusView->onFocusChange(false);
- fFocusView = focus;
- if (focus)
- focus->onFocusChange(true);
- }
- return true;
-}
-
-void SkWindow::onHandleInval(const SkIRect&) {
-}
-
-bool SkWindow::onHandleChar(SkUnichar) {
- return false;
-}
-
-bool SkWindow::onHandleKey(SkKey) {
- return false;
-}
-
-bool SkWindow::onHandleKeyUp(SkKey) {
- return false;
-}
-
-bool SkWindow::handleClick(int x, int y, Click::State state, void *owner,
- unsigned modifierKeys) {
- return this->onDispatchClick(x, y, state, owner, modifierKeys);
-}
-
-bool SkWindow::onDispatchClick(int x, int y, Click::State state,
- void* owner, unsigned modifierKeys) {
- bool handled = false;
-
- // First, attempt to find an existing click with this owner.
- int index = -1;
- for (int i = 0; i < fClicks.count(); i++) {
- if (owner == fClicks[i]->fOwner) {
- index = i;
- break;
- }
- }
-
- switch (state) {
- case Click::kDown_State: {
- if (index != -1) {
- delete fClicks[index];
- fClicks.remove(index);
- }
- Click* click = this->findClickHandler(SkIntToScalar(x),
- SkIntToScalar(y), modifierKeys);
-
- if (click) {
- click->fOwner = owner;
- *fClicks.append() = click;
- SkView::DoClickDown(click, x, y, modifierKeys);
- handled = true;
- }
- break;
- }
- case Click::kMoved_State:
- if (index != -1) {
- SkView::DoClickMoved(fClicks[index], x, y, modifierKeys);
- handled = true;
- }
- break;
- case Click::kUp_State:
- if (index != -1) {
- SkView::DoClickUp(fClicks[index], x, y, modifierKeys);
- delete fClicks[index];
- fClicks.remove(index);
- handled = true;
- }
- break;
- default:
- // Do nothing
- break;
- }
- return handled;
-}
-
-#if SK_SUPPORT_GPU
-
-#include "GrBackendSurface.h"
-#include "GrContext.h"
-#include "gl/GrGLInterface.h"
-#include "gl/GrGLUtil.h"
-#include "SkGr.h"
-
-sk_sp<SkSurface> SkWindow::makeGpuBackedSurface(const AttachmentInfo& attachmentInfo,
- const GrGLInterface* interface,
- GrContext* grContext) {
- int width = SkScalarRoundToInt(this->width());
- int height = SkScalarRoundToInt(this->height());
- if (0 == width || 0 == height) {
- return nullptr;
- }
-
- // TODO: Query the actual framebuffer for sRGB capable. However, to
- // preserve old (fake-linear) behavior, we don't do this. Instead, rely
- // on the flag (currently driven via 'C' mode in SampleApp).
- //
- // Also, we may not have real sRGB support (ANGLE, in particular), so check for
- // that, and fall back to L32:
- //
- // ... and, if we're using a 10-bit/channel FB0, it doesn't do sRGB conversion on write,
- // so pretend that it's non-sRGB 8888:
- GrPixelConfig config = grContext->caps()->srgbSupport() &&
- info().colorSpace() &&
- (attachmentInfo.fColorBits != 30)
- ? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
- GrGLFramebufferInfo fbInfo;
- GrGLint buffer;
- GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
- fbInfo.fFBOID = buffer;
-
- GrBackendRenderTarget backendRT(width,
- height,
- attachmentInfo.fSampleCount,
- attachmentInfo.fStencilBits,
- config,
- fbInfo);
-
-
- sk_sp<SkColorSpace> colorSpace =
- grContext->caps()->srgbSupport() && info().colorSpace()
- ? SkColorSpace::MakeSRGB() : nullptr;
- return SkSurface::MakeFromBackendRenderTarget(grContext, backendRT, kBottomLeft_GrSurfaceOrigin,
- colorSpace, &fSurfaceProps);
-}
-
-#endif
diff --git a/src/views/ios/SkOSWindow_iOS.mm b/src/views/ios/SkOSWindow_iOS.mm
deleted file mode 100755
index 3e2937181f..0000000000
--- a/src/views/ios/SkOSWindow_iOS.mm
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import <UIKit/UIKit.h>
-#include "SkCanvas.h"
-#include "SkGraphics.h"
-#import "SkEventNotifier.h"
-#include "SkOSMenu.h"
-#include "SkTime.h"
-#include "SkTypes.h"
-#import "SkUIView.h"
-#include "SkWindow.h"
-
-#define kINVAL_UIVIEW_EventType "inval-uiview"
-
-SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
- fInvalEventIsPending = false;
- fNotifier = [[SkEventNotifier alloc] init];
-}
-SkOSWindow::~SkOSWindow() {
- [(SkEventNotifier*)fNotifier release];
-}
-
-void SkOSWindow::onHandleInval(const SkIRect& r) {
- if (!fInvalEventIsPending) {
- fInvalEventIsPending = true;
- (new SkEvent(kINVAL_UIVIEW_EventType, this->getSinkID()))->post();
- }
-}
-
-bool SkOSWindow::onEvent(const SkEvent& evt) {
- if (evt.isType(kINVAL_UIVIEW_EventType)) {
- fInvalEventIsPending = false;
- const SkIRect& r = this->getDirtyBounds();
- [(SkUIView*)fHWND postInvalWithRect:&r];
- return true;
- }
- if ([(SkUIView*)fHWND onHandleEvent:evt]) {
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-void SkOSWindow::onSetTitle(const char title[]) {
- [(SkUIView*)fHWND setSkTitle:title];
-}
-
-void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
- [(SkUIView*)fHWND onAddMenu:menu];
-}
-
-void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
- [(SkUIView*)fHWND onUpdateMenu:menu];
-}
-
-bool SkOSWindow::attach(SkBackEndTypes /* attachType */,
- int /* msaaSampleCount */,
- bool /* deepColor */,
- AttachmentInfo* info) {
- [(SkUIView*)fHWND getAttachmentInfo:info];
- bool success = true;
- return success;
-}
-
-void SkOSWindow::release() {}
-
-void SkOSWindow::present() {
-}
diff --git a/src/views/mac/SkEventNotifier.h b/src/views/mac/SkEventNotifier.h
deleted file mode 100644
index ea6bbf1e34..0000000000
--- a/src/views/mac/SkEventNotifier.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#import <Foundation/Foundation.h>
-
-@interface SkEventNotifier : NSObject
-- (void)receiveSkEvent:(NSNotification*)notification;
-+ (void)postTimedSkEvent:(NSTimeInterval)ti;
-+ (void)timerFireMethod:(NSTimer*)theTimer;
-@end
diff --git a/src/views/mac/SkEventNotifier.mm b/src/views/mac/SkEventNotifier.mm
deleted file mode 100644
index 0864380d95..0000000000
--- a/src/views/mac/SkEventNotifier.mm
+++ /dev/null
@@ -1,68 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import "SkEventNotifier.h"
-#include "SkEvent.h"
-#define SkEventClass @"SkEvenClass"
-@implementation SkEventNotifier
-- (id)init {
- self = [super init];
- if (self) {
- //Register as an observer for SkEventClass events and call
- //receiveSkEvent: upon receiving the event
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(receiveSkEvent:)
- name:SkEventClass
- object:nil];
- }
- return self;
-}
-
-- (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [super dealloc];
-}
-
--(BOOL) acceptsFirstResponder {
- return YES;
-}
-
-//SkEvent Handers
-- (void)receiveSkEvent:(NSNotification *)notification {
- if(SkEvent::ProcessEvent())
- SkEvent::SignalNonEmptyQueue();
-}
-
-+ (void)postTimedSkEvent:(NSTimeInterval)timeInterval {
- [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self
- selector:@selector(timerFireMethod:)
- userInfo:nil repeats:NO];
-}
-
-+ (void)timerFireMethod:(NSTimer*)theTimer {
- SkEvent::ServiceQueueTimer();
-}
-
-@end
-////////////////////////////////////////////////////////////////////////////////
-void SkEvent::SignalNonEmptyQueue() {
- //post a SkEventClass event to the default notification queue
- NSNotification* notification = [NSNotification notificationWithName:SkEventClass object:nil];
- [[NSNotificationQueue defaultQueue] enqueueNotification:notification
- postingStyle:NSPostWhenIdle
- coalesceMask:NSNotificationNoCoalescing
- forModes:nil];
-}
-
-void SkEvent::SignalQueueTimer(SkMSec delay) {
- if (delay) {
- //Convert to seconds
- NSTimeInterval ti = delay/(float)SK_MSec1;
- [SkEventNotifier postTimedSkEvent:ti];
- }
-}
diff --git a/src/views/mac/SkNSView.h b/src/views/mac/SkNSView.h
deleted file mode 100644
index bf83c61c25..0000000000
--- a/src/views/mac/SkNSView.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import <QuartzCore/QuartzCore.h>
-#import <Cocoa/Cocoa.h>
-#import "SkWindow.h"
-
-class SkEvent;
-@class SkNSView;
-
-@protocol SkNSViewOptionsDelegate <NSObject>
-@optional
-// Called when the view needs to handle adding an SkOSMenu
-- (void) view:(SkNSView*)view didAddMenu:(const SkOSMenu*)menu;
-- (void) view:(SkNSView*)view didUpdateMenu:(const SkOSMenu*)menu;
-@end
-
-@interface SkNSView : NSView
-@property (nonatomic, retain) NSString* fTitle;
-#if SK_SUPPORT_GPU
-@property (nonatomic, retain) NSOpenGLContext* fGLContext;
-#endif
-@property (nonatomic, assign) id<SkNSViewOptionsDelegate> fOptionsDelegate;
-
-- (id)initWithDefaults;
-- (void)setNSViewSize:(NSSize)size;
-- (void)setUpWindow;
-- (void)resizeSkView:(NSSize)newSize;
-- (void)setSkTitle:(const char*)title;
-- (void)onAddMenu:(const SkOSMenu*)menu;
-- (void)onUpdateMenu:(const SkOSMenu*)menu;
-- (void)postInvalWithRect:(const SkIRect*)rectOrNil;
-- (BOOL)onHandleEvent:(const SkEvent&)event;
-
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount andGetInfo:(SkOSWindow::AttachmentInfo*) info;
-- (void)detach;
-- (void)present;
-
-- (void)setVSync:(bool)enable;
-
-- (void)freeNativeWind;
-
-@end
-
-@interface SkNSView()
- @property (nonatomic, readwrite) SkOSWindow *fWind;
-@end
diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm
deleted file mode 100644
index 9e25f2e7b4..0000000000
--- a/src/views/mac/SkNSView.mm
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import "SkNSView.h"
-#include "SkCanvas.h"
-#include "SkSurface.h"
-#include "SkCGUtils.h"
-#include "SkEvent.h"
-static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");
-#include <OpenGL/gl.h>
-
-//#define FORCE_REDRAW
-// Can be dropped when we no longer support 10.6.
-#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
- #define RETINA_API_AVAILABLE 1
-#else
- #define RETINA_API_AVAILABLE 0
-#endif
-
-@implementation SkNSView
-@synthesize fWind, fTitle, fOptionsDelegate, fGLContext;
-
-BOOL fRedrawRequestPending;
-
-- (id)initWithCoder:(NSCoder*)coder {
- if ((self = [super initWithCoder:coder])) {
- self = [self initWithDefaults];
- [self setUpWindow];
- }
- return self;
-}
-
-- (id)initWithFrame:(NSRect)frameRect {
- if ((self = [super initWithFrame:frameRect])) {
- self = [self initWithDefaults];
- [self setUpWindow];
- }
- return self;
-}
-
-- (id)initWithDefaults {
-#if RETINA_API_AVAILABLE
- [self setWantsBestResolutionOpenGLSurface:YES];
-#endif
- fRedrawRequestPending = false;
- fWind = NULL;
- return self;
-}
-
-- (void)setNSViewSize:(NSSize)size {
- NSWindow* w = [self window];
- NSRect f = w.frame;
- f.size = size;
- [w setFrame:f display:YES];
-}
-
-- (void)setUpWindow {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(backingPropertiesChanged:)
- name:@"NSWindowDidChangeBackingPropertiesNotification"
- object:[self window]];
- if (fWind) {
- fWind->setVisibleP(true);
- NSSize size = self.frame.size;
-#if RETINA_API_AVAILABLE
- size = [self convertSizeToBacking:self.frame.size];
-#endif
- fWind->resize((int) size.width, (int) size.height);
- [[self window] setAcceptsMouseMovedEvents:YES];
- }
-}
-
--(BOOL) isFlipped {
- return YES;
-}
-
-- (BOOL)acceptsFirstResponder {
- return YES;
-}
-
-- (float)scaleFactor {
- NSWindow *window = [self window];
-#if RETINA_API_AVAILABLE
- if (window) {
- return [window backingScaleFactor];
- }
- return [[NSScreen mainScreen] backingScaleFactor];
-#else
- if (window) {
- return [window userSpaceScaleFactor];
- }
- return [[NSScreen mainScreen] userSpaceScaleFactor];
-#endif
-}
-
-- (void)backingPropertiesChanged:(NSNotification *)notification {
- CGFloat oldBackingScaleFactor = (CGFloat)[
- [notification.userInfo objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue
- ];
- CGFloat newBackingScaleFactor = [self scaleFactor];
- if (oldBackingScaleFactor == newBackingScaleFactor) {
- return;
- }
-
- // TODO: need a better way to force a refresh (that works).
- // [fGLContext update] does not appear to update if the point size has not changed,
- // even if the backing size has changed.
- [self setFrameSize:NSMakeSize(self.frame.size.width + 1, self.frame.size.height + 1)];
-}
-
-- (void)resizeSkView:(NSSize)newSize {
-#if RETINA_API_AVAILABLE
- newSize = [self convertSizeToBacking:newSize];
-#endif
- if (fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) {
- fWind->resize((int) newSize.width, (int) newSize.height);
- if (fGLContext) {
- glClear(GL_STENCIL_BUFFER_BIT);
- [fGLContext update];
- }
- }
-}
-
-- (void) setFrameSize:(NSSize)newSize {
- [super setFrameSize:newSize];
- [self resizeSkView:newSize];
-}
-
-- (void)dealloc {
- [self freeNativeWind];
- self.fGLContext = nil;
- self.fTitle = nil;
- [super dealloc];
-}
-
-- (void)freeNativeWind {
- delete fWind;
- fWind = nil;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-- (void)drawSkia {
- fRedrawRequestPending = false;
- if (fWind) {
- sk_sp<SkSurface> surface(fWind->makeSurface());
- fWind->draw(surface->getCanvas());
-#ifdef FORCE_REDRAW
- fWind->inval(NULL);
-#endif
- }
-}
-
-- (void)setSkTitle:(const char *)title {
- self.fTitle = [NSString stringWithUTF8String:title];
- [[self window] setTitle:self.fTitle];
-}
-
-- (BOOL)onHandleEvent:(const SkEvent&)evt {
- return false;
-}
-
-#include "SkOSMenu.h"
-- (void)onAddMenu:(const SkOSMenu*)menu {
- [self.fOptionsDelegate view:self didAddMenu:menu];
-}
-
-- (void)onUpdateMenu:(const SkOSMenu*)menu {
- [self.fOptionsDelegate view:self didUpdateMenu:menu];
-}
-
-- (void)postInvalWithRect:(const SkIRect*)r {
- if (!fRedrawRequestPending) {
- fRedrawRequestPending = true;
- [self setNeedsDisplay:YES];
- [self performSelector:@selector(drawSkia) withObject:nil afterDelay:0];
- }
-}
-///////////////////////////////////////////////////////////////////////////////
-
-#include "SkKey.h"
-enum {
- SK_MacReturnKey = 36,
- SK_MacDeleteKey = 51,
- SK_MacEndKey = 119,
- SK_MacLeftKey = 123,
- SK_MacRightKey = 124,
- SK_MacDownKey = 125,
- SK_MacUpKey = 126,
- SK_Mac0Key = 0x52,
- SK_Mac1Key = 0x53,
- SK_Mac2Key = 0x54,
- SK_Mac3Key = 0x55,
- SK_Mac4Key = 0x56,
- SK_Mac5Key = 0x57,
- SK_Mac6Key = 0x58,
- SK_Mac7Key = 0x59,
- SK_Mac8Key = 0x5b,
- SK_Mac9Key = 0x5c
-};
-
-static SkKey raw2key(UInt32 raw)
-{
- static const struct {
- UInt32 fRaw;
- SkKey fKey;
- } gKeys[] = {
- { SK_MacUpKey, kUp_SkKey },
- { SK_MacDownKey, kDown_SkKey },
- { SK_MacLeftKey, kLeft_SkKey },
- { SK_MacRightKey, kRight_SkKey },
- { SK_MacReturnKey, kOK_SkKey },
- { SK_MacDeleteKey, kBack_SkKey },
- { SK_MacEndKey, kEnd_SkKey },
- { SK_Mac0Key, k0_SkKey },
- { SK_Mac1Key, k1_SkKey },
- { SK_Mac2Key, k2_SkKey },
- { SK_Mac3Key, k3_SkKey },
- { SK_Mac4Key, k4_SkKey },
- { SK_Mac5Key, k5_SkKey },
- { SK_Mac6Key, k6_SkKey },
- { SK_Mac7Key, k7_SkKey },
- { SK_Mac8Key, k8_SkKey },
- { SK_Mac9Key, k9_SkKey }
- };
-
- for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++)
- if (gKeys[i].fRaw == raw)
- return gKeys[i].fKey;
- return kNONE_SkKey;
-}
-
-- (void)keyDown:(NSEvent *)event {
- if (NULL == fWind)
- return;
-
- SkKey key = raw2key([event keyCode]);
- if (kNONE_SkKey != key)
- fWind->handleKey(key);
- else{
- unichar c = [[event characters] characterAtIndex:0];
- fWind->handleChar((SkUnichar)c);
- }
-}
-
-- (void)keyUp:(NSEvent *)event {
- if (NULL == fWind)
- return;
-
- SkKey key = raw2key([event keyCode]);
- if (kNONE_SkKey != key)
- fWind->handleKeyUp(key);
- // else
- // unichar c = [[event characters] characterAtIndex:0];
-}
-
-static const struct {
- unsigned fNSModifierMask;
- unsigned fSkModifierMask;
-} gModifierMasks[] = {
- { NSAlphaShiftKeyMask, kShift_SkModifierKey },
- { NSShiftKeyMask, kShift_SkModifierKey },
- { NSControlKeyMask, kControl_SkModifierKey },
- { NSAlternateKeyMask, kOption_SkModifierKey },
- { NSCommandKeyMask, kCommand_SkModifierKey },
-};
-
-static unsigned convertNSModifiersToSk(NSUInteger nsModi) {
- unsigned skModi = 0;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gModifierMasks); ++i) {
- if (nsModi & gModifierMasks[i].fNSModifierMask) {
- skModi |= gModifierMasks[i].fSkModifierMask;
- }
- }
- return skModi;
-}
-
-- (void)mouseDown:(NSEvent *)event {
- NSPoint p = [event locationInWindow];
- unsigned modi = convertNSModifiersToSk([event modifierFlags]);
-
- if ([self mouse:p inRect:[self bounds]] && fWind) {
- NSPoint loc = [self convertPoint:p fromView:nil];
-#if RETINA_API_AVAILABLE
- loc = [self convertPointToBacking:loc]; //y-up
- loc.y = -loc.y;
-#endif
- fWind->handleClick((int) loc.x, (int) loc.y,
- SkView::Click::kDown_State, self, modi);
- }
-}
-
-- (void)mouseDragged:(NSEvent *)event {
- NSPoint p = [event locationInWindow];
- unsigned modi = convertNSModifiersToSk([event modifierFlags]);
-
- if ([self mouse:p inRect:[self bounds]] && fWind) {
- NSPoint loc = [self convertPoint:p fromView:nil];
-#if RETINA_API_AVAILABLE
- loc = [self convertPointToBacking:loc]; //y-up
- loc.y = -loc.y;
-#endif
- fWind->handleClick((int) loc.x, (int) loc.y,
- SkView::Click::kMoved_State, self, modi);
- }
-}
-
-- (void)mouseMoved:(NSEvent *)event {
- NSPoint p = [event locationInWindow];
- unsigned modi = convertNSModifiersToSk([event modifierFlags]);
-
- if ([self mouse:p inRect:[self bounds]] && fWind) {
- NSPoint loc = [self convertPoint:p fromView:nil];
-#if RETINA_API_AVAILABLE
- loc = [self convertPointToBacking:loc]; //y-up
- loc.y = -loc.y;
-#endif
- fWind->handleClick((int) loc.x, (int) loc.y,
- SkView::Click::kMoved_State, self, modi);
- }
-}
-
-- (void)mouseUp:(NSEvent *)event {
- NSPoint p = [event locationInWindow];
- unsigned modi = convertNSModifiersToSk([event modifierFlags]);
-
- if ([self mouse:p inRect:[self bounds]] && fWind) {
- NSPoint loc = [self convertPoint:p fromView:nil];
-#if RETINA_API_AVAILABLE
- loc = [self convertPointToBacking:loc]; //y-up
- loc.y = -loc.y;
-#endif
- fWind->handleClick((int) loc.x, (int) loc.y,
- SkView::Click::kUp_State, self, modi);
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-#include <OpenGL/OpenGL.h>
-
-static CGLContextObj createGLContext(int msaaSampleCount) {
- GLint major, minor;
- CGLGetVersion(&major, &minor);
-
- static const CGLPixelFormatAttribute attributes[] = {
- kCGLPFAStencilSize, (CGLPixelFormatAttribute) 8,
- kCGLPFAAccelerated,
- kCGLPFADoubleBuffer,
- kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
- (CGLPixelFormatAttribute)0
- };
-
- CGLPixelFormatObj format;
- GLint npix = 0;
- if (msaaSampleCount > 0) {
- static const int kAttributeCount = SK_ARRAY_COUNT(attributes);
- CGLPixelFormatAttribute msaaAttributes[kAttributeCount + 5];
- memcpy(msaaAttributes, attributes, sizeof(attributes));
- SkASSERT(0 == msaaAttributes[kAttributeCount - 1]);
- msaaAttributes[kAttributeCount - 1] = kCGLPFASampleBuffers;
- msaaAttributes[kAttributeCount + 0] = (CGLPixelFormatAttribute)1;
- msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample;
- msaaAttributes[kAttributeCount + 2] = kCGLPFASamples;
- msaaAttributes[kAttributeCount + 3] =
- (CGLPixelFormatAttribute)msaaSampleCount;
- msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0;
- CGLChoosePixelFormat(msaaAttributes, &format, &npix);
- }
- if (!npix) {
- CGLChoosePixelFormat(attributes, &format, &npix);
- }
- CGLContextObj ctx;
- CGLCreateContext(format, NULL, &ctx);
- CGLDestroyPixelFormat(format);
-
- static const GLint interval = 1;
- CGLSetParameter(ctx, kCGLCPSwapInterval, &interval);
- CGLSetCurrentContext(ctx);
- return ctx;
-}
-
-- (void)viewDidMoveToWindow {
- [super viewDidMoveToWindow];
-
- //Attaching view to fGLContext requires that the view to be part of a window,
- //and that the NSWindow instance must have a CoreGraphics counterpart (or
- //it must NOT be deferred or should have been on screen at least once)
- if ([fGLContext view] != self && nil != self.window) {
- [fGLContext setView:self];
- }
-}
-- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType
- withMSAASampleCount:(int) sampleCount
- andGetInfo:(SkOSWindow::AttachmentInfo*) info {
- if (nil == fGLContext) {
- CGLContextObj ctx = createGLContext(sampleCount);
- SkASSERT(ctx);
- fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx];
- CGLReleaseContext(ctx);
- if (NULL == fGLContext) {
- return false;
- }
- [fGLContext setView:self];
- }
-
- [fGLContext makeCurrentContext];
- CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLContextObj]);
- CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount);
- CGLDescribePixelFormat(format, 0, kCGLPFAStencilSize, &info->fStencilBits);
- NSSize size = self.bounds.size;
-#if RETINA_API_AVAILABLE
- size = [self convertSizeToBacking:size];
-#endif
- glViewport(0, 0, (int) size.width, (int) size.height);
- glClearColor(0, 0, 0, 0);
- glClearStencil(0);
- glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- return true;
-}
-
-- (void)detach {
- [fGLContext release];
- fGLContext = nil;
-}
-
-- (void)present {
- if (nil != fGLContext) {
- [fGLContext flushBuffer];
- }
-}
-
-- (void)setVSync:(bool)enable {
- if (fGLContext) {
- GLint interval = enable ? 1 : 0;
- CGLContextObj ctx = (CGLContextObj)[fGLContext CGLContextObj];
- CGLSetParameter(ctx, kCGLCPSwapInterval, &interval);
- }
-}
-@end
diff --git a/src/views/mac/SkOSWindow_Mac.mm b/src/views/mac/SkOSWindow_Mac.mm
deleted file mode 100644
index bb00bbcf77..0000000000
--- a/src/views/mac/SkOSWindow_Mac.mm
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import <Cocoa/Cocoa.h>
-#include "SkOSWindow_Mac.h"
-#include "SkOSMenu.h"
-#include "SkTypes.h"
-#include "SkWindow.h"
-#import "SkNSView.h"
-#import "SkEventNotifier.h"
-#define kINVAL_NSVIEW_EventType "inval-nsview"
-
-static constexpr int DEFAULT_W = 1024;
-static constexpr int DEFAULT_H = 768;
-
-static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build");
-
-SkOSWindow::SkOSWindow(void* hwnd, int w, int h): fHWND(hwnd) {
- this->init(hwnd, w, h);
-}
-
-SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) {
- this->init(hWnd, DEFAULT_W, DEFAULT_H);
-}
-
-void SkOSWindow::init(void* hwnd, int w, int h) {
- fInvalEventIsPending = false;
- fGLContext = NULL;
- fNotifier = [[SkEventNotifier alloc] init];
- [(SkNSView*)hwnd setNSViewSize:NSMakeSize(w, h)];
-}
-
-SkOSWindow::~SkOSWindow() {
- [(SkEventNotifier*)fNotifier release];
-}
-
-void SkOSWindow::onHandleInval(const SkIRect& r) {
- if (!fInvalEventIsPending) {
- fInvalEventIsPending = true;
- (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post();
- }
-}
-
-bool SkOSWindow::onEvent(const SkEvent& evt) {
- if (evt.isType(kINVAL_NSVIEW_EventType)) {
- fInvalEventIsPending = false;
- const SkIRect& r = this->getDirtyBounds();
- [(SkNSView*)fHWND postInvalWithRect:&r];
- [(NSOpenGLContext*)fGLContext update];
- return true;
- }
- if ([(SkNSView*)fHWND onHandleEvent:evt]) {
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner,
- unsigned modi) {
- return this->INHERITED::onDispatchClick(x, y, state, owner, modi);
-}
-
-void SkOSWindow::onSetTitle(const char title[]) {
- [(SkNSView*)fHWND setSkTitle:title];
-}
-
-void SkOSWindow::onAddMenu(const SkOSMenu* menu) {
- [(SkNSView*)fHWND onAddMenu:menu];
-}
-
-void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) {
- [(SkNSView*)fHWND onUpdateMenu:menu];
-}
-
-bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, bool /*deepColor*/,
- AttachmentInfo* info) {
- return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info];
-}
-
-void SkOSWindow::release() {
- [(SkNSView*)fHWND detach];
-}
-
-void SkOSWindow::present() {
- [(SkNSView*)fHWND present];
-}
-
-void SkOSWindow::closeWindow() {
- [[(SkNSView*)fHWND window] close];
-}
-
-void SkOSWindow::setVsync(bool enable) {
- [(SkNSView*)fHWND setVSync:enable];
-}
-
-bool SkOSWindow::makeFullscreen() {
- NSScreen* _Nullable screen = [NSScreen mainScreen];
- if (screen) {
- [(SkNSView*)fHWND enterFullScreenMode:(NSScreen* _Nonnull)screen withOptions:nil];
- }
- return true;
-}
-
diff --git a/src/views/mac/SkOptionsTableView.h b/src/views/mac/SkOptionsTableView.h
deleted file mode 100644
index 8fa03d1fc5..0000000000
--- a/src/views/mac/SkOptionsTableView.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import <Cocoa/Cocoa.h>
-#import "SkNSView.h"
-#import "SkOSMenu.h"
-#import "SkEvent.h"
-@interface SkOptionItem : NSObject {
- NSCell* fCell;
- const SkOSMenu::Item* fItem;
-}
-@property (nonatomic, assign) const SkOSMenu::Item* fItem;
-@property (nonatomic, retain) NSCell* fCell;
-@end
-
-@interface SkOptionsTableView : NSTableView <SkNSViewOptionsDelegate, NSTableViewDelegate, NSTableViewDataSource> {
- NSMutableArray* fItems;
- const SkTDArray<SkOSMenu*>* fMenus;
- BOOL fShowKeys;
-}
-@property (nonatomic, retain) NSMutableArray* fItems;
-
-- (void)registerMenus:(const SkTDArray<SkOSMenu*>*)menus;
-- (void)updateMenu:(const SkOSMenu*)menu;
-- (void)loadMenu:(const SkOSMenu*)menu;
-- (IBAction)toggleKeyEquivalents:(id)sender;
-
-- (NSCell*)createAction;
-- (NSCell*)createList:(NSArray*)items current:(int)index;
-- (NSCell*)createSlider:(float)value min:(float)min max:(float)max;
-- (NSCell*)createSwitch:(BOOL)state;
-- (NSCell*)createTextField:(NSString*)placeHolder;
-- (NSCell*)createTriState:(NSCellStateValue)state;
-
-@end
diff --git a/src/views/mac/SkOptionsTableView.mm b/src/views/mac/SkOptionsTableView.mm
deleted file mode 100644
index 51d4864833..0000000000
--- a/src/views/mac/SkOptionsTableView.mm
+++ /dev/null
@@ -1,297 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import "SkOptionsTableView.h"
-#import "SkTextFieldCell.h"
-@implementation SkOptionItem
-@synthesize fCell, fItem;
-- (void)dealloc {
- [fCell release];
- [super dealloc];
-}
-@end
-
-@implementation SkOptionsTableView
-@synthesize fItems;
-
-- (id)initWithCoder:(NSCoder*)coder {
- if ((self = [super initWithCoder:coder])) {
- self.dataSource = self;
- self.delegate = self;
- fMenus = NULL;
- fShowKeys = YES;
- [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone];
- self.fItems = [NSMutableArray array];
- }
- return self;
-}
-
-- (void)dealloc {
- self.fItems = nil;
- [super dealloc];
-}
-
-- (void) view:(SkNSView*)view didAddMenu:(const SkOSMenu*)menu {}
-- (void) view:(SkNSView*)view didUpdateMenu:(const SkOSMenu*)menu {
- [self updateMenu:menu];
-}
-
-- (IBAction)toggleKeyEquivalents:(id)sender {
- fShowKeys = !fShowKeys;
- NSMenuItem* item = (NSMenuItem*)sender;
- [item setState:fShowKeys];
- [self reloadData];
-}
-
-- (void)registerMenus:(const SkTDArray<SkOSMenu*>*)menus {
- fMenus = menus;
- for (int i = 0; i < fMenus->count(); ++i) {
- [self loadMenu:(*fMenus)[i]];
- }
-}
-
-- (void)updateMenu:(const SkOSMenu*)menu {
- // the first menu is always assumed to be the static, the second is
- // repopulated every time over and over again
-
- // seems pretty weird that we have to get rid of the const'ness here,
- // but trying to propagate the const'ness through all the way to the fMenus
- // vector was a non-starter.
-
- int menuIndex = fMenus->find(const_cast<SkOSMenu *>(menu));
- if (menuIndex >= 0 && menuIndex < fMenus->count()) {
- NSUInteger first = 0;
- for (int i = 0; i < menuIndex; ++i) {
- first += (*fMenus)[i]->getCount();
- }
- [fItems removeObjectsInRange:NSMakeRange(first, [fItems count] - first)];
- [self loadMenu:menu];
- }
- [self reloadData];
-}
-
-- (NSCellStateValue)triStateToNSState:(SkOSMenu::TriState)state {
- if (SkOSMenu::kOnState == state)
- return NSOnState;
- else if (SkOSMenu::kOffState == state)
- return NSOffState;
- else
- return NSMixedState;
-}
-
-- (void)loadMenu:(const SkOSMenu*)menu {
- const SkOSMenu::Item* menuitems[menu->getCount()];
- menu->getItems(menuitems);
- for (int i = 0; i < menu->getCount(); ++i) {
- const SkOSMenu::Item* item = menuitems[i];
- SkOptionItem* option = [[SkOptionItem alloc] init];
- option.fItem = item;
-
- if (SkOSMenu::kList_Type == item->getType()) {
- int index = 0, count = 0;
- SkOSMenu::FindListItemCount(*item->getEvent(), &count);
- NSMutableArray* optionstrs = [[NSMutableArray alloc] initWithCapacity:count];
- std::unique_ptr<SkString[]> ada(new SkString[count]);
- SkString* options = ada.get();
- SkOSMenu::FindListItems(*item->getEvent(), options);
- for (int i = 0; i < count; ++i)
- [optionstrs addObject:[NSString stringWithUTF8String:options[i].c_str()]];
- SkOSMenu::FindListIndex(*item->getEvent(), item->getSlotName(), &index);
- option.fCell = [self createList:optionstrs current:index];
- [optionstrs release];
- }
- else {
- bool state = false;
- SkString str;
- SkOSMenu::TriState tristate;
- switch (item->getType()) {
- case SkOSMenu::kAction_Type:
- option.fCell = [self createAction];
- break;
- case SkOSMenu::kSlider_Type:
- SkScalar min, max, value;
- SkOSMenu::FindSliderValue(*item->getEvent(), item->getSlotName(), &value);
- SkOSMenu::FindSliderMin(*item->getEvent(), &min);
- SkOSMenu::FindSliderMax(*item->getEvent(), &max);
- option.fCell = [self createSlider:value
- min:min
- max:max];
- break;
- case SkOSMenu::kSwitch_Type:
- SkOSMenu::FindSwitchState(*item->getEvent(), item->getSlotName(), &state);
- option.fCell = [self createSwitch:(BOOL)state];
- break;
- case SkOSMenu::kTriState_Type:
- SkOSMenu::FindTriState(*item->getEvent(), item->getSlotName(), &tristate);
- option.fCell = [self createTriState:[self triStateToNSState:tristate]];
- break;
- case SkOSMenu::kTextField_Type:
- SkOSMenu::FindText(*item->getEvent(),item->getSlotName(), &str);
- option.fCell = [self createTextField:[NSString stringWithUTF8String:str.c_str()]];
- break;
- default:
- break;
- }
- }
- [fItems addObject:option];
- [option release];
- }
-}
-
-- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
- return [self.fItems count];
-}
-
-- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
- NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]];
- if (columnIndex == 0) {
- const SkOSMenu::Item* item = ((SkOptionItem*)[fItems objectAtIndex:row]).fItem;
- NSString* label = [NSString stringWithUTF8String:item->getLabel()];
- if (fShowKeys)
- return [NSString stringWithFormat:@"%@ (%c)", label, item->getKeyEquivalent()];
- else
- return label;
- }
- else
- return nil;
-}
-
-- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
- if (tableColumn) {
- NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]];
- if (columnIndex == 1)
- return [((SkOptionItem*)[fItems objectAtIndex:row]).fCell copy];
- else
- return [[[SkTextFieldCell alloc] init] autorelease];
- }
- return nil;
-}
-
-- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
- NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]];
- if (columnIndex == 1) {
- SkOptionItem* option = (SkOptionItem*)[self.fItems objectAtIndex:row];
- NSCell* storedCell = option.fCell;
- const SkOSMenu::Item* item = option.fItem;
- switch (item->getType()) {
- case SkOSMenu::kAction_Type:
- break;
- case SkOSMenu::kList_Type:
- [cell selectItemAtIndex:[(NSPopUpButtonCell*)storedCell indexOfSelectedItem]];
- break;
- case SkOSMenu::kSlider_Type:
- [cell setFloatValue:[storedCell floatValue]];
- break;
- case SkOSMenu::kSwitch_Type:
- [cell setState:[(NSButtonCell*)storedCell state]];
- break;
- case SkOSMenu::kTextField_Type:
- if ([[storedCell stringValue] length] > 0)
- [cell setStringValue:[storedCell stringValue]];
- break;
- case SkOSMenu::kTriState_Type:
- [cell setState:[(NSButtonCell*)storedCell state]];
- break;
- default:
- break;
- }
- }
- else {
- [(SkTextFieldCell*)cell setEditable:NO];
- }
-}
-
-- (void)tableView:(NSTableView *)tableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
- NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]];
- if (columnIndex == 1) {
- SkOptionItem* option = (SkOptionItem*)[self.fItems objectAtIndex:row];
- NSCell* cell = option.fCell;
- const SkOSMenu::Item* item = option.fItem;
- switch (item->getType()) {
- case SkOSMenu::kAction_Type:
- item->postEvent();
- break;
- case SkOSMenu::kList_Type:
- [(NSPopUpButtonCell*)cell selectItemAtIndex:[anObject intValue]];
- item->setInt([anObject intValue]);
- break;
- case SkOSMenu::kSlider_Type:
- [cell setFloatValue:[anObject floatValue]];
- item->setScalar([anObject floatValue]);
- break;
- case SkOSMenu::kSwitch_Type:
- [cell setState:[anObject boolValue]];
- item->setBool([anObject boolValue]);
- break;
- case SkOSMenu::kTextField_Type:
- if ([anObject length] > 0) {
- [cell setStringValue:anObject];
- item->setString([anObject UTF8String]);
- }
- break;
- case SkOSMenu::kTriState_Type:
- [cell setState:[anObject intValue]];
- item->setTriState((SkOSMenu::TriState)[anObject intValue]);
- break;
- default:
- break;
- }
- item->postEvent();
- }
-}
-
-- (NSCell*)createAction{
- NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease];
- [cell setTitle:@""];
- [cell setButtonType:NSMomentaryPushInButton];
- [cell setBezelStyle:NSSmallSquareBezelStyle];
- return cell;
-}
-
-- (NSCell*)createList:(NSArray*)items current:(int)index {
- NSPopUpButtonCell* cell = [[[NSPopUpButtonCell alloc] init] autorelease];
- [cell addItemsWithTitles:items];
- [cell selectItemAtIndex:index];
- [cell setArrowPosition:NSPopUpArrowAtBottom];
- [cell setBezelStyle:NSSmallSquareBezelStyle];
- return cell;
-}
-
-- (NSCell*)createSlider:(float)value min:(float)min max:(float)max {
- NSSliderCell* cell = [[[NSSliderCell alloc] init] autorelease];
- [cell setFloatValue:value];
- [cell setMinValue:min];
- [cell setMaxValue:max];
- return cell;
-}
-
-- (NSCell*)createSwitch:(BOOL)state {
- NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease];
- [cell setState:state];
- [cell setTitle:@""];
- [cell setButtonType:NSSwitchButton];
- return cell;
-}
-
-- (NSCell*)createTextField:(NSString*)placeHolder {
- SkTextFieldCell* cell = [[[SkTextFieldCell alloc] init] autorelease];
- [cell setEditable:YES];
- [cell setStringValue:@""];
- [cell setPlaceholderString:placeHolder];
- return cell;
-}
-
-- (NSCell*)createTriState:(NSCellStateValue)state {
- NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease];
- [cell setAllowsMixedState:TRUE];
- [cell setTitle:@""];
- [cell setState:(NSInteger)state];
- [cell setButtonType:NSSwitchButton];
- return cell;
-}
-@end
diff --git a/src/views/mac/SkTextFieldCell.h b/src/views/mac/SkTextFieldCell.h
deleted file mode 100644
index dfca7ae690..0000000000
--- a/src/views/mac/SkTextFieldCell.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#import <Cocoa/Cocoa.h>
-//A text field cell that has vertically centered text
-@interface SkTextFieldCell : NSTextFieldCell {
- BOOL selectingOrEditing;
-}
-@end
diff --git a/src/views/mac/SkTextFieldCell.m b/src/views/mac/SkTextFieldCell.m
deleted file mode 100644
index fbfed05f7f..0000000000
--- a/src/views/mac/SkTextFieldCell.m
+++ /dev/null
@@ -1,56 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#import "SkTextFieldCell.h"
-@implementation SkTextFieldCell
-- (NSRect)drawingRectForBounds:(NSRect)theRect {
- NSRect newRect = [super drawingRectForBounds:theRect];
- if (selectingOrEditing == NO) {
- NSSize textSize = [self cellSizeForBounds:theRect];
- float heightDelta = newRect.size.height - textSize.height;
- if (heightDelta > 0) {
- newRect.size.height -= heightDelta;
- newRect.origin.y += (heightDelta / 2);
- }
- }
- return newRect;
-}
-
-- (void)selectWithFrame:(NSRect)aRect
- inView:(NSView *)controlView
- editor:(NSText *)textObj
- delegate:(id)anObject
- start:(NSInteger)selStart
- length:(NSInteger)selLength {
- aRect = [self drawingRectForBounds:aRect];
- selectingOrEditing = YES;
- [super selectWithFrame:aRect
- inView:controlView
- editor:textObj
- delegate:anObject
- start:selStart
- length:selLength];
- selectingOrEditing = NO;
-}
-
-- (void)editWithFrame:(NSRect)aRect
- inView:(NSView *)controlView
- editor:(NSText *)textObj
- delegate:(id)anObject
- event:(NSEvent *)theEvent {
- aRect = [self drawingRectForBounds:aRect];
- selectingOrEditing = YES;
- [super editWithFrame:aRect
- inView:controlView
- editor:textObj
- delegate:anObject
- event:theEvent];
- selectingOrEditing = NO;
-}
-
-@end
diff --git a/src/views/mac/skia_mac.mm b/src/views/mac/skia_mac.mm
deleted file mode 100644
index b2c59516e0..0000000000
--- a/src/views/mac/skia_mac.mm
+++ /dev/null
@@ -1,126 +0,0 @@
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <crt_externs.h>
-#import <Cocoa/Cocoa.h>
-#include "SkApplication.h"
-#include "SkGraphics.h"
-#include "SkNSView.h"
-
-@interface MainView : SkNSView {
-}
-- (id)initWithFrame: (NSRect)frame ;
-- (void)dealloc;
-- (void)begin;
-@end
-
-@implementation MainView : SkNSView
-
-- (id)initWithFrame: (NSRect)frame {
- self = [super initWithFrame:frame];
- return self;
-}
-
-- (void)dealloc {
- delete self.fWind;
- [super dealloc];
-}
-
-- (void)begin {
- self.fWind = create_sk_window(self, *_NSGetArgc(), *_NSGetArgv());
- [self setUpWindow];
-}
-@end
-
-@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate> {
-}
-- (id)init;
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication;
-@end
-
-#
-@implementation AppDelegate : NSObject
-- (id)init {
- self = [super init];
- return self;
-}
-
-- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
- return TRUE;
-}
-@end
-
-int main(int argc, char *argv[]) {
- SkGraphics::Init();
- signal(SIGPIPE, SIG_IGN);
- NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
-
- NSApplication* app = [NSApplication sharedApplication];
-
- NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask);
-
- NSRect windowRect = NSMakeRect(100, 100, 1000, 1000);
- NSWindow* window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO];
-
- NSRect rect = [NSWindow contentRectForFrameRect:windowRect styleMask:windowStyle];
- MainView* customView = [[MainView alloc] initWithFrame:rect];
- [customView setTranslatesAutoresizingMaskIntoConstraints:NO];
- NSView* contentView = window.contentView;
- [contentView addSubview:customView];
- NSDictionary *views = NSDictionaryOfVariableBindings(customView);
-
- [contentView addConstraints:
- [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[customView]|"
- options:0
- metrics:nil
- views:views]];
-
- [contentView addConstraints:
- [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[customView]|"
- options:0
- metrics:nil
- views:views]];
-
- [customView begin];
- [customView release];
-
- [window makeKeyAndOrderFront:NSApp];
-
- AppDelegate * appDelegate = [[[AppDelegate alloc] init] autorelease];
-
- app.delegate = appDelegate;
-
- NSMenu* menu=[[NSMenu alloc] initWithTitle:@"AMainMenu"];
- NSMenuItem* item;
- NSMenu* subMenu;
-
- //Create the application menu.
- item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""];
- [menu addItem:item];
- subMenu=[[NSMenu alloc] initWithTitle:@"Apple"];
- [menu setSubmenu:subMenu forItem:item];
- [item release];
- item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
- [subMenu addItem:item];
- [item release];
- [subMenu release];
-
- //Add the menu to the app.
- [app setMenu:menu];
-
- [app setActivationPolicy:NSApplicationActivationPolicyRegular];
-
- [app run];
-
- [menu release];
- [appDelegate release];
- [window release];
- [pool release];
-
- return EXIT_SUCCESS;
-}
diff --git a/src/views/unix/SkOSWindow_Unix.cpp b/src/views/unix/SkOSWindow_Unix.cpp
deleted file mode 100644
index dcdfd06008..0000000000
--- a/src/views/unix/SkOSWindow_Unix.cpp
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/XKBlib.h>
-#include <GL/glx.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
-
-#include "SkWindow.h"
-
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkColor.h"
-#include "SkEvent.h"
-#include "SkKey.h"
-#include "SkWindow.h"
-#include "XkeysToSkKeys.h"
-extern "C" {
- #include "keysym2ucs.h"
-}
-
-const int WIDTH = 1024;
-const int HEIGHT = 768;
-
-// Determine which events to listen for.
-const long EVENT_MASK = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask
- |ExposureMask|PointerMotionMask|KeyPressMask|KeyReleaseMask;
-
-void SkOSWindow::init(int w, int h) {
- fUnixWindow.fDisplay = nullptr;
- fUnixWindow.fGLContext = nullptr;
- this->initWindow(0, nullptr, w, h);
- this->resize(w, h);
-}
-
-SkOSWindow::SkOSWindow(void*)
- : fVi(nullptr)
- , fMSAASampleCount(0) {
- this->init(WIDTH, HEIGHT);
-}
-
-SkOSWindow::SkOSWindow(void*, int width, int height)
- : fVi(nullptr)
- , fMSAASampleCount(0) {
- this->init(width, height);
-}
-
-SkOSWindow::~SkOSWindow() {
- this->internalCloseWindow();
-}
-
-void SkOSWindow::internalCloseWindow() {
- if (fUnixWindow.fDisplay) {
- this->release();
- SkASSERT(fUnixWindow.fGc);
- XFreeGC(fUnixWindow.fDisplay, fUnixWindow.fGc);
- fUnixWindow.fGc = nullptr;
- XDestroyWindow(fUnixWindow.fDisplay, fUnixWindow.fWin);
- fVi = nullptr;
- XCloseDisplay(fUnixWindow.fDisplay);
- fUnixWindow.fDisplay = nullptr;
- fMSAASampleCount = 0;
- }
-}
-
-void SkOSWindow::initWindow(int requestedMSAASampleCount, AttachmentInfo* info, int w, int h) {
- if (fMSAASampleCount != requestedMSAASampleCount) {
- this->internalCloseWindow();
- }
- // presence of fDisplay means we already have a window
- if (fUnixWindow.fDisplay) {
- if (info) {
- if (fVi) {
- glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_SAMPLES_ARB, &info->fSampleCount);
- glXGetConfig(fUnixWindow.fDisplay, fVi, GLX_STENCIL_SIZE, &info->fStencilBits);
- } else {
- info->fSampleCount = 0;
- info->fStencilBits = 0;
- }
- }
- return;
- }
- fUnixWindow.fDisplay = XOpenDisplay(nullptr);
- Display* dsp = fUnixWindow.fDisplay;
- if (nullptr == dsp) {
- SkDebugf("Could not open an X Display");
- return;
- }
- // Attempt to create a window that supports GL
- GLint att[] = {
- GLX_RGBA,
- GLX_DEPTH_SIZE, 24,
- GLX_DOUBLEBUFFER,
- GLX_STENCIL_SIZE, 8,
- None
- };
- SkASSERT(nullptr == fVi);
- if (requestedMSAASampleCount > 0) {
- static const GLint kAttCount = SK_ARRAY_COUNT(att);
- GLint msaaAtt[kAttCount + 4];
- memcpy(msaaAtt, att, sizeof(att));
- SkASSERT(None == msaaAtt[kAttCount - 1]);
- msaaAtt[kAttCount - 1] = GLX_SAMPLE_BUFFERS_ARB;
- msaaAtt[kAttCount + 0] = 1;
- msaaAtt[kAttCount + 1] = GLX_SAMPLES_ARB;
- msaaAtt[kAttCount + 2] = requestedMSAASampleCount;
- msaaAtt[kAttCount + 3] = None;
- fVi = glXChooseVisual(dsp, DefaultScreen(dsp), msaaAtt);
- fMSAASampleCount = requestedMSAASampleCount;
- }
- if (nullptr == fVi) {
- fVi = glXChooseVisual(dsp, DefaultScreen(dsp), att);
- fMSAASampleCount = 0;
- }
-
- if (fVi) {
- if (info) {
- glXGetConfig(dsp, fVi, GLX_SAMPLES_ARB, &info->fSampleCount);
- glXGetConfig(dsp, fVi, GLX_STENCIL_SIZE, &info->fStencilBits);
- }
- Colormap colorMap = XCreateColormap(dsp,
- RootWindow(dsp, fVi->screen),
- fVi->visual,
- AllocNone);
- XSetWindowAttributes swa;
- swa.colormap = colorMap;
- swa.event_mask = EVENT_MASK;
- fUnixWindow.fWin = XCreateWindow(dsp,
- RootWindow(dsp, fVi->screen),
- 0, 0, // x, y
- w, h,
- 0, // border width
- fVi->depth,
- InputOutput,
- fVi->visual,
- CWEventMask | CWColormap,
- &swa);
- } else {
- if (info) {
- info->fSampleCount = 0;
- info->fStencilBits = 0;
- }
- // Create a simple window instead. We will not be able to show GL
- fUnixWindow.fWin = XCreateSimpleWindow(dsp,
- DefaultRootWindow(dsp),
- 0, 0, // x, y
- w, h,
- 0, // border width
- 0, // border value
- 0); // background value
- }
- this->mapWindowAndWait();
- fUnixWindow.fGc = XCreateGC(dsp, fUnixWindow.fWin, 0, nullptr);
-}
-
-static unsigned getModi(const XEvent& evt) {
- static const struct {
- unsigned fXMask;
- unsigned fSkMask;
- } gModi[] = {
- // X values found by experiment. Is there a better way?
- { 1, kShift_SkModifierKey },
- { 4, kControl_SkModifierKey },
- { 8, kOption_SkModifierKey },
- };
-
- unsigned modi = 0;
- for (size_t i = 0; i < SK_ARRAY_COUNT(gModi); ++i) {
- if (evt.xkey.state & gModi[i].fXMask) {
- modi |= gModi[i].fSkMask;
- }
- }
- return modi;
-}
-
-static SkMSec gTimerDelay;
-
-static bool MyXNextEventWithDelay(Display* dsp, XEvent* evt) {
- // Check for pending events before entering the select loop. There might
- // be events in the in-memory queue but not processed yet.
- if (XPending(dsp)) {
- XNextEvent(dsp, evt);
- return true;
- }
-
- SkMSec ms = gTimerDelay;
- if (ms > 0) {
- int x11_fd = ConnectionNumber(dsp);
- fd_set input_fds;
- FD_ZERO(&input_fds);
- FD_SET(x11_fd, &input_fds);
-
- timeval tv;
- tv.tv_sec = ms / 1000; // seconds
- tv.tv_usec = (ms % 1000) * 1000; // microseconds
-
- if (!select(x11_fd + 1, &input_fds, nullptr, nullptr, &tv)) {
- if (!XPending(dsp)) {
- return false;
- }
- }
- }
- XNextEvent(dsp, evt);
- return true;
-}
-
-static Atom wm_delete_window_message;
-
-SkOSWindow::NextXEventResult SkOSWindow::nextXEvent() {
- XEvent evt;
- Display* dsp = fUnixWindow.fDisplay;
-
- if (!MyXNextEventWithDelay(dsp, &evt)) {
- return kContinue_NextXEventResult;
- }
-
- switch (evt.type) {
- case Expose:
- if (0 == evt.xexpose.count) {
- return kPaintRequest_NextXEventResult;
- }
- break;
- case ConfigureNotify:
- this->resize(evt.xconfigure.width, evt.xconfigure.height);
- break;
- case ButtonPress:
- if (evt.xbutton.button == Button1)
- this->handleClick(evt.xbutton.x, evt.xbutton.y,
- SkView::Click::kDown_State, nullptr, getModi(evt));
- break;
- case ButtonRelease:
- if (evt.xbutton.button == Button1)
- this->handleClick(evt.xbutton.x, evt.xbutton.y,
- SkView::Click::kUp_State, nullptr, getModi(evt));
- break;
- case MotionNotify:
- this->handleClick(evt.xmotion.x, evt.xmotion.y,
- SkView::Click::kMoved_State, nullptr, getModi(evt));
- break;
- case KeyPress: {
- int shiftLevel = (evt.xkey.state & ShiftMask) ? 1 : 0;
- KeySym keysym = XkbKeycodeToKeysym(dsp, evt.xkey.keycode,
- 0, shiftLevel);
- if (keysym == XK_Escape) {
- return kQuitRequest_NextXEventResult;
- }
- this->handleKey(XKeyToSkKey(keysym));
- long uni = keysym2ucs(keysym);
- if (uni != -1) {
- this->handleChar((SkUnichar) uni);
- }
- break;
- }
- case KeyRelease:
- this->handleKeyUp(XKeyToSkKey(XkbKeycodeToKeysym(dsp, evt.xkey.keycode, 0, 0)));
- break;
- case ClientMessage:
- if ((Atom)evt.xclient.data.l[0] == wm_delete_window_message) {
- return kQuitRequest_NextXEventResult;
- }
- // fallthrough
- default:
- // Do nothing for other events
- break;
- }
- return kContinue_NextXEventResult;
-}
-
-void SkOSWindow::loop() {
- Display* dsp = fUnixWindow.fDisplay;
- if (nullptr == dsp) {
- return;
- }
- Window win = fUnixWindow.fWin;
-
- wm_delete_window_message = XInternAtom(dsp, "WM_DELETE_WINDOW", False);
- XSetWMProtocols(dsp, win, &wm_delete_window_message, 1);
-
- XSelectInput(dsp, win, EVENT_MASK);
-
- bool sentExposeEvent = false;
-
- for (;;) {
- SkEvent::ServiceQueueTimer();
-
- bool moreToDo = SkEvent::ProcessEvent();
-
- if (this->isDirty() && !sentExposeEvent) {
- sentExposeEvent = true;
-
- XEvent evt;
- sk_bzero(&evt, sizeof(evt));
- evt.type = Expose;
- evt.xexpose.display = dsp;
- XSendEvent(dsp, win, false, ExposureMask, &evt);
- }
-
- if (XPending(dsp) || !moreToDo) {
- switch (this->nextXEvent()) {
- case kContinue_NextXEventResult:
- break;
- case kPaintRequest_NextXEventResult:
- sentExposeEvent = false;
- if (this->isDirty()) {
- this->update(nullptr);
- }
- this->doPaint();
- break;
- case kQuitRequest_NextXEventResult:
- return;
- }
- }
- }
-}
-
-void SkOSWindow::mapWindowAndWait() {
- SkASSERT(fUnixWindow.fDisplay);
- Display* dsp = fUnixWindow.fDisplay;
- Window win = fUnixWindow.fWin;
- XMapWindow(dsp, win);
-
- long eventMask = StructureNotifyMask;
- XSelectInput(dsp, win, eventMask);
-
- // Wait until screen is ready.
- XEvent evt;
- do {
- XNextEvent(dsp, &evt);
- } while(evt.type != MapNotify);
-
-}
-
-////////////////////////////////////////////////
-
-// Some helper code to load the correct version of glXSwapInterval
-#define GLX_GET_PROC_ADDR(name) glXGetProcAddress(reinterpret_cast<const GLubyte*>((name)))
-#define EXT_WRANGLE(name, type, ...) \
- if (GLX_GET_PROC_ADDR(#name)) { \
- static type k##name; \
- if (!k##name) { \
- k##name = (type) GLX_GET_PROC_ADDR(#name); \
- } \
- k##name(__VA_ARGS__); \
- /*SkDebugf("using %s\n", #name);*/ \
- return; \
- }
-
-static void glXSwapInterval(Display* dsp, GLXDrawable drawable, int interval) {
- EXT_WRANGLE(glXSwapIntervalEXT, PFNGLXSWAPINTERVALEXTPROC, dsp, drawable, interval);
- EXT_WRANGLE(glXSwapIntervalMESA, PFNGLXSWAPINTERVALMESAPROC, interval);
- EXT_WRANGLE(glXSwapIntervalSGI, PFNGLXSWAPINTERVALSGIPROC, interval);
-}
-
-/////////////////////////////////////////////////////////////////////////
-
-bool SkOSWindow::attach(SkBackEndTypes, int msaaSampleCount, bool deepColor,
- AttachmentInfo* info) {
- this->initWindow(msaaSampleCount, info, WIDTH, HEIGHT);
-
- if (nullptr == fUnixWindow.fDisplay) {
- return false;
- }
- if (nullptr == fUnixWindow.fGLContext) {
- SkASSERT(fVi);
-
- fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay,
- fVi,
- nullptr,
- GL_TRUE);
- if (nullptr == fUnixWindow.fGLContext) {
- return false;
- }
- }
- glXMakeCurrent(fUnixWindow.fDisplay,
- fUnixWindow.fWin,
- fUnixWindow.fGLContext);
- glViewport(0, 0,
- SkScalarRoundToInt(this->width()),
- SkScalarRoundToInt(this->height()));
- glClearColor(0, 0, 0, 0);
- glClearStencil(0);
- glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- return true;
-}
-
-void SkOSWindow::release() {
- if (nullptr == fUnixWindow.fDisplay || nullptr == fUnixWindow.fGLContext) {
- return;
- }
- glXMakeCurrent(fUnixWindow.fDisplay, None, nullptr);
- glXDestroyContext(fUnixWindow.fDisplay, fUnixWindow.fGLContext);
- fUnixWindow.fGLContext = nullptr;
-}
-
-void SkOSWindow::present() {
- if (fUnixWindow.fDisplay && fUnixWindow.fGLContext) {
- glXSwapBuffers(fUnixWindow.fDisplay, fUnixWindow.fWin);
- }
-}
-
-void SkOSWindow::onSetTitle(const char title[]) {
- if (nullptr == fUnixWindow.fDisplay) {
- return;
- }
- XTextProperty textProp;
- textProp.value = (unsigned char*)title;
- textProp.format = 8;
- textProp.nitems = strlen((char*)textProp.value);
- textProp.encoding = XA_STRING;
- XSetWMName(fUnixWindow.fDisplay, fUnixWindow.fWin, &textProp);
-}
-
-static bool convertBitmapToXImage(XImage& image, const SkBitmap& bitmap) {
- sk_bzero(&image, sizeof(image));
-
- int bitsPerPixel = bitmap.bytesPerPixel() * 8;
- image.width = bitmap.width();
- image.height = bitmap.height();
- image.format = ZPixmap;
- image.data = (char*) bitmap.getPixels();
- image.byte_order = LSBFirst;
- image.bitmap_unit = bitsPerPixel;
- image.bitmap_bit_order = LSBFirst;
- image.bitmap_pad = bitsPerPixel;
- image.depth = 24;
- image.bytes_per_line = bitmap.rowBytes() - bitmap.width() * 4;
- image.bits_per_pixel = bitsPerPixel;
- return XInitImage(&image);
-}
-
-void SkOSWindow::doPaint() {
- if (nullptr == fUnixWindow.fDisplay) {
- return;
- }
- // If we are drawing with GL, we don't need XPutImage.
- if (fUnixWindow.fGLContext) {
- return;
- }
- // Draw the bitmap to the screen.
- const SkBitmap& bitmap = getBitmap();
- int width = bitmap.width();
- int height = bitmap.height();
-
- XImage image;
- if (!convertBitmapToXImage(image, bitmap)) {
- return;
- }
-
- XPutImage(fUnixWindow.fDisplay,
- fUnixWindow.fWin,
- fUnixWindow.fGc,
- &image,
- 0, 0, // src x,y
- 0, 0, // dst x,y
- width, height);
-}
-
-enum {
- _NET_WM_STATE_REMOVE =0,
- _NET_WM_STATE_ADD = 1,
- _NET_WM_STATE_TOGGLE =2
-};
-
-bool SkOSWindow::makeFullscreen() {
- Display* dsp = fUnixWindow.fDisplay;
- if (nullptr == dsp) {
- return false;
- }
-
- // Full screen
- Atom wm_state = XInternAtom(dsp, "_NET_WM_STATE", False);
- Atom fullscreen = XInternAtom(dsp, "_NET_WM_STATE_FULLSCREEN", False);
-
- XEvent evt;
- sk_bzero(&evt, sizeof(evt));
- evt.type = ClientMessage;
- evt.xclient.window = fUnixWindow.fWin;
- evt.xclient.message_type = wm_state;
- evt.xclient.format = 32;
- evt.xclient.data.l[0] = _NET_WM_STATE_ADD;
- evt.xclient.data.l[1] = fullscreen;
- evt.xclient.data.l[2] = 0;
-
- XSendEvent(dsp, DefaultRootWindow(dsp), False,
- SubstructureRedirectMask | SubstructureNotifyMask, &evt);
- return true;
-}
-
-void SkOSWindow::setVsync(bool vsync) {
- if (fUnixWindow.fDisplay && fUnixWindow.fGLContext && fUnixWindow.fWin) {
- int swapInterval = vsync ? 1 : 0;
- glXSwapInterval(fUnixWindow.fDisplay, fUnixWindow.fWin, swapInterval);
- }
-}
-
-void SkOSWindow::closeWindow() {
- Display* dsp = fUnixWindow.fDisplay;
- if (nullptr == dsp) {
- return;
- }
-
- XEvent evt;
- sk_bzero(&evt, sizeof(evt));
- evt.type = ClientMessage;
- evt.xclient.message_type = XInternAtom(dsp, "WM_PROTOCOLS", true);
- evt.xclient.window = fUnixWindow.fWin;
- evt.xclient.format = 32;
- evt.xclient.data.l[0] = XInternAtom(dsp, "WM_DELETE_WINDOW", false);
- evt.xclient.data.l[1] = CurrentTime;
-
- XSendEvent(dsp, fUnixWindow.fWin, false, NoEventMask, &evt);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-void SkEvent::SignalNonEmptyQueue() {
- // nothing to do, since we spin on our event-queue, polling for XPending
-}
-
-void SkEvent::SignalQueueTimer(SkMSec delay) {
- // just need to record the delay time. We handle waking up for it in
- // MyXNextEventWithDelay()
- gTimerDelay = delay;
-}
diff --git a/src/views/unix/XkeysToSkKeys.h b/src/views/unix/XkeysToSkKeys.h
deleted file mode 100644
index aced74c0af..0000000000
--- a/src/views/unix/XkeysToSkKeys.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "X11/Xlib.h"
-#include "X11/keysym.h"
-
-#include "SkKey.h"
-
-#ifndef XKEYS_TOSKKEYS_H
-#define XKEYS_TOSKKEYS_H
-
-SkKey XKeyToSkKey(KeySym keysym) {
- switch (keysym) {
- case XK_BackSpace:
- return kBack_SkKey;
- case XK_Return:
- return kOK_SkKey;
- case XK_Home:
- return kHome_SkKey;
- case XK_End:
- return kEnd_SkKey;
- case XK_Right:
- return kRight_SkKey;
- case XK_Left:
- return kLeft_SkKey;
- case XK_Down:
- return kDown_SkKey;
- case XK_Up:
- return kUp_SkKey;
- case XK_KP_0:
- case XK_KP_Insert:
- return k0_SkKey;
- case XK_KP_1:
- case XK_KP_End:
- return k1_SkKey;
- case XK_KP_2:
- case XK_KP_Down:
- return k2_SkKey;
- case XK_KP_3:
- case XK_KP_Page_Down:
- return k3_SkKey;
- case XK_KP_4:
- case XK_KP_Left:
- return k4_SkKey;
- case XK_KP_5:
- return k5_SkKey;
- case XK_KP_6:
- case XK_KP_Right:
- return k6_SkKey;
- case XK_KP_7:
- case XK_KP_Home:
- return k7_SkKey;
- case XK_KP_8:
- case XK_KP_Up:
- return k8_SkKey;
- case XK_KP_9:
- case XK_KP_Page_Up:
- return k9_SkKey;
- default:
- return kNONE_SkKey;
- }
-}
-#endif
diff --git a/src/views/unix/skia_unix.cpp b/src/views/unix/skia_unix.cpp
deleted file mode 100644
index 9f99059625..0000000000
--- a/src/views/unix/skia_unix.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkApplication.h"
-#include "SkEvent.h"
-#include "SkGraphics.h"
-#include "SkWindow.h"
-
-int main(int argc, char** argv){
- SkGraphics::Init();
- SkOSWindow* window = create_sk_window(nullptr, argc, argv);
-
- // drain any events that occurred before |window| was assigned.
- while (SkEvent::ProcessEvent());
-
- // Start normal Skia sequence
- application_init();
-
- window->loop();
-
- delete window;
- application_term();
- return 0;
-}
diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp
deleted file mode 100644
index 8788b10ef4..0000000000
--- a/src/views/win/SkOSWindow_win.cpp
+++ /dev/null
@@ -1,726 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkTypes.h"
-
-#if defined(SK_BUILD_FOR_WIN)
-
-#include "SkLeanWindows.h"
-
-#include <GL/gl.h>
-#include <WindowsX.h>
-#include "win/SkWGL.h"
-#include "SkWindow.h"
-#include "SkCanvas.h"
-#include "SkOSMenu.h"
-#include "SkTime.h"
-#include "SkUtils.h"
-
-#include "SkGraphics.h"
-
-#if SK_ANGLE
-#include "gl/GrGLAssembleInterface.h"
-#include "gl/GrGLInterface.h"
-#include "GLES2/gl2.h"
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-#endif // SK_ANGLE
-
-const int kDefaultWindowWidth = 1024;
-const int kDefaultWindowHeight = 768;
-
-#define GL_CALL(IFACE, X) \
- SkASSERT(IFACE); \
- do { \
- (IFACE)->fFunctions.f##X; \
- } while (false)
-
-#define WM_EVENT_CALLBACK (WM_USER+0)
-
-void post_skwinevent(HWND hwnd)
-{
- PostMessage(hwnd, WM_EVENT_CALLBACK, 0, 0);
-}
-
-SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap;
-
-SkOSWindow::SkOSWindow(const void* winInit) {
- this->init(winInit, kDefaultWindowWidth, kDefaultWindowHeight);
-}
-
-SkOSWindow::SkOSWindow(const void* winInit, int w, int h) {
- this->init(winInit, w, h);
-}
-
-void SkOSWindow::init(const void* winInit, int w, int h) {
- fWinInit = *(const WindowInit*)winInit;
-
- fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, w, h, NULL, NULL,
- fWinInit.fInstance, NULL);
- gHwndToOSWindowMap.set(fHWND, this);
-#if SK_SUPPORT_GPU
-#if SK_ANGLE
- fDisplay = EGL_NO_DISPLAY;
- fContext = EGL_NO_CONTEXT;
- fSurface = EGL_NO_SURFACE;
-#endif
-
- fHGLRC = NULL;
-#endif
- fAttached = kNone_BackEndType;
- fFullscreen = false;
-}
-
-SkOSWindow::~SkOSWindow() {
-#if SK_SUPPORT_GPU
- if (fHGLRC) {
- wglDeleteContext((HGLRC)fHGLRC);
- }
-#if SK_ANGLE
- if (EGL_NO_CONTEXT != fContext) {
- eglDestroyContext(fDisplay, fContext);
- fContext = EGL_NO_CONTEXT;
- }
-
- if (EGL_NO_SURFACE != fSurface) {
- eglDestroySurface(fDisplay, fSurface);
- fSurface = EGL_NO_SURFACE;
- }
-
- if (EGL_NO_DISPLAY != fDisplay) {
- eglTerminate(fDisplay);
- fDisplay = EGL_NO_DISPLAY;
- }
-#endif // SK_ANGLE
-#endif // SK_SUPPORT_GPU
- this->closeWindow();
-}
-
-static SkKey winToskKey(WPARAM vk) {
- static const struct {
- WPARAM fVK;
- SkKey fKey;
- } gPair[] = {
- { VK_BACK, kBack_SkKey },
- { VK_CLEAR, kBack_SkKey },
- { VK_RETURN, kOK_SkKey },
- { VK_UP, kUp_SkKey },
- { VK_DOWN, kDown_SkKey },
- { VK_LEFT, kLeft_SkKey },
- { VK_RIGHT, kRight_SkKey }
- };
- for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
- if (gPair[i].fVK == vk) {
- return gPair[i].fKey;
- }
- }
- return kNONE_SkKey;
-}
-
-static unsigned getModifiers(UINT message) {
- return 0; // TODO
-}
-
-bool SkOSWindow::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- switch (message) {
- case WM_KEYDOWN: {
- SkKey key = winToskKey(wParam);
- if (kNONE_SkKey != key) {
- this->handleKey(key);
- return true;
- }
- } break;
- case WM_KEYUP: {
- SkKey key = winToskKey(wParam);
- if (kNONE_SkKey != key) {
- this->handleKeyUp(key);
- return true;
- }
- } break;
- case WM_UNICHAR:
- this->handleChar((SkUnichar) wParam);
- return true;
- case WM_CHAR: {
- const uint16_t* c = reinterpret_cast<uint16_t*>(&wParam);
- this->handleChar(SkUTF16_NextUnichar(&c));
- return true;
- } break;
- case WM_SIZE: {
- INT width = LOWORD(lParam);
- INT height = HIWORD(lParam);
- this->resize(width, height);
- break;
- }
- case WM_PAINT: {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hWnd, &ps);
- this->doPaint(hdc);
- EndPaint(hWnd, &ps);
- return true;
- } break;
-
- case WM_LBUTTONDOWN:
- this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
- Click::kDown_State, NULL, getModifiers(message));
- return true;
-
- case WM_MOUSEMOVE:
- this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
- Click::kMoved_State, NULL, getModifiers(message));
- return true;
-
- case WM_LBUTTONUP:
- this->handleClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
- Click::kUp_State, NULL, getModifiers(message));
- return true;
-
- case WM_EVENT_CALLBACK:
- if (SkEvent::ProcessEvent()) {
- post_skwinevent(hWnd);
- }
- return true;
- }
- return false;
-}
-
-void SkOSWindow::doPaint(void* ctx) {
- this->update(NULL);
-
- if (kNone_BackEndType == fAttached)
- {
- HDC hdc = (HDC)ctx;
- const SkBitmap& bitmap = this->getBitmap();
-
- BITMAPINFO bmi;
- memset(&bmi, 0, sizeof(bmi));
- bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = bitmap.width();
- bmi.bmiHeader.biHeight = -bitmap.height(); // top-down image
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 32;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = 0;
-
- //
- // Do the SetDIBitsToDevice.
- //
- // TODO(wjmaclean):
- // Fix this call to handle SkBitmaps that have rowBytes != width,
- // i.e. may have padding at the end of lines. The SkASSERT below
- // may be ignored by builds, and the only obviously safe option
- // seems to be to copy the bitmap to a temporary (contiguous)
- // buffer before passing to SetDIBitsToDevice().
- SkASSERT(bitmap.width() * bitmap.bytesPerPixel() == bitmap.rowBytes());
- int ret = SetDIBitsToDevice(hdc,
- 0, 0,
- bitmap.width(), bitmap.height(),
- 0, 0,
- 0, bitmap.height(),
- bitmap.getPixels(),
- &bmi,
- DIB_RGB_COLORS);
- (void)ret; // we're ignoring potential failures for now.
- }
-}
-
-void SkOSWindow::updateSize()
-{
- RECT r;
- GetWindowRect((HWND)fHWND, &r);
- this->resize(r.right - r.left, r.bottom - r.top);
-}
-
-void SkOSWindow::onHandleInval(const SkIRect& r) {
- RECT rect;
- rect.left = r.fLeft;
- rect.top = r.fTop;
- rect.right = r.fRight;
- rect.bottom = r.fBottom;
- InvalidateRect((HWND)fHWND, &rect, FALSE);
-}
-
-void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu)
-{
-}
-
-void SkOSWindow::onSetTitle(const char title[]){
- SetWindowTextA((HWND)fHWND, title);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////
-
-void SkEvent::SignalNonEmptyQueue()
-{
- SkOSWindow::ForAllWindows([](void* hWND, SkOSWindow**) {
- post_skwinevent((HWND)hWND);
- });
-}
-
-static UINT_PTR gTimer;
-
-VOID CALLBACK sk_timer_proc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
-{
- SkEvent::ServiceQueueTimer();
- //SkDebugf("timer task fired\n");
-}
-
-void SkEvent::SignalQueueTimer(SkMSec delay)
-{
- if (gTimer)
- {
- KillTimer(NULL, gTimer);
- gTimer = NULL;
- }
- if (delay)
- {
- gTimer = SetTimer(NULL, 0, delay, sk_timer_proc);
- //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer);
- }
-}
-
-#if SK_SUPPORT_GPU
-
-bool SkOSWindow::attachGL(int msaaSampleCount, bool deepColor, AttachmentInfo* info) {
- HDC dc = GetDC((HWND)fHWND);
- if (NULL == fHGLRC) {
- fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, deepColor,
- kGLPreferCompatibilityProfile_SkWGLContextRequest);
- if (NULL == fHGLRC) {
- return false;
- }
- glClearStencil(0);
- glClearColor(0, 0, 0, 0);
- glStencilMask(0xffffffff);
- glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
- }
- if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) {
- // use DescribePixelFormat to get the stencil and color bit depth.
- int pixelFormat = GetPixelFormat(dc);
- PIXELFORMATDESCRIPTOR pfd;
- DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd);
- info->fStencilBits = pfd.cStencilBits;
- // pfd.cColorBits includes alpha, so it will be 32 in 8/8/8/8 and 10/10/10/2
- info->fColorBits = pfd.cRedBits + pfd.cGreenBits + pfd.cBlueBits;
-
- // Get sample count if the MSAA WGL extension is present
- SkWGLExtensions extensions;
- if (extensions.hasExtension(dc, "WGL_ARB_multisample")) {
- static const int kSampleCountAttr = SK_WGL_SAMPLES;
- extensions.getPixelFormatAttribiv(dc,
- pixelFormat,
- 0,
- 1,
- &kSampleCountAttr,
- &info->fSampleCount);
- } else {
- info->fSampleCount = 0;
- }
-
- glViewport(0, 0,
- SkScalarRoundToInt(this->width()),
- SkScalarRoundToInt(this->height()));
- return true;
- }
- return false;
-}
-
-void SkOSWindow::detachGL() {
- wglMakeCurrent(GetDC((HWND)fHWND), 0);
- wglDeleteContext((HGLRC)fHGLRC);
- fHGLRC = NULL;
-}
-
-void SkOSWindow::presentGL() {
- HDC dc = GetDC((HWND)fHWND);
- SwapBuffers(dc);
- ReleaseDC((HWND)fHWND, dc);
-}
-
-#if SK_ANGLE
-
-static void* get_angle_egl_display(void* nativeDisplay) {
- PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
- eglGetPlatformDisplayEXT =
- (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
-
- // We expect ANGLE to support this extension
- if (!eglGetPlatformDisplayEXT) {
- return EGL_NO_DISPLAY;
- }
-
- EGLDisplay display = EGL_NO_DISPLAY;
- // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL.
- EGLint attribs[3][3] = {
- {
- EGL_PLATFORM_ANGLE_TYPE_ANGLE,
- EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
- EGL_NONE
- },
- {
- EGL_PLATFORM_ANGLE_TYPE_ANGLE,
- EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
- EGL_NONE
- },
- };
- for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) {
- display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDisplay, attribs[i]);
- }
- return display;
-}
-
-struct ANGLEAssembleContext {
- ANGLEAssembleContext() {
- fEGL = GetModuleHandle("libEGL.dll");
- fGL = GetModuleHandle("libGLESv2.dll");
- }
-
- bool isValid() const { return SkToBool(fEGL) && SkToBool(fGL); }
-
- HMODULE fEGL;
- HMODULE fGL;
-};
-
-static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
- const ANGLEAssembleContext& context = *reinterpret_cast<const ANGLEAssembleContext*>(ctx);
- GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress(context.fGL, name);
- if (proc) {
- return proc;
- }
- proc = (GrGLFuncPtr) GetProcAddress(context.fEGL, name);
- if (proc) {
- return proc;
- }
- return eglGetProcAddress(name);
-}
-
-static const GrGLInterface* get_angle_gl_interface() {
- ANGLEAssembleContext context;
- if (!context.isValid()) {
- return nullptr;
- }
- return GrGLAssembleGLESInterface(&context, angle_get_gl_proc);
-}
-
-bool create_ANGLE(EGLNativeWindowType hWnd,
- int msaaSampleCount,
- EGLDisplay* eglDisplay,
- EGLContext* eglContext,
- EGLSurface* eglSurface,
- EGLConfig* eglConfig) {
- static const EGLint contextAttribs[] = {
- EGL_CONTEXT_CLIENT_VERSION, 2,
- EGL_NONE, EGL_NONE
- };
- static const EGLint configAttribList[] = {
- EGL_RED_SIZE, 8,
- EGL_GREEN_SIZE, 8,
- EGL_BLUE_SIZE, 8,
- EGL_ALPHA_SIZE, 8,
- EGL_DEPTH_SIZE, 8,
- EGL_STENCIL_SIZE, 8,
- EGL_NONE
- };
- static const EGLint surfaceAttribList[] = {
- EGL_NONE, EGL_NONE
- };
-
- EGLDisplay display = get_angle_egl_display(GetDC(hWnd));
-
- if (EGL_NO_DISPLAY == display) {
- SkDebugf("Could not create ANGLE egl display!\n");
- return false;
- }
-
- // Initialize EGL
- EGLint majorVersion, minorVersion;
- if (!eglInitialize(display, &majorVersion, &minorVersion)) {
- return false;
- }
-
- EGLint numConfigs;
- if (!eglGetConfigs(display, NULL, 0, &numConfigs)) {
- return false;
- }
-
- // Choose config
- bool foundConfig = false;
- if (msaaSampleCount) {
- static const int kConfigAttribListCnt =
- SK_ARRAY_COUNT(configAttribList);
- EGLint msaaConfigAttribList[kConfigAttribListCnt + 4];
- memcpy(msaaConfigAttribList,
- configAttribList,
- sizeof(configAttribList));
- SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]);
- msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS;
- msaaConfigAttribList[kConfigAttribListCnt + 0] = 1;
- msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES;
- msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount;
- msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE;
- if (eglChooseConfig(display, msaaConfigAttribList, eglConfig, 1, &numConfigs)) {
- SkASSERT(numConfigs > 0);
- foundConfig = true;
- }
- }
- if (!foundConfig) {
- if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs)) {
- return false;
- }
- }
-
- // Create a surface
- EGLSurface surface = eglCreateWindowSurface(display, *eglConfig,
- (EGLNativeWindowType)hWnd,
- surfaceAttribList);
- if (surface == EGL_NO_SURFACE) {
- return false;
- }
-
- // Create a GL context
- EGLContext context = eglCreateContext(display, *eglConfig,
- EGL_NO_CONTEXT,
- contextAttribs );
- if (context == EGL_NO_CONTEXT ) {
- return false;
- }
-
- // Make the context current
- if (!eglMakeCurrent(display, surface, surface, context)) {
- return false;
- }
-
- *eglDisplay = display;
- *eglContext = context;
- *eglSurface = surface;
- return true;
-}
-
-bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) {
- if (EGL_NO_DISPLAY == fDisplay) {
- bool bResult = create_ANGLE((HWND)fHWND,
- msaaSampleCount,
- &fDisplay,
- &fContext,
- &fSurface,
- &fConfig);
- if (false == bResult) {
- return false;
- }
- fANGLEInterface.reset(get_angle_gl_interface());
- if (!fANGLEInterface) {
- this->detachANGLE();
- return false;
- }
- GL_CALL(fANGLEInterface, ClearStencil(0));
- GL_CALL(fANGLEInterface, ClearColor(0, 0, 0, 0));
- GL_CALL(fANGLEInterface, StencilMask(0xffffffff));
- GL_CALL(fANGLEInterface, Clear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT));
- }
- if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
- this->detachANGLE();
- return false;
- }
- eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilBits);
- eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount);
-
- GL_CALL(fANGLEInterface, Viewport(0, 0, SkScalarRoundToInt(this->width()),
- SkScalarRoundToInt(this->height())));
- return true;
-}
-
-void SkOSWindow::detachANGLE() {
- fANGLEInterface.reset(nullptr);
- eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT);
-
- eglDestroyContext(fDisplay, fContext);
- fContext = EGL_NO_CONTEXT;
-
- eglDestroySurface(fDisplay, fSurface);
- fSurface = EGL_NO_SURFACE;
-
- eglTerminate(fDisplay);
- fDisplay = EGL_NO_DISPLAY;
-}
-
-void SkOSWindow::presentANGLE() {
- GL_CALL(fANGLEInterface, Flush());
-
- eglSwapBuffers(fDisplay, fSurface);
-}
-#endif // SK_ANGLE
-
-#endif // SK_SUPPORT_GPU
-
-// return true on success
-bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, bool deepColor,
- AttachmentInfo* info) {
-
- // attach doubles as "windowResize" so we need to allo
- // already bound states to pass through again
- // TODO: split out the resize functionality
-// SkASSERT(kNone_BackEndType == fAttached);
- bool result = true;
-
- switch (attachType) {
- case kNone_BackEndType:
- // nothing to do
- break;
-#if SK_SUPPORT_GPU
- case kNativeGL_BackEndType:
- result = attachGL(msaaSampleCount, deepColor, info);
- break;
-#if SK_ANGLE
- case kANGLE_BackEndType:
- result = attachANGLE(msaaSampleCount, info);
- break;
-#endif // SK_ANGLE
-#endif // SK_SUPPORT_GPU
- default:
- SkASSERT(false);
- result = false;
- break;
- }
-
- if (result) {
- fAttached = attachType;
- }
-
- return result;
-}
-
-void SkOSWindow::release() {
- switch (fAttached) {
- case kNone_BackEndType:
- // nothing to do
- break;
-#if SK_SUPPORT_GPU
- case kNativeGL_BackEndType:
- detachGL();
- break;
-#if SK_ANGLE
- case kANGLE_BackEndType:
- detachANGLE();
- break;
-#endif // SK_ANGLE
-#endif // SK_SUPPORT_GPU
- default:
- SkASSERT(false);
- break;
- }
- fAttached = kNone_BackEndType;
-}
-
-void SkOSWindow::present() {
- switch (fAttached) {
- case kNone_BackEndType:
- // nothing to do
- return;
-#if SK_SUPPORT_GPU
- case kNativeGL_BackEndType:
- presentGL();
- break;
-#if SK_ANGLE
- case kANGLE_BackEndType:
- presentANGLE();
- break;
-#endif // SK_ANGLE
-#endif // SK_SUPPORT_GPU
- default:
- SkASSERT(false);
- break;
- }
-}
-
-bool SkOSWindow::makeFullscreen() {
- if (fFullscreen) {
- return true;
- }
-#if SK_SUPPORT_GPU
- if (fHGLRC) {
- this->detachGL();
- }
-#endif // SK_SUPPORT_GPU
- // This is hacked together from various sources on the web. It can certainly be improved and be
- // made more robust.
-
- // Save current window/resolution information. We do this in case we ever implement switching
- // back to windowed mode.
- fSavedWindowState.fZoomed = SkToBool(IsZoomed((HWND)fHWND));
- if (fSavedWindowState.fZoomed) {
- SendMessage((HWND)fHWND, WM_SYSCOMMAND, SC_RESTORE, 0);
- }
- fSavedWindowState.fStyle = GetWindowLong((HWND)fHWND, GWL_STYLE);
- fSavedWindowState.fExStyle = GetWindowLong((HWND)fHWND, GWL_EXSTYLE);
- GetWindowRect((HWND)fHWND, &fSavedWindowState.fRect);
- DEVMODE currScreenSettings;
- memset(&currScreenSettings,0,sizeof(currScreenSettings));
- currScreenSettings.dmSize = sizeof(currScreenSettings);
- EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &currScreenSettings);
- fSavedWindowState.fScreenWidth = currScreenSettings.dmPelsWidth;
- fSavedWindowState.fScreenHeight = currScreenSettings.dmPelsHeight;
- fSavedWindowState.fScreenBits = currScreenSettings.dmBitsPerPel;
- fSavedWindowState.fHWND = fHWND;
-
- // Try different sizes to find an allowed setting? Use ChangeDisplaySettingsEx?
- static const int kWidth = 1280;
- static const int kHeight = 1024;
- DEVMODE newScreenSettings;
- memset(&newScreenSettings, 0, sizeof(newScreenSettings));
- newScreenSettings.dmSize = sizeof(newScreenSettings);
- newScreenSettings.dmPelsWidth = kWidth;
- newScreenSettings.dmPelsHeight = kHeight;
- newScreenSettings.dmBitsPerPel = 32;
- newScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
- if (ChangeDisplaySettings(&newScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
- return false;
- }
- RECT WindowRect;
- WindowRect.left = 0;
- WindowRect.right = kWidth;
- WindowRect.top = 0;
- WindowRect.bottom = kHeight;
- ShowCursor(FALSE);
- AdjustWindowRectEx(&WindowRect, WS_POPUP, FALSE, WS_EX_APPWINDOW);
- HWND fsHWND = CreateWindowEx(
- WS_EX_APPWINDOW,
- fWinInit.fClass,
- NULL,
- WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP,
- 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top,
- NULL,
- NULL,
- fWinInit.fInstance,
- NULL
- );
- if (!fsHWND) {
- return false;
- }
- // Hide the old window and set the entry in the global mapping for this SkOSWindow to the
- // new HWND.
- ShowWindow((HWND)fHWND, SW_HIDE);
- gHwndToOSWindowMap.remove(fHWND);
- fHWND = fsHWND;
- gHwndToOSWindowMap.set(fHWND, this);
- this->updateSize();
-
- fFullscreen = true;
- return true;
-}
-
-void SkOSWindow::setVsync(bool enable) {
- SkWGLExtensions wgl;
- wgl.swapInterval(enable ? 1 : 0);
-}
-
-void SkOSWindow::closeWindow() {
- DestroyWindow((HWND)fHWND);
- if (fFullscreen) {
- DestroyWindow((HWND)fSavedWindowState.fHWND);
- }
- gHwndToOSWindowMap.remove(fHWND);
-}
-#endif
diff --git a/src/views/win/skia_win.cpp b/src/views/win/skia_win.cpp
deleted file mode 100644
index df600d771c..0000000000
--- a/src/views/win/skia_win.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkTypes.h"
-
-#include <tchar.h>
-
-#include "SkApplication.h"
-#include "SkGraphics.h"
-#include "SkOSWindow_Win.h"
-
-LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
-
-// Returns the main window Win32 class name.
-static const TCHAR* register_class(HINSTANCE hInstance) {
- WNDCLASSEX wcex;
- // The main window class name
- static const TCHAR gSZWindowClass[] = _T("SkiaApp");
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = NULL;
- wcex.hCursor = NULL;
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = gSZWindowClass;
- wcex.hIconSm = NULL;
-
- RegisterClassEx(&wcex);
-
- return gSZWindowClass;
-}
-
-static char* tchar_to_utf8(const TCHAR* str) {
-#ifdef _UNICODE
- int size = WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), NULL, 0, NULL, NULL);
- char* str8 = (char*) sk_malloc_throw(size+1);
- WideCharToMultiByte(CP_UTF8, 0, str, wcslen(str), str8, size, NULL, NULL);
- str8[size] = '\0';
- return str8;
-#else
- return _strdup(str);
-#endif
-}
-
-// This file can work with GUI or CONSOLE subsystem types since we define _tWinMain and main().
-
-static int main_common(HINSTANCE hInstance, int show, int argc, char**argv);
-
-int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine,
- int nCmdShow) {
-
- // convert from lpCmdLine to argc, argv.
- char* argv[4096];
- int argc = 0;
- TCHAR exename[1024], *next;
- int exenameLen = GetModuleFileName(NULL, exename, SK_ARRAY_COUNT(exename));
- // we're ignoring the possibility that the exe name exceeds the exename buffer
- (void) exenameLen;
- argv[argc++] = tchar_to_utf8(exename);
- TCHAR* arg = _tcstok_s(lpCmdLine, _T(" "), &next);
- while (arg != NULL) {
- argv[argc++] = tchar_to_utf8(arg);
- arg = _tcstok_s(NULL, _T(" "), &next);
- }
- int result = main_common(hInstance, nCmdShow, argc, argv);
- for (int i = 0; i < argc; ++i) {
- sk_free(argv[i]);
- }
- return result;
-}
-
-int main(int argc, char**argv) {
- SkGraphics::Init();
- return main_common(GetModuleHandle(NULL), SW_SHOW, argc, argv);
-}
-
-static int main_common(HINSTANCE hInstance, int show, int argc, char**argv) {
- const TCHAR* windowClass = register_class(hInstance);
-
- application_init();
-
- SkOSWindow::WindowInit winInit;
- winInit.fInstance = hInstance;
- winInit.fClass = windowClass;
-
- create_sk_window(&winInit, argc, argv);
- SkOSWindow::ForAllWindows([show](void* hWnd, SkOSWindow**) {
- ShowWindow((HWND)hWnd, show);
- UpdateWindow((HWND)hWnd); }
- );
-
- MSG msg;
- // Main message loop
- while (GetMessage(&msg, NULL, 0, 0)) {
- if (true) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-
- application_term();
-
- return (int) msg.wParam;
-}
-
-extern SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv);
-
-LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
- switch (message) {
- case WM_COMMAND:
- return DefWindowProc(hWnd, message, wParam, lParam);
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default: {
- SkOSWindow* window = SkOSWindow::GetOSWindowForHWND(hWnd);
- if (window && window->wndProc(hWnd, message, wParam, lParam)) {
- return 0;
- } else {
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- }
- }
- return 0;
-}