[core] Avoid extra copy of TransformState in Painter::render

In MapContext thread, TransformState gets updated from main thread to
MapContext and Painter can safely reference MapContext's TransformState
instead of copying it upon each Painter::render call.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-13 18:58:12 +02:00
parent 31354186a6
commit 711d41f91b
8 changed files with 20 additions and 21 deletions

View File

@@ -242,8 +242,8 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
// Cleanup OpenGL objects that we abandoned since the last render call.
glObjectStore.performCleanup();
if (!painter) painter = std::make_unique<Painter>(data);
painter->render(*style, transformState, frame);
if (!painter) painter = std::make_unique<Painter>(data, transformState);
painter->render(*style, frame);
if (data.mode == MapMode::Still) {
callback(nullptr, view.readStillImage());

View File

@@ -21,13 +21,8 @@ class View;
class MapData;
class TexturePool;
class Painter;
class Sprite;
class Worker;
class StillImage;
class SpriteImage;
class FileRequest;
struct LatLng;
struct LatLngBounds;
struct FrameData {
std::array<uint16_t, 2> framebufferSize;

View File

@@ -159,7 +159,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration&
#pragma mark - Zoom
void Transform::scaleBy(const double ds, const PrecisionPoint& center, const Duration& duration) {
void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& duration) {
if (std::isnan(ds) || !center) {
return;
}
@@ -175,7 +175,7 @@ void Transform::scaleBy(const double ds, const PrecisionPoint& center, const Dur
_setScale(new_scale, center, duration);
}
void Transform::setScale(const double scale, const PrecisionPoint& center, const Duration& duration) {
void Transform::setScale(double scale, const PrecisionPoint& center, const Duration& duration) {
if (std::isnan(scale) || !center) {
return;
}
@@ -183,7 +183,7 @@ void Transform::setScale(const double scale, const PrecisionPoint& center, const
_setScale(scale, center, duration);
}
void Transform::setZoom(const double zoom, const Duration& duration) {
void Transform::setZoom(double zoom, const Duration& duration) {
if (std::isnan(zoom)) {
return;
}
@@ -225,7 +225,7 @@ void Transform::_setScale(double new_scale, const PrecisionPoint& center, const
_setScaleXY(new_scale, xn, yn, duration);
}
void Transform::_setScaleXY(const double new_scale, const double xn, const double yn,
void Transform::_setScaleXY(double new_scale, double xn, double yn,
const Duration& duration) {
CameraOptions options;
options.duration = duration;
@@ -332,7 +332,7 @@ void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& seco
_setAngle(ang, duration);
}
void Transform::setAngle(const double new_angle, const Duration& duration) {
void Transform::setAngle(double new_angle, const Duration& duration) {
if (std::isnan(new_angle)) {
return;
}
@@ -340,7 +340,7 @@ void Transform::setAngle(const double new_angle, const Duration& duration) {
_setAngle(new_angle, duration);
}
void Transform::setAngle(const double new_angle, const PrecisionPoint& center) {
void Transform::setAngle(double new_angle, const PrecisionPoint& center) {
if (std::isnan(new_angle) || !center) {
return;
}

View File

@@ -60,7 +60,7 @@ public:
bool isGestureInProgress() const { return state.isGestureInProgress(); }
// Transform state
const TransformState getState() const { return state; }
TransformState getState() const { return state; }
bool isRotating() const { return state.isRotating(); }
bool isScaling() const { return state.isScaling(); }
bool isPanning() const { return state.isPanning(); }

View File

@@ -7,6 +7,10 @@
using namespace mbgl;
TransformState::TransformState()
{
}
#pragma mark - Matrix
void TransformState::matrixFor(mat4& matrix, const TileID& id, const int8_t z) const {

View File

@@ -21,6 +21,8 @@ class TransformState {
friend class Transform;
public:
TransformState();
// Matrix
void matrixFor(mat4& matrix, const TileID& id, const int8_t z) const;
void getProjMatrix(mat4& matrix) const;

View File

@@ -43,7 +43,8 @@
using namespace mbgl;
Painter::Painter(MapData& data_) : data(data_) {
Painter::Painter(MapData& data_, TransformState& state_)
: data(data_), state(state_) {
setup();
}
@@ -127,8 +128,7 @@ void Painter::prepareTile(const Tile& tile) {
config.stencilFunc = { GL_EQUAL, ref, mask };
}
void Painter::render(const Style& style, TransformState state_, const FrameData& frame_) {
state = state_;
void Painter::render(const Style& style, const FrameData& frame_) {
frame = frame_;
glyphAtlas = style.glyphAtlas.get();

View File

@@ -82,7 +82,7 @@ struct RenderItem {
class Painter : private util::noncopyable {
public:
Painter(MapData& data);
Painter(MapData&, TransformState&);
~Painter();
// Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any
@@ -93,7 +93,6 @@ public:
void changeMatrix();
void render(const Style& style,
TransformState state,
const FrameData& frame);
// Renders debug information for a tile.
@@ -182,8 +181,7 @@ public:
private:
MapData& data;
TransformState state;
TransformState& state;
FrameData frame;
int indent = 0;