Skip to content

Commit

Permalink
HYDRA-598 : Merge viewport information interface (#4)
Browse files Browse the repository at this point in the history
* HYDRA-598 : Merge viewport information interface

* Fix build under Linux.

* HYDRA-598 : Fixes from code review.

* HYDRA-598 : Attempt in fixing Linux crash in tests

* HYDRA-598 : Changes from code review.

* HYDRA-598 : Fix a possible crash by deleting the RenderIndexProxy last.

* HYDRA-598 : Fixes from the code review.

* HYDRA-598 : Update a name from code review.

* HYDRA-598 : Add tests for multiviewports and update code taking into account the shared scene/render/index we use for all viewports

* HYDRA-598 : Fixes from code review.

* HYDRA-598 : Fixes from code review.
  • Loading branch information
lanierd-adsk authored Nov 21, 2023
1 parent d4f2a6d commit 9922683
Show file tree
Hide file tree
Showing 47 changed files with 1,341 additions and 86 deletions.
3 changes: 3 additions & 0 deletions lib/flowViewport/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ set(HEADERS
fvpSelectionClient.h
fvpFlowSelectionInterface.h
fvpVersionInterface.h
fvpInformationInterface.h
fvpInformationClient.h
)

# -----------------------------------------------------------------------------
Expand All @@ -27,3 +29,4 @@ install(FILES ${HEADERS}
# -----------------------------------------------------------------------------
add_subdirectory(interfacesImp)
add_subdirectory(samples)
add_subdirectory(perViewportSceneIndicesData)
63 changes: 63 additions & 0 deletions lib/flowViewport/API/fvpInformationClient.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


/// Is the definition of a callbacks InformationClient for an Hydra viewport.

#ifndef FLOW_VIEWPORT_API_INFORMATION_CLIENT_H
#define FLOW_VIEWPORT_API_INFORMATION_CLIENT_H

#include "flowViewport/api.h"

#include "fvpInformationInterface.h"

namespace FVP_NS_DEF
{
///Subclass this to create a client and register it through the InformationInterface class
class InformationClient
{
public:

/**
* @brief Callback function called when an Hydra viewport scene index is being created by our Hydra viewport plugin
*
* This is a callback function that gets called when an Hydra viewport scene index is being created by our Hydra viewport plugin.
* A typical case is when an Hydra viewport is created.
*
* @param[in] viewportInformation is an Hydra viewport information from the scene index being added by our Hydra viewport plugin.
*/
virtual void SceneIndexAdded(const InformationInterface::ViewportInformation& viewportInformation) = 0;

/**
* @brief Callback function called when an Hydra viewport scene index is being removed by our Hydra viewport plugin
*
* This is a callback function that gets called when an Hydra viewport scene index is removed by our Hydra viewport plugin.
* A typical case is when an Hydra viewport is removed.
*
* @param[in] viewportInformation is an Hydra viewport information from the scene index being removed by our Hydra viewport plugin.
*/
virtual void SceneIndexRemoved(const InformationInterface::ViewportInformation& viewportInformation) = 0;

/// Destructor
virtual ~InformationClient() = default;
};

/// Set of InformationClient
using SharedInformationClientPtrSet = std::set<std::shared_ptr<InformationClient>>;

}//end of namespace

#endif //FLOW_VIEWPORT_API_INFORMATION_CLIENT_H
98 changes: 98 additions & 0 deletions lib/flowViewport/API/fvpInformationInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H
#define FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H

//Local headers
#include "flowViewport/api.h"

//Hydra headers
#include <pxr/imaging/hd/sceneIndex.h>

namespace FVP_NS_DEF
{
class InformationClient;//Predeclaration

/*!\class InformationInterface
\brief : interface for a customer to register a callbacks InformationClient to get Hydra viewports information.
* To get an instance of the InformationInterface class, please use :
* Fvp::InformationInterface& informationInterface = Fvp::InformationInterface::Get();
*/
class InformationInterface
{
public:

///Interface accessor
static FVP_API InformationInterface& Get();

///Struct used to store information about an Hydra viewport from the DCC
struct ViewportInformation
{
/// Constructor
ViewportInformation(const std::string& viewportId, const std::string& cameraName)
: _viewportId(viewportId), _cameraName(cameraName) {}

///_viewportId is an Hydra viewport string identifier which is unique for all hydra viewports during a session
const std::string _viewportId;

///_cameraName is the name of the camera/viewport when the viewport was created, it is not updated if the camera's name has changed.
const std::string _cameraName;

///_rendererName is the Hydra viewport renderer name (example : "GL" for Storm or "Arnold" for the Arnold render delegate)
std::string _rendererName;

bool operator ==(const ViewportInformation& other)const{
return _viewportId == other._viewportId &&
_cameraName == other._cameraName &&
_rendererName == other._rendererName;
}

bool operator <(const ViewportInformation& other) const{ //to be used in std::set
auto a = {_viewportId, _cameraName, _rendererName};
auto b = {other._viewportId, other._cameraName, other._rendererName};
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end());
}
};

///Set of InformationInterface::ViewportInformation
typedef std::set<InformationInterface::ViewportInformation> ViewportInformationSet;

/**
* @brief Register a set of callbacks through an InformationClient instance
*
* @param[in] client is the InformationClient.
*/
virtual void RegisterInformationClient(const std::shared_ptr<InformationClient>& client) = 0;

/**
* @brief Unregister an InformationClient instance
*
* @param[in] client is the InformationClient.
*/
virtual void UnregisterInformationClient(const std::shared_ptr<InformationClient>& client)= 0;

/**
* @brief Get the Hydra viewports information.
*
* @param[out] outAllHydraViewportInformation is a set of ViewportInformation to have information about each Hydra viewport in use in the current DCC.
*/
virtual void GetViewportsInformation(ViewportInformationSet& outAllHydraViewportInformation)const = 0;
};

}//end of namespace

#endif //FLOW_VIEWPORT_API_INFORMATION_INTERFACE_H
2 changes: 1 addition & 1 deletion lib/flowViewport/API/fvpSelectionClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "flowViewport/api.h"

#include <pxr/usd/sdf/path.h>
#include <vector>
#include <set>

namespace FVP_NS_DEF
{
Expand Down
2 changes: 2 additions & 0 deletions lib/flowViewport/API/interfacesImp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ target_sources(${TARGET_NAME}
PRIVATE
fvpSelectionInterfaceImp.cpp
fvpVersionInterfaceImp.cpp
fvpInformationInterfaceImp.cpp
)

set(HEADERS
fvpSelectionInterfaceImp.h
fvpVersionInterfaceImp.h
fvpInformationInterfaceImp.h
)

# -----------------------------------------------------------------------------
Expand Down
100 changes: 100 additions & 0 deletions lib/flowViewport/API/interfacesImp/fvpInformationInterfaceImp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

//Local headers
#include "fvpInformationInterfaceImp.h"
#include "flowViewport/API/perViewportSceneIndicesData/fvpViewportInformationAndSceneIndicesPerViewportDataManager.h"

#include <mutex>

namespace{
std::mutex _viewportInformationClient_mutex;

//Set of information clients
FVP_NS_DEF::SharedInformationClientPtrSet _viewportInformationClients;
}

PXR_NAMESPACE_USING_DIRECTIVE

namespace FVP_NS_DEF {


InformationInterface& InformationInterface::Get()
{
return InformationInterfaceImp::Get();
}

InformationInterfaceImp& InformationInterfaceImp::Get()
{
static InformationInterfaceImp theInterface;
return theInterface;
}

void InformationInterfaceImp::RegisterInformationClient(const std::shared_ptr<InformationClient>& client)
{
TF_AXIOM(client);

std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex);

auto foundResult = _viewportInformationClients.find(client);
if (foundResult == _viewportInformationClients.cend()){
_viewportInformationClients.insert(client);
}
}

void InformationInterfaceImp::UnregisterInformationClient(const std::shared_ptr<InformationClient>& client)
{
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex);

auto foundResult = _viewportInformationClients.find(client);
if (foundResult != _viewportInformationClients.end()){
_viewportInformationClients.erase(foundResult);
}
}

void InformationInterfaceImp::SceneIndexAdded(const InformationInterface::ViewportInformation& _viewportInfo)
{
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex);
for (auto viewportInfoClient : _viewportInformationClients){
if (viewportInfoClient){
viewportInfoClient->SceneIndexAdded(_viewportInfo);
}
}
}

