diff --git a/frameworks/bootanimation/include/boot_picture_player.h b/frameworks/bootanimation/include/boot_picture_player.h index 6e182e73b4bb857aff22ad392e601c8387472717..0c5b50bdaa20defb45976a2eeac81baae8442b7e 100644 --- a/frameworks/bootanimation/include/boot_picture_player.h +++ b/frameworks/bootanimation/include/boot_picture_player.h @@ -56,6 +56,7 @@ private: std::shared_ptr rsSurface_; std::unique_ptr rsSurfaceFrame_; std::shared_ptr receiver_; + std::shared_ptr surfaceNode_; }; } // namespace OHOS diff --git a/frameworks/bootanimation/include/boot_player.h b/frameworks/bootanimation/include/boot_player.h index 1363b0c2857629dcb7dd15711fca398f5e86b396..01bbf52091c49353e5bb7152baaba0f9f7900457 100644 --- a/frameworks/bootanimation/include/boot_player.h +++ b/frameworks/bootanimation/include/boot_player.h @@ -42,7 +42,9 @@ public: Rosen::ScreenId screenId_; std::string resPath_; bool isSoundEnabled_ = false; +#ifdef PLAYER_FRAMEWORK_ENABLE std::shared_ptr mediaPlayer_; +#endif }; } // namespace OHOS diff --git a/frameworks/bootanimation/include/boot_video_player.h b/frameworks/bootanimation/include/boot_video_player.h index 7e4514ba572655a45048dcb9ea9c1b79dd040052..713f51e5ce579304ba84035aa3de0ffb0b8b238f 100644 --- a/frameworks/bootanimation/include/boot_video_player.h +++ b/frameworks/bootanimation/include/boot_video_player.h @@ -30,7 +30,9 @@ public: private: void SetCallback(const BootAnimationCallback* cb); bool SetVideoSound(); +#ifdef PLAYER_FRAMEWORK_ENABLE std::shared_ptr GetMediaPlayer() const; +#endif void StopVideo(); #ifdef PLAYER_FRAMEWORK_ENABLE diff --git a/frameworks/bootanimation/include/util.h b/frameworks/bootanimation/include/util.h index 365b53aedb8f3c7a10653d17250145ea791a2fd0..36b244b8551c93c7cd0bacd7a9ff307835800daa 100644 --- a/frameworks/bootanimation/include/util.h +++ b/frameworks/bootanimation/include/util.h @@ -29,6 +29,7 @@ #include #include #include "zlib.h" +#include namespace OHOS { static const int NUMBER_TWO = 2; @@ -129,6 +130,7 @@ using PlayerParams = struct PlayerParams { bool soundEnabled = false; BootAnimationCallback* callback; std::string resPath; + std::shared_ptr surfaceNode = nullptr; }; void PostTask(std::function func, uint32_t delayTime = 0); diff --git a/frameworks/bootanimation/src/boot_animation_operation.cpp b/frameworks/bootanimation/src/boot_animation_operation.cpp index c4d4173be9669d50824a9dffc7e81cf2ca4a46fa..7b35bcb42abedf61869315b4c7bd3af087d993a7 100644 --- a/frameworks/bootanimation/src/boot_animation_operation.cpp +++ b/frameworks/bootanimation/src/boot_animation_operation.cpp @@ -58,6 +58,7 @@ void BootAnimationOperation::StartEventHandler(const BootAnimationConfig& config mainHandler_->PostTask([this] { this->InitRsDisplayNode(); }); mainHandler_->PostTask([this, &config] { this->InitRsSurfaceNode(config.rotateDegree); }); mainHandler_->PostTask([this] { this->StopBootAnimation(); }, duration_); +// ruhi #ifdef PLAYER_FRAMEWORK_ENABLE if (IsBootVideoEnabled(config)) { mainHandler_->PostTask([this, &config] { this->PlayVideo(config.videoDefaultPath); }); @@ -171,6 +172,7 @@ void BootAnimationOperation::PlayPicture(const std::string& path) params.screenId = currentScreenId_; params.rsSurface = rsSurface_; params.resPath = path; + params.surfaceNode = rsSurfaceNode_; picPlayer_ = std::make_shared(params); picPlayer_->Play(); } @@ -203,6 +205,7 @@ bool BootAnimationOperation::InitRsSurface() drawingContext->SetUpDrawingContext(); rsSurface_ = Rosen::RSSurfaceFactory::CreateRSSurface(Rosen::PlatformName::OHOS, surface, drawingContext); rsSurface_->SetRenderContext(renderContext); + #else rsSurface_ = OHOS::Rosen::RSSurfaceExtractor::ExtractRSSurface(rsSurfaceNode_); if (rsSurface_ == nullptr) { diff --git a/frameworks/bootanimation/src/boot_picture_player.cpp b/frameworks/bootanimation/src/boot_picture_player.cpp index 12b5d7c575680120dba37f6b30a0ac64f05d6eb2..41aa7fcc650e61ac4a8a4296036d34021f7b96f2 100644 --- a/frameworks/bootanimation/src/boot_picture_player.cpp +++ b/frameworks/bootanimation/src/boot_picture_player.cpp @@ -28,6 +28,7 @@ BootPicturePlayer::BootPicturePlayer(const PlayerParams& params) { resPath_ = params.resPath; rsSurface_ = params.rsSurface; + surfaceNode_ = params.surfaceNode; InitPicCoordinates(params.screenId); } @@ -147,6 +148,7 @@ bool BootPicturePlayer::Draw() return false; } #ifdef NEW_RENDER_CONTEXT +#error NEW_RENDER_CONTEXT code if (rsSurface_ == nullptr) { LOGE("rsSurface is nullptr"); AppExecFwk::EventRunner::Current()->Stop(); @@ -168,6 +170,116 @@ bool BootPicturePlayer::Draw() return true; } +sptr GetSurfaceBuffer(sptr ohosSurface, int32_t width, int32_t height) +{ + sptr buffer; + int32_t releaseFence = 0; + BufferRequestConfig config = { + .width = width, + .height = height, + .strideAlignment = 0x8, + .format = GRAPHIC_PIXEL_FMT_RGBA_8888, + .usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE | BUFFER_USAGE_MEM_DMA, + }; + + SurfaceError ret = ohosSurface->RequestBuffer(buffer, releaseFence, config); + if (ret != SURFACE_ERROR_OK) { + return nullptr; + } + return buffer; +} + +// bool BootPicturePlayer::OnDraw(Rosen::Drawing::CoreCanvas* canvas, int32_t curNo) +// { +// if (canvas == nullptr) { +// LOGE("OnDraw canvas is nullptr"); +// AppExecFwk::EventRunner::Current()->Stop(); +// return false; +// } +// if (curNo > (imgVecSize_ - 1) || curNo < 0) { +// AppExecFwk::EventRunner::Current()->Stop(); +// return false; +// } +// std::shared_ptr imgstruct = imageVector_[curNo]; +// std::shared_ptr image = imgstruct->imageData; + +// ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, "BootAnimation::OnDraw in drawRect"); + +// LOGE("WDS: auto ohosSurface = surfaceNode_->GetSurface();"); +// auto ohosSurface = surfaceNode_->GetSurface(); +// if (ohosSurface == nullptr) { +// LOGE("WDS: ohosSurface == nullptr"); +// return false; +// } +// LOGE("WDS: sptr buffer = GetSurfaceBuffer(ohosSurface, surfaceNode_->GetStagingProperties().GetBounds().z_,"); + +// // sptr buffer = surfaceNode_->GetBuffer(); +// LOGE("WDS: buffer == nullptr || buffer->GetVirAddr() == nullptr"); +// if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { +// LOGE("WDS: return false"); +// return false; +// } +// LOGE("WDS: auto addr = static_cast(buffer->GetVirAddr());"); +// auto addr = static_cast(buffer->GetVirAddr()); + +// LOGE("WDS: Rosen::Drawing::Bitmap bitmap;"); +// Rosen::Drawing::Bitmap bitmap; +// LOGE("WDS: Rosen::Drawing::BitmapFormat format { Rosen::Drawing::COLORTYPE_RGBA_8888, Rosen::Drawing::ALPHATYPE_OPAQUE };"); +// Rosen::Drawing::BitmapFormat format { Rosen::Drawing::COLORTYPE_RGBA_8888, Rosen::Drawing::ALPHATYPE_OPAQUE }; +// LOGE("WDS: bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format);"); +// bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format); +// LOGE("WDS: canvas->Bind(bitmap);"); +// canvas->Bind(bitmap); + +// Rosen::Drawing::Brush brush; +// brush.SetColor(Rosen::Drawing::Color::COLOR_RED); +// Rosen::Drawing::Rect bgRect(0.0, 0.0, windowWidth_, windowHeight_); +// canvas->AttachBrush(brush); +// canvas->DrawRect(bgRect); +// canvas->DetachBrush(); +// ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); +// ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, "BootAnimation::OnDraw in drawImageRect"); +// Rosen::Drawing::Rect rect(pointX_, pointY_, pointX_ + realWidth_, pointY_ + realHeight_); +// Rosen::Drawing::SamplingOptions samplingOptions; +// canvas->DrawImageRect(*image, rect, samplingOptions); + +// static constexpr uint32_t stride = 4; +// uint32_t addrSize = windowWidth_ * windowHeight_ * stride; +// LOGE("WDS: memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);"); +// memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); +// // { + +// // Rosen::Drawing::Brush brush2; +// // brush2.SetColor(Rosen::Drawing::Color::COLOR_RED); +// // Rosen::Drawing::Rect bgRect2(50.0, 120.0, windowWidth_, windowHeight_); +// // canvas->AttachBrush(brush2); +// // canvas->DrawRect(bgRect2); +// // canvas->DetachBrush(); +// // } +// LOGE("WDS: imageVector_[curNo].reset();"); +// imageVector_[curNo].reset(); +// ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); +// LOGE("WDS: return true;"); +// return true; +// } + + +void DrawBuffer(Rosen::Drawing::CoreCanvas* canvas, BufferDrawParam& params) +{ + LOGE("RSBaseRenderEngine::DrawBuffer(CPU)"); + Drawing::Bitmap bitmap; + std::vector newBuffer; + if (!RSBaseRenderUtil::ConvertBufferToBitmap(params.buffer, newBuffer, params.targetColorGamut, bitmap, + params.metaDatas)) { + RS_LOGE("RSDividedRenderUtil::DrawBuffer: create bitmap failed."); + return; + } + Drawing::Image drImage; + drImage.BuildFromBitmap(bitmap); + canvas.DrawImageRect(drImage, params.srcRect, params.dstRect, Drawing::SamplingOptions(), + Drawing::SrcRectConstraint::STRICT_SRC_RECT_CONSTRAINT); +} + bool BootPicturePlayer::OnDraw(Rosen::Drawing::CoreCanvas* canvas, int32_t curNo) { if (canvas == nullptr) { @@ -183,8 +295,39 @@ bool BootPicturePlayer::OnDraw(Rosen::Drawing::CoreCanvas* canvas, int32_t curNo std::shared_ptr image = imgstruct->imageData; ROSEN_TRACE_BEGIN(HITRACE_TAG_GRAPHIC_AGP, "BootAnimation::OnDraw in drawRect"); + + + + LOGE("WDS: auto ohosSurface = surfaceNode_->GetSurface();"); + auto ohosSurface = surfaceNode_->GetSurface(); + if (ohosSurface == nullptr) { + LOGE("WDS: ohosSurface == nullptr"); + return false; + } + LOGE("WDS: sptr buffer = GetSurfaceBuffer(ohosSurface, surfaceNode_->GetStagingProperties().GetBounds().z_,"); + // std::shared_ptr drawingCanvas = std::make_shared(canvas.get()); + // std::shared_ptr canvas = std::make_shared(drawingCanvas.get()); + + // sptr buffer = surfaceNode_->GetBuffer(); + LOGE("WDS: buffer == nullptr || buffer->GetVirAddr() == nullptr"); + if (buffer == nullptr || buffer->GetVirAddr() == nullptr) { + LOGE("WDS: return false"); + return false; + } + LOGE("WDS: auto addr = static_cast(buffer->GetVirAddr());"); + auto addr = static_cast(buffer->GetVirAddr()); + + LOGE("WDS: Rosen::Drawing::Bitmap bitmap;"); + Rosen::Drawing::Bitmap bitmap; + LOGE("WDS: Rosen::Drawing::BitmapFormat format { Rosen::Drawing::COLORTYPE_RGBA_8888, Rosen::Drawing::ALPHATYPE_OPAQUE };"); + Rosen::Drawing::BitmapFormat format { Rosen::Drawing::COLORTYPE_RGBA_8888, Rosen::Drawing::ALPHATYPE_OPAQUE }; + LOGE("WDS: bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format);"); + bitmap.Build(buffer->GetWidth(), buffer->GetHeight(), format); + LOGE("WDS: canvas->Bind(bitmap);"); + canvas->Bind(bitmap); + Rosen::Drawing::Brush brush; - brush.SetColor(Rosen::Drawing::Color::COLOR_BLACK); + brush.SetColor(Rosen::Drawing::Color::COLOR_RED); Rosen::Drawing::Rect bgRect(0.0, 0.0, windowWidth_, windowHeight_); canvas->AttachBrush(brush); canvas->DrawRect(bgRect); @@ -194,8 +337,21 @@ bool BootPicturePlayer::OnDraw(Rosen::Drawing::CoreCanvas* canvas, int32_t curNo Rosen::Drawing::Rect rect(pointX_, pointY_, pointX_ + realWidth_, pointY_ + realHeight_); Rosen::Drawing::SamplingOptions samplingOptions; canvas->DrawImageRect(*image, rect, samplingOptions); + + static constexpr uint32_t stride = 4; + uint32_t addrSize = windowWidth_ * windowHeight_ * stride; + LOGE("WDS: memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);"); + memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + + + + + + LOGE("WDS: imageVector_[curNo].reset();"); imageVector_[curNo].reset(); ROSEN_TRACE_END(HITRACE_TAG_GRAPHIC_AGP); + LOGE("WDS: return true;"); return true; } + } // namespace OHOS diff --git a/frameworks/bootanimation/src/boot_video_player.cpp b/frameworks/bootanimation/src/boot_video_player.cpp index 16ed91226aaf0737a598f2db24666a87920dcfd8..abc72819ef536ca7d0897cd3fa14ae8ede677b31 100644 --- a/frameworks/bootanimation/src/boot_video_player.cpp +++ b/frameworks/bootanimation/src/boot_video_player.cpp @@ -119,8 +119,8 @@ bool BootVideoPlayer::SetVideoSound() return false; } } - return true; #endif + return true; } void BootVideoPlayer::SetCallback(const BootAnimationCallback* cb) diff --git a/graphic_config.gni b/graphic_config.gni index f86cbe1b31b0c13794abc8a2642b99fbf9eeaaaa..190bce3742a8db11eb8128cb7ef8ab0587bec42c 100644 --- a/graphic_config.gni +++ b/graphic_config.gni @@ -40,7 +40,7 @@ declare_args() { use_video_processing_engine = false logger_enable_scope = false texgine_enable_debug_log = false - player_framework_enable = true + player_framework_enable = false graphic_2d_feature_drivers_interface_display_enable = true graphic_2d_feature_tp_switch_enbale = false graphic_2d_feature_enable_recording_dcl = true @@ -125,10 +125,13 @@ if (graphic_2d_feature_ace_enable_gpu) { libvulkan += [ "//third_party/vulkan-loader:vulkan_loader" ] } } else { - gpu_defines = [ "ACE_DISABLE_GL" ] + gpu_defines += [ "ACE_DISABLE_GL" ] ace_enable_gpu = false rs_enable_gpu = false surface_enable_gpu = false + print("----------init--------------ace_enable_gpu=") + print(ace_enable_gpu) + libvulkan = [] } diff --git a/interfaces/kits/napi/graphic/webgl/BUILD.gn b/interfaces/kits/napi/graphic/webgl/BUILD.gn index e0404518093d163843a1a1b2ebcae6b3e2140ac8..6923313e66d55d45153a3e955d9999ccbb98d71d 100644 --- a/interfaces/kits/napi/graphic/webgl/BUILD.gn +++ b/interfaces/kits/napi/graphic/webgl/BUILD.gn @@ -40,6 +40,7 @@ ohos_source_set("webgl_src") { "image_framework:image_native", "napi:ace_napi", "node:node_header_notice", + "opengles:libGLES" ] if (ace_enable_gpu) { @@ -78,6 +79,7 @@ ohos_source_set("webgl_src") { deps = [ "$graphic_2d_root/frameworks/opengl_wrapper:EGL", + "$graphic_2d_root/frameworks/opengl_wrapper:GLESv2", "$graphic_2d_root/frameworks/opengl_wrapper:GLESv3", ] external_deps += [ "bounds_checking_function:libsec_shared" ] diff --git a/rosen/modules/2d_graphics/BUILD.gn b/rosen/modules/2d_graphics/BUILD.gn index 499e2369daa68e79657b7c990ec084c0b1f85f5b..c2c15b7a01cd8e651f998a6811cff60379f69fe7 100755 --- a/rosen/modules/2d_graphics/BUILD.gn +++ b/rosen/modules/2d_graphics/BUILD.gn @@ -170,6 +170,11 @@ template("graphics2d_source_set") { "$drawing_core_src_dir/utils/vertices.cpp", ] + sources += [ + "$drawing_core_src_dir/engine_adapter/skia_adapter/skia_gpu_context.cpp", + "$drawing_core_src_dir/image/gpu_context.cpp", + ] + if (platform == "ohos" || platform == "ohos_ng") { sanitize = { boundary_sanitize = true @@ -188,10 +193,10 @@ template("graphics2d_source_set") { } if (ace_enable_gpu) { - sources += [ - "$drawing_core_src_dir/engine_adapter/skia_adapter/skia_gpu_context.cpp", - "$drawing_core_src_dir/image/gpu_context.cpp", - ] +# sources += [ +# "$drawing_core_src_dir/engine_adapter/skia_adapter/skia_gpu_context.cpp", +# "$drawing_core_src_dir/image/gpu_context.cpp", +# ] defines += [ "ACE_ENABLE_GPU" ] } diff --git a/rosen/modules/2d_graphics/include/image/gpu_context.h b/rosen/modules/2d_graphics/include/image/gpu_context.h index 7483f5353a418009f76ec43239ce1c9103229def..88dc046cae45a5d070295631d782e860441aa35e 100644 --- a/rosen/modules/2d_graphics/include/image/gpu_context.h +++ b/rosen/modules/2d_graphics/include/image/gpu_context.h @@ -101,6 +101,7 @@ private: class DRAWING_API GPUContext { public: GPUContext(); +public: ~GPUContext() {} /** diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_factory.h b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_factory.h index 2c7d615f12ec78776ebb4fb78d6413e0a3870bb2..dc517fc4e717d508a52eae911dcb5c82eb29fffa 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_factory.h +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_factory.h @@ -24,9 +24,9 @@ #include "impl_interface/color_space_impl.h" #include "impl_interface/core_canvas_impl.h" #include "impl_interface/data_impl.h" -#ifdef ACE_ENABLE_GPU +//#ifdef ACE_ENABLE_GPU #include "impl_interface/gpu_context_impl.h" -#endif +//#endif #include "impl_interface/font_impl.h" #include "impl_interface/font_mgr_impl.h" #include "impl_interface/image_filter_impl.h" diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/gpu_context_impl.h b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/gpu_context_impl.h index 43f745603268e4a0289aed58d17bcfbb272f9605..4bf2b255ccb31b4fbb2a6199d32a49a2d96aab1f 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/gpu_context_impl.h +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/gpu_context_impl.h @@ -36,8 +36,10 @@ struct HpsBlurParameter; class GPUContext; class GPUContextOptions; class GPUContextImpl : public BaseImpl { +//private: public: GPUContextImpl() {}; +public: ~GPUContextImpl() override {}; virtual bool BuildFromGL(const GPUContextOptions& options) = 0; diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/trace_memory_dump_impl.h b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/trace_memory_dump_impl.h index 819d5734092d757880931a236d4948b6bbd9e971..39925414440934b8d290ff596d9f6ba0b28c5e96 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/trace_memory_dump_impl.h +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/impl_interface/trace_memory_dump_impl.h @@ -24,6 +24,7 @@ namespace OHOS { namespace Rosen { namespace Drawing { +// #error TraceMemoryDumpImpl-ruhiAdded class TraceMemoryDumpImpl : public BaseImpl { public: TraceMemoryDumpImpl(const char* categoryKey, bool itemizeType) {}; diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.cpp b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.cpp index 26ca1d4df0afd5b65a3720c8a283e535ed987faf..1ebf7ab93d965240e8284af67d7a747bdea91c7f 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.cpp +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.cpp @@ -123,6 +123,8 @@ RectI SkiaCanvas::GetRoundInDeviceClipBounds() const #ifdef ACE_ENABLE_GPU std::shared_ptr SkiaCanvas::GetGPUContext() const { +//ruhi return nullptr; + if (skCanvas_ == nullptr || skCanvas_->recordingContext() == nullptr || GrAsDirectContext(skCanvas_->recordingContext()) == nullptr) { LOGD("skCanvas_ or grContext is null, return on line %{public}d", __LINE__); diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.h b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.h index 133da0bef0efb6ba6d3daef869146aa246bc9f02..3257d3a9ed1a8bea631edeb6e605c7bea54eacc8 100755 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.h +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_canvas.h @@ -64,8 +64,10 @@ public: RectI GetDeviceClipBounds() const override; RectI GetRoundInDeviceClipBounds() const override; #ifdef ACE_ENABLE_GPU - std::shared_ptr GetGPUContext() const override; +// std::shared_ptr GetGPUContext() const override; #endif + std::shared_ptr GetGPUContext() const override; + int32_t GetWidth() const override; int32_t GetHeight() const override; ImageInfo GetImageInfo() override; diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.cpp b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.cpp index 20b30f63d871738ae57caefc885debfbb1ab9dea..797de887ed108741e60912577a64f03fcfadaf19 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.cpp +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.cpp @@ -78,6 +78,7 @@ void SkiaGPUContext::InitSkExecutor() bool SkiaGPUContext::BuildFromGL(const GPUContextOptions& options) { + LOGD("---------ruhi---------SkiaGPUContext::BuildFromGL: 0x%{public}08x", (int)&options); sk_sp glInterface(GrGLCreateNativeInterface()); if (options.GetPersistentCache() != nullptr) { skiaPersistentCache_ = std::make_shared(options.GetPersistentCache()); diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.h b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.h index 3e3aac54c3e703402a21e4c32ca9d8c99e2ba8e1..e2e1c172a997b08b287609ab2e09ba852f169a33 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.h +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_gpu_context.h @@ -120,6 +120,10 @@ private: std::shared_ptr skiaPersistentCache_; static std::unordered_map& task)>> contextPostMap_; }; + + +//ruhi add + } // namespace Drawing } // namespace Rosen } // namespace OHOS diff --git a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_image.cpp b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_image.cpp index 1631fc664e45501a70467f9640cc8c7f07e543c3..c062acbccb21652acfab1cc238d89e369c8910cc 100644 --- a/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_image.cpp +++ b/rosen/modules/2d_graphics/src/drawing/engine_adapter/skia_adapter/skia_image.cpp @@ -36,8 +36,9 @@ #ifdef ACE_ENABLE_GPU #include "include/core/SkYUVAPixmaps.h" -#include "skia_gpu_context.h" + #endif +#include "skia_gpu_context.h" namespace OHOS { namespace Rosen { diff --git a/rosen/modules/2d_graphics/src/render_context/render_context.cpp b/rosen/modules/2d_graphics/src/render_context/render_context.cpp index 5901c821ee881bb61b2a5256fc476ad5100cad32..1bf5099e6ae29e9df02e3ec6452a7980a7c3b950 100644 --- a/rosen/modules/2d_graphics/src/render_context/render_context.cpp +++ b/rosen/modules/2d_graphics/src/render_context/render_context.cpp @@ -106,7 +106,9 @@ RenderContext::RenderContext() eglSurface_(EGL_NO_SURFACE), config_(nullptr), mHandler_(nullptr) -{} +{ + LOGE("---------ruhi---------RenderContext: 0x%{public}d", 555); +} RenderContext::~RenderContext() { @@ -282,10 +284,20 @@ EGLSurface RenderContext::CreateEGLSurface(EGLNativeWindowType eglNativeWindow) bool RenderContext::SetUpGpuContext(std::shared_ptr drawingContext) { + LOGE("---------ruhi---------SetUpGpuContext-1: 0x%{public}08x", (unsigned int)drawingContext.get()); if (drGPUContext_ != nullptr) { LOGD("Drawing GPUContext has already created!!"); return true; } + + LOGE("---------ruhi---------GetGpuApiType: 0x%{public}08x", (unsigned int)RSSystemProperties::GetGpuApiType()); + LOGE("---------ruhi---------:GL_VERSION X%{public}sX", glGetString(GL_VERSION)); + LOGE("---------ruhi---------mHandler_: 0x%{public}08x", (unsigned int)mHandler_.get()); + { + auto drGPUContext = std::make_shared(); + LOGE("---------ruhi---------drGPUContext: 0x%{public}08x", (unsigned int)drGPUContext.get()); + } +// return false; #ifdef RS_ENABLE_GL if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { mHandler_ = std::make_shared(); @@ -338,6 +350,7 @@ void RenderContext::AbandonContext() std::shared_ptr RenderContext::AcquireSurface(int width, int height) { + LOGE("---------ruhi---------SetUpGpuContext-2: 0x%{public}d", width); if (!SetUpGpuContext(nullptr)) { LOGE("GrContext is not ready!!!"); return nullptr; diff --git a/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp b/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp index f2cbe8d2caf0857823dc3c0d4d16d893ee0a806b..43342bd0bb97e472d6ca591dc20b3e2af7acddec 100644 --- a/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_base_render_engine.cpp @@ -56,6 +56,7 @@ RSBaseRenderEngine::~RSBaseRenderEngine() noexcept void RSBaseRenderEngine::Init(bool independentContext) { + RS_LOGE("-----ruhi---- RSBaseRenderEngine::Init"); (void)independentContext; #if defined(NEW_RENDER_CONTEXT) RenderType renderType = RenderType::RASTER; @@ -71,13 +72,18 @@ void RSBaseRenderEngine::Init(bool independentContext) drawingContext_ = std::make_shared(renderContext_->GetRenderType()); drawingContext_->SetUpDrawingContext(); #else + RS_LOGE("---------ruhi---------renderContext_ Skip 0x%{public}08x", (unsigned int)renderContext_.get()); + #if (defined RS_ENABLE_GL) || (defined RS_ENABLE_VK) renderContext_ = std::make_shared(); + #ifdef RS_ENABLE_GL +//#error GL_Creation RS_ENABLE_GL only if (!RSSystemProperties::IsUseVulkan()) { renderContext_->InitializeEglContext(); } #endif + if (RSUniRenderJudgement::IsUniRender()) { RS_LOGI("RSRenderEngine::RSRenderEngine set new cacheDir"); renderContext_->SetUniRenderMode(true); @@ -91,18 +97,24 @@ void RSBaseRenderEngine::Init(bool independentContext) renderContext_->SetUpGpuContext(); } #else + RS_LOGE("---------ruhi---------SetUpGpuContext-3: 0x%{public}08x", 0x7770777); renderContext_->SetUpGpuContext(); #endif #endif // RS_ENABLE_GL || RS_ENABLE_VK + #endif + if (renderContext_ != nullptr) { #if defined(RS_ENABLE_EGLIMAGE) #if defined(NEW_RENDER_CONTEXT) - std::shared_ptr frame = renderContext_->GetRSRenderSurfaceFrame(); - eglImageManager_ = std::make_shared(frame->eglState->eglDisplay); + std::shared_ptr frame = renderContext_->GetRSRenderSurfaceFrame(); + eglImageManager_ = std::make_shared(frame->eglState->eglDisplay); #else - eglImageManager_ = std::make_shared(renderContext_->GetEGLDisplay()); + eglImageManager_ = std::make_shared(renderContext_->GetEGLDisplay()); #endif #endif // RS_ENABLE_EGLIMAGE + } else { + RS_LOGE("---ruhi---This render context is nullptr."); + } #ifdef RS_ENABLE_VK if (RSSystemProperties::IsUseVulkan()) { skContext_ = RsVulkanContext::GetSingleton().CreateDrawingContext(); @@ -388,11 +400,15 @@ std::unique_ptr RSBaseRenderEngine::RequestFrame(const sptr rsSurface = nullptr; #if (defined RS_ENABLE_GL) && (defined RS_ENABLE_EGLIMAGE) if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { +#ifndef RS_FORCE_DISABLE_OHOS_GL if (forceCPU) { rsSurface = std::make_shared(targetSurface); } else { rsSurface = std::make_shared(targetSurface); } +#else + rsSurface = std::make_shared(targetSurface); +#endif } #endif #if (defined RS_ENABLE_VK) @@ -431,11 +447,16 @@ std::shared_ptr RSBaseRenderEngine::MakeRSSurface(const sptr rsSurface = nullptr; #if (defined RS_ENABLE_GL) && (defined RS_ENABLE_EGLIMAGE) if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { +#ifndef RS_FORCE_DISABLE_OHOS_GL if (forceCPU) { rsSurface = std::make_shared(targetSurface); } else { rsSurface = std::make_shared(targetSurface); } +#else + rsSurface = std::make_shared(targetSurface); +#endif + } #endif #if (defined RS_ENABLE_VK) diff --git a/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp index 6159d69b1d107a67aa105162947e6f62db14e085..2362614b72ec447b14ec096039d46585908b278c 100644 --- a/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_hardware_thread.cpp @@ -406,9 +406,13 @@ std::shared_ptr RSHardwareThread::CreateFrameBufferSurfaceOhos(co { std::shared_ptr rsSurface = nullptr; #if (defined RS_ENABLE_GL) && (defined RS_ENABLE_EGLIMAGE) +#ifndef RS_FORCE_DISABLE_OHOS_GL if (RSSystemProperties::GetGpuApiType() == GpuApiType::OPENGL) { rsSurface = std::make_shared(surface); } +#else + rsSurface = std::make_shared(surface); +#endif #endif #if (defined RS_ENABLE_VK) if (RSSystemProperties::GetGpuApiType() == GpuApiType::VULKAN) { diff --git a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp index 03c27d3fe5ad1375dd6694ad94b22bcfa19ead0e..1954e9a6bc16f8538e6a6f29989fcc19b66a0f97 100644 --- a/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp +++ b/rosen/modules/render_service/core/pipeline/rs_main_thread.cpp @@ -421,12 +421,15 @@ void RSMainThread::Init() Drawing::DrawOpItem::SetTypefaceQueryCallBack(customTypefaceQueryfunc); isUniRender_ = RSUniRenderJudgement::IsUniRender(); + RS_LOGE("---------ruhi---------RSMainThread-1: 0x%{public}08x", (unsigned int)context_.get()); + SetDeviceType(); qosPidCal_ = deviceType_ == DeviceType::PC; isFoldScreenDevice_ = RSSystemProperties::IsFoldScreenFlag(); auto taskDispatchFunc = [](const RSTaskDispatcher::RSTask& task, bool isSyncTask = false) { RSMainThread::Instance()->PostTask(task); }; + RS_LOGE("---------ruhi---------RSMainThread-2: 0x%{public}08x", (unsigned int)context_.get()); context_->SetTaskRunner(taskDispatchFunc); if (isUniRender_) { auto rtTaskDispatchFunc = [](const RSTaskDispatcher::RSTask& task) { @@ -441,6 +444,7 @@ void RSMainThread::Init() RSTaskDispatcher::GetInstance().RegisterTaskDispatchFunc(gettid(), taskDispatchFunc); RsFrameReport::GetInstance().Init(); RSSystemProperties::WatchSystemProperty(HIDE_NOTCH_STATUS, OnHideNotchStatusCallback, nullptr); + RS_LOGE("---------ruhi---------RSMainThread-3: 0x%{public}08x", (unsigned int)context_.get()); if (isUniRender_) { unmarshalBarrierTask_ = [this]() { auto cachedTransactionData = RSUnmarshalThread::Instance().GetCachedTransactionData(); diff --git a/rosen/modules/render_service_base/include/drawable/rs_render_node_drawable_adapter.h b/rosen/modules/render_service_base/include/drawable/rs_render_node_drawable_adapter.h index adc43880e3a159847e3a2390ff8c9f9f20214021..0a16868b3c343c7bb6f4d0f47f291eb42ed594aa 100755 --- a/rosen/modules/render_service_base/include/drawable/rs_render_node_drawable_adapter.h +++ b/rosen/modules/render_service_base/include/drawable/rs_render_node_drawable_adapter.h @@ -26,6 +26,7 @@ #include "recording/recording_canvas.h" #include "pipeline/rs_render_content.h" #include "utils/rect.h" +#include "pipeline/rs_dirty_region_manager.h" #ifndef ROSEN_CROSS_PLATFORM #include diff --git a/rosen/modules/render_service_base/include/pipeline/rs_draw_cmd.h b/rosen/modules/render_service_base/include/pipeline/rs_draw_cmd.h index 4e87cc9cf97c168e53904a11fe24e2948570ea77..96ba1454bdd3dae41b7825ac3b8eff71d5051a44 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_draw_cmd.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_draw_cmd.h @@ -17,12 +17,14 @@ #define RENDER_SERVICE_CLIENT_CORE_PIPELINE_RS_DRAW_CMD_H #ifdef ROSEN_OHOS +#ifdef ACE_ENABLE_GPU #include #include "EGL/egl.h" #include "EGL/eglext.h" #include "GLES2/gl2.h" #include "GLES2/gl2ext.h" #endif +#endif #include "recording/draw_cmd.h" #include "recording/recording_canvas.h" diff --git a/rosen/modules/render_service_base/include/pipeline/rs_render_content.h b/rosen/modules/render_service_base/include/pipeline/rs_render_content.h index 6ef7caff4d3ee599f0157c46d50bf7a42eb8b1fa..c39f825d677a854231cccb5eaa85e2d47aa97d58 100644 --- a/rosen/modules/render_service_base/include/pipeline/rs_render_content.h +++ b/rosen/modules/render_service_base/include/pipeline/rs_render_content.h @@ -15,6 +15,7 @@ #ifndef RENDER_SERVICE_BASE_CORE_PIPELINE_RS_RENDER_CONTENT_H #define RENDER_SERVICE_BASE_CORE_PIPELINE_RS_RENDER_CONTENT_H +#include #include "common/rs_macros.h" #include "memory/rs_dfx_string.h" #include "modifier/rs_render_modifier.h" diff --git a/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn b/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn index b6a152b8a7f9db76387ee0553f8ea561f934b57e..5b2669b76c18e83f5912169a754ae10e6fd607ce 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn +++ b/rosen/modules/render_service_base/src/platform/ohos/BUILD.gn @@ -88,6 +88,9 @@ ohos_source_set("rosen_ohos_sources") { "backend/rs_vulkan_context.cpp", ] } + print("------------------------ace_enable_gpu=") + print(ace_enable_gpu) + if (graphic_2d_feature_enable_opengl) { sources += [ "backend/rs_surface_frame_ohos_gl.cpp", @@ -133,10 +136,15 @@ ohos_source_set("rosen_ohos_sources") { public_deps += [ "$graphic_2d_root:libvulkan", +#### "$graphic_2d_root/frameworks/opengl_wrapper:EGL", +#### "$graphic_2d_root/frameworks/opengl_wrapper:GLESv3", + ] + } + + public_deps += [ "$graphic_2d_root/frameworks/opengl_wrapper:EGL", "$graphic_2d_root/frameworks/opengl_wrapper:GLESv3", ] - } external_deps = [ "c_utils:utils", diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.cpp index 365fcc4ebbc6958145ea5f2dc4a9c0cb18a026ea..b7301cdf528dfdd64f067a4ec32e8709c6a2923b 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.cpp @@ -14,6 +14,7 @@ */ #include "rs_surface_frame_ohos_gl.h" +#ifndef RS_FORCE_DISABLE_OHOS_GL #include "platform/common/rs_log.h" #include "render_context/render_context.h" @@ -79,3 +80,4 @@ void RSSurfaceFrameOhosGl::CreateSurface() } } // namespace Rosen } // namespace OHOS +#endif \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.h b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.h index 3e69fd33d811e5dd6e71507dd111bd72dda0df60..51970033874ba484073a0212d4688dbb55bff519 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.h +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_frame_ohos_gl.h @@ -13,8 +13,11 @@ * limitations under the License. */ -#ifndef RS_SURFACE_FRAME_OHOS_GL_H -#define RS_SURFACE_FRAME_OHOS_GL_H +#ifndef RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_GL_H +#define RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_GL_H + +//#define RS_FORCE_DISABLE_OHOS_GL +#ifndef RS_FORCE_DISABLE_OHOS_GL #include @@ -52,4 +55,5 @@ private: } // namespace Rosen } // namespace OHOS +#endif #endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.cpp b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.cpp index 9ee8341cddf14234087993f4f406453590895873..a7f94de20db711125a8a302bdbc260fe0371f5df 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.cpp @@ -14,6 +14,8 @@ */ #include "rs_surface_ohos_gl.h" +#ifndef RS_FORCE_DISABLE_OHOS_GL + #include "platform/common/rs_log.h" #include "window.h" #include @@ -149,3 +151,5 @@ void RSSurfaceOhosGl::ResetBufferAge() } } // namespace Rosen } // namespace OHOS + +#endif \ No newline at end of file diff --git a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.h b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.h index 11141a09020c9306732ff50ab3654d9f12ce6425..05eb8096920b18e2e548fcc90e9bc186ae8c8e1d 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.h +++ b/rosen/modules/render_service_base/src/platform/ohos/backend/rs_surface_ohos_gl.h @@ -16,6 +16,9 @@ #ifndef RS_SURFACE_OHOS_GL_H #define RS_SURFACE_OHOS_GL_H +//#define RS_FORCE_DISABLE_OHOS_GL +#ifndef RS_FORCE_DISABLE_OHOS_GL + #include #include "platform/drawing/rs_surface.h" @@ -59,4 +62,5 @@ private: } // namespace Rosen } // namespace OHOS +#endif // RS_FORCE_DISABLE_OHOS_GL #endif // RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_OHOS_H diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp index 5c3d5073325d896317c5798b6aa62287125cbaf3..2f216cebb675e3ded700218223a5d41674e4a504 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_render_service_client.cpp @@ -147,9 +147,11 @@ std::shared_ptr RSRenderServiceClient::CreateRSSurface(const sptr(surface); // GPU render } +#endif #endif return std::make_shared(surface); // CPU render } diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_surface_frame_ohos.h b/rosen/modules/render_service_base/src/platform/ohos/rs_surface_frame_ohos.h index 45050ecb74191db831366e12c90262237a0b9dc9..8aaa103f48ff2a3645d267439daa41bdc8a145e1 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_surface_frame_ohos.h +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_surface_frame_ohos.h @@ -14,12 +14,15 @@ */ #ifndef RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H -#define RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H +//#define RENDER_SERVICE_BASE_PLATFORM_RS_SURFACE_FRAME_OHOS_H #include #include "platform/drawing/rs_surface_frame.h" - +// ruhi activate header +#ifdef RS_Sur_frame_OHOS_GL +#error checkHeaderFor Build +#endif namespace OHOS { namespace Rosen { class RenderContext; diff --git a/rosen/modules/render_service_base/src/platform/ohos/rs_surface_ohos_converter.cpp b/rosen/modules/render_service_base/src/platform/ohos/rs_surface_ohos_converter.cpp index 22bbd77288937440bead7c42057eafc1083c2389..aa430d222723f9b9aa0a0b388eaaa396cb90b60a 100644 --- a/rosen/modules/render_service_base/src/platform/ohos/rs_surface_ohos_converter.cpp +++ b/rosen/modules/render_service_base/src/platform/ohos/rs_surface_ohos_converter.cpp @@ -53,10 +53,12 @@ sptr RSSurfaceConverter::ConvertToOhosSurface(std::shared_ptr(surface); // gpu render return derivedPtr->GetSurface(); } +#endif #endif auto derivedPtr = std::static_pointer_cast(surface); // cpu render diff --git a/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp b/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp index 594183476decc1cfe808dbd74199357b3580256e..369e3f357e27b0cb9ae85618d4e58a488e9f80ae 100644 --- a/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp +++ b/rosen/modules/render_service_client/core/pipeline/rs_render_thread.cpp @@ -92,6 +92,7 @@ void SendFrameEvent(bool start) RSRenderThread& RSRenderThread::Instance() { static RSRenderThread renderThread; + ROSEN_LOGE("------------ruhi---------RSRenderThread+ !!"); RSAnimationFraction::Init(); return renderThread; } @@ -229,6 +230,13 @@ int32_t RSRenderThread::GetTid() void RSRenderThread::CreateAndInitRenderContextIfNeed() { +//#if defined(RS_ENABLE_GL) +//#error DEF:RS_ENABLE_GL +//#endif +#if defined(RS_ENABLE_VK) +#error DEF:RS_ENABLE_VK +#endif + #if defined(NEW_RENDER_CONTEXT) #if !defined(ROSEN_PREVIEW) if (renderContext_ == nullptr) { diff --git a/rosen/modules/render_service_client/test/render_service_client_pointer_window_demo.cpp b/rosen/modules/render_service_client/test/render_service_client_pointer_window_demo.cpp index dc0e7deb1d557b3fd348cf51c3858c3de63017d2..0698f704740040f2d1f9445977005d33563673be 100644 --- a/rosen/modules/render_service_client/test/render_service_client_pointer_window_demo.cpp +++ b/rosen/modules/render_service_client/test/render_service_client_pointer_window_demo.cpp @@ -15,7 +15,7 @@ #include -#include "dm/display_manager.h" +#include "display_manager.h" #include "securec.h" #include "draw/canvas.h" @@ -25,30 +25,28 @@ #include "ui/rs_surface_node.h" #include "transaction/rs_interfaces.h" +#include "../../render_service_base/src/platform/ohos/backend/rs_vulkan_context.h" + +#include "EGL/egl.h" +#include "EGL/eglext.h" +#include "GLES3/gl32.h" +#include "utils/log.h" + using namespace OHOS; using namespace OHOS::Rosen; constexpr uint32_t SLEEP_TIME = 3; -constexpr uint32_t POINTER_WIDTH = 100; -constexpr uint32_t POINTER_HEIGHT = 200; +constexpr uint32_t POINTER_WIDTH = 712; +constexpr uint32_t POINTER_HEIGHT = 712; constexpr uint32_t POINTER_WINDOW_INIT_SIZE = 64; std::shared_ptr surfaceNode; uint64_t screenId = 0; -namespace { -void Resize(std::shared_ptr surfaceNode, int32_t width, int32_t height) -{ - width = (width / POINTER_WINDOW_INIT_SIZE + 1) * POINTER_WINDOW_INIT_SIZE; - height = (height / POINTER_WINDOW_INIT_SIZE + 1) * POINTER_WINDOW_INIT_SIZE; - surfaceNode->SetBoundsWidth(width); - surfaceNode->SetBoundsHeight(height); -} +constexpr int32_t EGL_CONTEXT_CLIENT_VERSION_NUM = 2; +EGLDisplay eglDisplay_ = EGL_NO_DISPLAY; +EGLContext eglContext_ = EGL_NO_CONTEXT; -void MoveTo(std::shared_ptr surfaceNode, int32_t x, int32_t y) -{ - surfaceNode->SetBounds( - x, y, surfaceNode->GetStagingProperties().GetBounds().z_, surfaceNode->GetStagingProperties().GetBounds().w_); -} +namespace { sptr GetSurfaceBuffer(sptr ohosSurface, int32_t width, int32_t height) { @@ -69,27 +67,127 @@ sptr GetSurfaceBuffer(sptr ohosSurface, int32_t width, i return buffer; } +static void InitEGL() +{ + LOGI("Creating EGLContext!!!"); + eglDisplay_ = eglGetDisplay(static_cast(EGL_DEFAULT_DISPLAY)); + if (eglDisplay_ == EGL_NO_DISPLAY) { + LOGW("Failed to create EGLDisplay gl errno : %{public}x", eglGetError()); + return; + } + + EGLint major, minor; + if (eglInitialize(eglDisplay_, &major, &minor) == EGL_FALSE) { + LOGE("Failed to initialize EGLDisplay"); + return; + } + + if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) { + LOGE("Failed to bind OpenGL ES API"); + return; + } + + unsigned int ret; + EGLConfig config; + EGLint count; + EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT, EGL_NONE }; + + ret = eglChooseConfig(eglDisplay_, configAttribs, &config, 1, &count); + if (!(ret && static_cast(count) >= 1)) { + LOGE("Failed to eglChooseConfig"); + return; + } + + static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, EGL_CONTEXT_CLIENT_VERSION_NUM, EGL_NONE }; + + eglContext_ = eglCreateContext(eglDisplay_, config, EGL_NO_CONTEXT, contextAttribs); + if (eglContext_ == EGL_NO_CONTEXT) { + LOGE("Failed to create egl context %{public}x", eglGetError()); + return; + } + if (!eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, eglContext_)) { + LOGE("Failed to make current on surface, error is %{public}x", eglGetError()); + return; + } + + LOGI("Create EGL context successfully, version %{public}d.%{public}d", major, minor); +} + +void DestroyEGL() +{ + if (eglDisplay_ == EGL_NO_DISPLAY) { + return; + } + + eglDestroyContext(eglDisplay_, eglContext_); + eglMakeCurrent(eglDisplay_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglTerminate(eglDisplay_); + eglReleaseThread(); + + eglDisplay_ = EGL_NO_DISPLAY; + eglContext_ = EGL_NO_CONTEXT; +} + void DoDraw(uint8_t* addr, uint32_t width, uint32_t height) { Drawing::Bitmap bitmap; Drawing::BitmapFormat format { Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_OPAQUE }; bitmap.Build(width, height, format); - Drawing::Canvas canvas; - canvas.Bind(bitmap); - canvas.Clear(Drawing::Color::COLOR_GREEN); + Drawing::Canvas canvas2; + canvas2.Bind(bitmap); + +// VVR + Drawing::GPUContextOptions contextOps; + auto context = std::make_shared(); + std::cout << "context" << std::endl; + /* + bool isSuccess = context->BuildFromVK(RsVulkanContext::GetSingleton().GetGrVkBackendContext(), contextOps); + if (!isSuccess) { + std::cout << "context->BuildFromVK Return FALSE" << std::endl; + return; + } + std::cout << "context->BuildFromVK Return TRUE" << std::endl; + */ + + InitEGL(); + bool isSuccess = context->BuildFromGL(contextOps); + if (!isSuccess) { + std::cout << "context->BuildFromGL Return FALSE" << std::endl; + return; + } + std::cout << "context->BuildFromGL Return TRUE" << std::endl; + + + Drawing::ImageInfo info = Drawing::ImageInfo { width, height, Drawing::COLORTYPE_RGBA_8888, Drawing::ALPHATYPE_PREMUL }; + std::shared_ptr surface_ = Drawing::Surface::MakeRenderTarget(context.get(), false, info); + auto canvas = std::make_shared(surface_.get()); +// VVR + + //canvas->Clear(Drawing::Color::COLOR_YELLOW); Drawing::Pen pen; pen.SetAntiAlias(true); - pen.SetColor(Drawing::Color::COLOR_RED); - Drawing::scalar penWidth = 1; - pen.SetWidth(penWidth); - canvas.AttachPen(pen); - Drawing::Point startPt(10, 10); - Drawing::Point endPt(50, 50); - canvas.DrawLine(startPt, endPt); + pen.SetColor(Drawing::Color::COLOR_BLACK); + pen.SetWidth(1); + canvas->AttachPen(pen); + Drawing::Path path; + path.MoveTo(65, 162.5); + path.QuadTo(650, 325, 650, 65); + canvas->DrawPath(path); + +//VVR + auto samplingOptions = Drawing::SamplingOptions(Drawing::FilterMode::LINEAR, Drawing::MipmapMode::LINEAR); + auto image_ = surface_->GetImageSnapshot(); + canvas2.DrawImage(*image_, 0.f, 0.f, samplingOptions); +//VVR + static constexpr uint32_t stride = 4; uint32_t addrSize = width * height * stride; memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize); + + + DestroyEGL(); } void InitSurfaceStyle(std::shared_ptr surfaceNode) @@ -123,7 +221,6 @@ bool InitSurface() RSSurfaceNodeType surfaceNodeType = RSSurfaceNodeType::SELF_DRAWING_WINDOW_NODE; std::cout << "RSSurfaceNode::Create" <SetPositionZ(RSSurfaceNode::POINTER_WINDOW_POSITION_Z); int width = (POINTER_WIDTH / POINTER_WINDOW_INIT_SIZE + 1) * POINTER_WINDOW_INIT_SIZE; int height = (POINTER_HEIGHT / POINTER_WINDOW_INIT_SIZE + 1) * POINTER_WINDOW_INIT_SIZE; - surfaceNode->SetBounds(100, 300, width, height); - surfaceNode->SetBackgroundColor(SK_ColorGREEN); + surfaceNode->SetBounds(100, 712, width, height); + surfaceNode->SetBackgroundColor(SK_ColorYELLOW); // Attach RSSurfaceNode to RSDisplayNode through dms // DisplayManager::GetInstance().AddSurfaceNodeToDisplay(displayId, surfaceNode); @@ -147,7 +244,7 @@ bool InitSurface() std::cout << "RSTranscation::FlushImplicitTransaction" << std::endl; RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); + //sleep(SLEEP_TIME); return true; } @@ -169,51 +266,14 @@ int main() std::cout << "rs pointer window demo stage 1 Init" << std::endl; InitSurface(); - // Attach and Detach - std::cout << "rs pointer window demo stage 2 Detach" << std::endl; - surfaceNode->DetachToDisplay(screenId); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - std::cout << "rs pointer window demo stage 2 Attach" << std::endl; - surfaceNode->AttachToDisplay(screenId); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - - // Resize - std::cout << "rs pointer window demo stage 3 Resize" << std::endl; - Resize(surfaceNode, POINTER_WIDTH / 2, POINTER_HEIGHT / 2); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - // SetStyle std::cout << "rs pointer window demo stage 4 SetStyle" << std::endl; InitSurfaceStyle(surfaceNode); RSTransaction::FlushImplicitTransaction(); sleep(SLEEP_TIME); - // Hide - std::cout << "rs pointer window demo stage 5 Hide" << std::endl; - surfaceNode->SetVisible(false); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - // Show - std::cout << "rs pointer window demo stage 6 Show" << std::endl; - surfaceNode->SetVisible(true); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - std::cout << "rs pointer window demo stage MoveTo" << std::endl; while (isRemote) { - // while (true) { - // MoveTo - MoveTo(surfaceNode, 0, 0); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - MoveTo(surfaceNode, 100, 160); - RSTransaction::FlushImplicitTransaction(); - sleep(SLEEP_TIME); - MoveTo(surfaceNode, 320, 640); - RSTransaction::FlushImplicitTransaction(); sleep(SLEEP_TIME); while (!isRemote) { std::cout << "ReInitSurface" << std::endl;