2026-03-31 18:15:28 +09:00

105 lines
3.5 KiB
C++

#pragma once
#include "AnimationStrategy.h"
#include "TransitionStrategy.h"
#include "Preloader.h"
#include <string>
#include <sstream>
#include <iomanip>
#include <chrono>
#include <mutex>
#include <random>
#include <memory>
#include <android/native_window.h>
#include <android/native_window_jni.h>
class Renderer {
public:
enum class AnimationMode {
PAN = 0, ZOOM = 1, NONE = 2, RANDOM = 3,
PAN_ONE_WAY = 4, PAGE_TURN = 5
};
enum class TransitionMode {
FADE = 0, SLIDE = 1, RANDOM = 2, MOSAIC = 3
};
Renderer();
~Renderer();
void setNextMedia(int fd);
void renderFrame(ANativeWindow* window);
void release();
std::string getDebugInfo() const;
void startRenderLoop(ANativeWindow* window);
void stopRenderLoop();
void setAnimationSpeed(float speed);
void setAnimationMode(int mode);
void setFadeDuration(int durationMs);
void setPageTurnDelay(int delayMs);
void setTransitionMode(int mode);
void setImageRenderFrame(int frame);
void updateWeatherBitmap(void* pixels, int width, int height);
void clearWeatherBitmap();
void drawMedia(ANativeWindow_Buffer& buffer, MediaAsset& media, float alpha, float finalOffsetX, float finalOffsetY, float finalScale);
void renderVideoFrame(MediaAsset& media, ANativeWindow_Buffer& buffer, float scale, float offsetX, float offsetY, float alpha);
void renderImageFrame(const MediaAsset& media, ANativeWindow_Buffer& buffer, float scale, float offsetX, float offsetY, float alpha);
void calculateFitScaleAndOffset(const MediaAsset& media, int surfaceWidth, int surfaceHeight,
float& outScale, float& outOffsetX, float& outOffsetY) const;
private:
std::thread renderThread_;
std::atomic<bool> isRunning_{false};
ANativeWindow* nativeWindow_ = nullptr;
enum class RenderState { ANIMATING, TRANSITIONING };
RenderState currentState_ = RenderState::ANIMATING;
void handleAnimationState(ANativeWindow_Buffer& buffer, int surfaceWidth, int surfaceHeight);
void handleTransitionState(ANativeWindow_Buffer& buffer, int surfaceWidth, int surfaceHeight);
std::mutex renderMutex_;
Preloader preloader_;
MediaAsset currentMedia_;
MediaAsset nextMedia_;
std::unique_ptr<AnimationStrategy> animationStrategy_;
AnimationMode predictedNextAnimationMode_;
std::unique_ptr<TransitionStrategy> transitionStrategy_;
AnimationState lastAnimationState_;
AnimationMode configuredAnimationMode_ = AnimationMode::PAN;
TransitionMode configuredTransitionMode_ = TransitionMode::FADE;
AnimationMode activeAnimationMode_ = AnimationMode::PAN;
long long fadeDurationMs_ = 3000;
long long pageTurnDelayMs_ = 5000;
float animationSpeed_ = 1.0f;
// --- ⬇️ 목표 프레임 딜레이 변수 추가 ⬇️ ---
std::chrono::milliseconds currentFrameDelay_{33}; // 기본값 33ms (약 30fps)
AnimationState getStartStateForMode(AnimationMode mode, int surfaceWidth, int surfaceHeight);
AnimationMode predictNextAnimationMode();
std::chrono::steady_clock::time_point transitionStartTime_;
std::mt19937 randomEngine_;
void determineActiveAnimationMode();
std::vector<uint8_t> weatherPixels_;
int weatherWidth_ = 0;
int weatherHeight_ = 0;
int imageFrame_ = 33;
// 위치 변수
float weatherX_ = 100.0f;
float weatherY_ = 100.0f;
// 속도 변수 (방향 및 속도 조절)
float weatherVelX_ = 2.5f;
float weatherVelY_ = 2.0f;
std::mutex weatherMutex_;
};