void InformationInterfaceImp::SceneIndexRemoved(const InformationInterface::ViewportInformation& _viewportInfo)
{
std::lock_guard<std::mutex> lock(_viewportInformationClient_mutex);
for (auto viewportInfoClient : _viewportInformationClients){
if (viewportInfoClient){
viewportInfoClient->SceneIndexRemoved(_viewportInfo);
}
}
}

void InformationInterfaceImp::GetViewportsInformation(ViewportInformationSet& outHydraViewportInformationArray)const
{
outHydraViewportInformationArray.clear();
const ViewportInformationAndSceneIndicesPerViewportDataSet& allViewportInformationAndSceneIndicesPerViewportData =
ViewportInformationAndSceneIndicesPerViewportDataManager::Get().GetViewportInfoAndSceneIndicesPerViewportData();
for (const ViewportInformationAndSceneIndicesPerViewportData& viewportInformationAndSceneIndicesPerViewportData : allViewportInformationAndSceneIndicesPerViewportData){
const InformationInterface::ViewportInformation& viewportInfo = viewportInformationAndSceneIndicesPerViewportData.GetViewportInformation();
outHydraViewportInformationArray.insert(viewportInfo);
}
}

} //End of namespace FVP_NS_DEF {

50 changes: 50 additions & 0 deletions lib/flowViewport/API/interfacesImp/fvpInformationInterfaceImp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Copyright 2023 Autodesk, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H
#define FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H

