Skip to content

Commit 70e82e2

Browse files
committed
Use CPU texture in getFastBounds()
1 parent 6221223 commit 70e82e2

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/renderedtarget.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,14 @@ QRectF RenderedTarget::getBoundsForBubble() const
410410

411411
Rect RenderedTarget::getFastBounds() const
412412
{
413-
if (!m_costume || !m_skin || !m_texture.isValid())
413+
if (!m_costume || !m_skin || !m_texture.isValid() || !m_cpuTexture.isValid())
414414
return Rect(m_x, m_y, m_x, m_y);
415415

416-
const double scale = this->scale();
417-
const double width = this->width() / m_stageScale;
418-
const double height = this->height() / m_stageScale;
419-
const double originX = m_costume->rotationCenterX() * m_size / scale / m_costume->bitmapResolution() - width / 2;
420-
const double originY = -m_costume->rotationCenterY() * m_size / scale / m_costume->bitmapResolution() + height / 2;
416+
const double textureScale = m_skin->getTextureScale(m_cpuTexture);
417+
const double width = m_cpuTexture.width() * m_size / textureScale;
418+
const double height = m_cpuTexture.height() * m_size / textureScale;
419+
const double originX = m_costume->rotationCenterX() * m_size / textureScale / m_costume->bitmapResolution() - width / 2;
420+
const double originY = -m_costume->rotationCenterY() * m_size / textureScale / m_costume->bitmapResolution() + height / 2;
421421
const double rot = -rotation() * pi / 180;
422422

423423
QPointF topLeft = transformPoint(-width / 2, height / 2, originX, originY, rot);
@@ -438,7 +438,7 @@ Rect RenderedTarget::getFastBounds() const
438438
const double minY = std::min(yList);
439439
const double maxY = std::max(yList);
440440

441-
return Rect(minX * scale + m_x, maxY * scale + m_y, maxX * scale + m_x, minY * scale + m_y);
441+
return Rect(minX + m_x, maxY + m_y, maxX + m_x, minY + m_y);
442442
}
443443

444444
QPointF RenderedTarget::mapFromScene(const QPointF &point) const

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,40 +758,40 @@ TEST_F(RenderedTargetTest, GetFastBounds)
758758
target.beforeRedraw();
759759

760760
Rect bounds = target.getFastBounds();
761-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 65.84);
762-
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -123.92);
763-
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 67.31);
761+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 64.47);
762+
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -120.57);
763+
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 69.26);
764764
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -125.4);
765765

766766
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
767767
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
768768
target.updateRotationStyle(Sprite::RotationStyle::LeftRight);
769769

770770
bounds = target.getFastBounds();
771-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 71.67);
771+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 69.78);
772772
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -110.26);
773773
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 72.5);
774-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -111.51);
774+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -114.34);
775775

776776
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
777777
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
778778
target.setStageScale(20.75);
779779

780780
bounds = target.getFastBounds();
781-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 71.67);
781+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, 69.78);
782782
ASSERT_EQ(std::round(bounds.top() * 100) / 100, -110.26);
783783
ASSERT_EQ(std::round(bounds.right() * 100) / 100, 72.5);
784-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -111.51);
784+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, -114.34);
785785

786786
EXPECT_CALL(engine, stageWidth()).WillOnce(Return(480));
787787
EXPECT_CALL(engine, stageHeight()).WillOnce(Return(360));
788788
target.updateSize(9780.6);
789789

790790
bounds = target.getFastBounds();
791-
ASSERT_EQ(std::round(bounds.left() * 100) / 100, -496.15);
791+
ASSERT_EQ(std::round(bounds.left() * 100) / 100, -767);
792792
ASSERT_EQ(std::round(bounds.top() * 100) / 100, 1324.22);
793793
ASSERT_EQ(std::round(bounds.right() * 100) / 100, -375.77);
794-
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, 1143.65);
794+
ASSERT_EQ(std::round(bounds.bottom() * 100) / 100, 737.38);
795795

796796
context.doneCurrent();
797797
}

0 commit comments

Comments
 (0)