//Local headers
#include <flowViewport/api.h>
#include <flowViewport/API/fvpInformationInterface.h>
#include <flowViewport/API/fvpInformationClient.h>

namespace FVP_NS_DEF {

///Is a singleton, use InformationInterfaceImp& InformationInterfaceImp::Get() to get an instance of that interface
class InformationInterfaceImp : public InformationInterface
{
public:
virtual ~InformationInterfaceImp() = default;

///Interface accessor
static FVP_API InformationInterfaceImp& Get();

//From InformationInterface
void RegisterInformationClient(const std::shared_ptr<InformationClient>& client)override;
void UnregisterInformationClient(const std::shared_ptr<InformationClient>& client)override;
void GetViewportsInformation(ViewportInformationSet& outHydraviewportInformationSet) const override;

void SceneIndexAdded(const InformationInterface::ViewportInformation& _viewportInfo);
void SceneIndexRemoved(const InformationInterface::ViewportInformation& viewportInfo);

private:
InformationInterfaceImp() = default;
};

} //End of namespace FVP_NS_DEF

#endif // FLOW_VIEWPORT_API_INTERFACESIMP_INFORMATION_INTERFACE_IMP_H
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@
#include <mutex>

namespace{
static std::mutex _viewportSelectClient_mutex;
std::mutex _viewportSelectClient_mutex;
}

PXR_NAMESPACE_USING_DIRECTIVE

namespace FVP_NS_DEF {

static SelectionInterfaceImp theInterface;

SelectionClientSet _viewportSelectionClients;

FlowSelectionInterface& FlowSelectionInterface::Get()
{
return theInterface;
return SelectionInterfaceImp::Get();
}

SelectionInterfaceImp& SelectionInterfaceImp::Get()
{
static SelectionInterfaceImp theInterface;
return theInterface;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ namespace FVP_NS_DEF {
class SelectionInterfaceImp : public FVP_NS_DEF::FlowSelectionInterface
{
public:
SelectionInterfaceImp() = default;
virtual ~SelectionInterfaceImp() = default;

///Interface accessor
Expand All @@ -40,6 +39,9 @@ class SelectionInterfaceImp : public FVP_NS_DEF::FlowSelectionInterface

//To be called by maya-hydra
void DummySelectionCallback();

private:
SelectionInterfaceImp() = default;
};

} //End of namespace FVP_NS_DEF
Expand Down
Loading

0 comments on commit 9922683

Please sign in to comment.