wms自绘制不再依赖RenderContext

Signed-off-by: xingyanan <xingyanan2@huawei.com>
Change-Id: Idee2234c1ccaf6371db50d9ff864fed8e2359ab2
Signed-off-by: xingyanan <xingyanan2@huawei.com>
This commit is contained in:
xingyanan
2022-07-05 11:54:53 +08:00
parent c2159aaca7
commit b2438fc05d
7 changed files with 103 additions and 148 deletions
-6
View File
@@ -12,7 +12,6 @@
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
config("libwmutil_private_config") {
include_dirs = [
"include",
@@ -20,10 +19,6 @@ config("libwmutil_private_config") {
"../interfaces/innerkits/dm",
"../interfaces/innerkits/wm",
]
defines = []
# Get gpu defines
defines += gpu_defines
}
config("libwmutil_public_config") {
@@ -55,7 +50,6 @@ ohos_shared_library("libwmutil") {
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
"//third_party/flutter/build/skia:ace_skia_ohos",
]
external_deps = [
+11 -8
View File
@@ -31,20 +31,23 @@ class SurfaceDraw {
public:
SurfaceDraw() = default;
~SurfaceDraw() = default;
static bool DrawColor(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode, int32_t bufferWidth,
static bool DrawColor(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, uint32_t color);
static bool DrawImage(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode, int32_t bufferWidth,
static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, const std::string& imagePath);
static bool DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
sptr<Media::PixelMap> pixelMap, uint32_t bkgColor);
static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, std::shared_ptr<Media::PixelMap> pixelMap);
static bool DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect, sptr<Media::PixelMap> pixelMap,
uint32_t bkgColor);
private:
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath);
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color);
static sptr<OHOS::Surface> GetLayer(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode);
static sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer,
int32_t bufferWidth, int32_t bufferHeight);
static void DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath);
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap);
static sptr<OHOS::Surface> GetLayer(std::shared_ptr<RSSurfaceNode> surfaceNode);
static sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer, int32_t bufferWidth,
int32_t bufferHeight);
static void DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath);
static std::unique_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath);
static bool DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight, sptr<Media::PixelMap> pixelMap,
uint32_t color);
+83 -21
View File
@@ -32,7 +32,7 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SurfaceDraw"};
} // namespace
bool SurfaceDraw::DrawImage(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode, int32_t bufferWidth,
bool SurfaceDraw::DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, const std::string& imagePath)
{
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
@@ -63,7 +63,38 @@ bool SurfaceDraw::DrawImage(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceN
return true;
}
bool SurfaceDraw::DrawColor(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode, int32_t bufferWidth,
bool SurfaceDraw::DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, std::shared_ptr<Media::PixelMap> pixelMap)
{
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
if (layer == nullptr) {
WLOGFE("layer is nullptr");
return false;
}
sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight);
if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
return false;
}
auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), pixelMap)) {
WLOGE("draw window pixel failed");
return false;
}
OHOS::BufferFlushConfig flushConfig = {
.damage = {
.w = buffer->GetWidth(),
.h = buffer->GetHeight(),
},
};
OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig);
if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) {
WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
return false;
}
return true;
}
bool SurfaceDraw::DrawColor(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
int32_t bufferHeight, uint32_t color)
{
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
@@ -94,7 +125,7 @@ bool SurfaceDraw::DrawColor(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceN
return true;
}
sptr<OHOS::Surface> SurfaceDraw::GetLayer(std::shared_ptr<OHOS::Rosen::RSSurfaceNode> surfaceNode)
sptr<OHOS::Surface> SurfaceDraw::GetLayer(std::shared_ptr<RSSurfaceNode> surfaceNode)
{
if (surfaceNode == nullptr) {
return nullptr;
@@ -145,17 +176,17 @@ std::unique_ptr<OHOS::Media::PixelMap> SurfaceDraw::DecodeImageToPixelMap(const
return pixelMap;
}
void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::string& imagePath)
void SurfaceDraw::DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath)
{
std::unique_ptr<OHOS::Media::PixelMap> pixelmap = DecodeImageToPixelMap(imagePath);
if (pixelmap == nullptr) {
WLOGFE("drawing pixel map is nullptr");
return;
}
OHOS::Rosen::Drawing::Pen pen;
Drawing::Pen pen;
pen.SetAntiAlias(true);
pen.SetColor(OHOS::Rosen::Drawing::Color::COLOR_BLUE);
OHOS::Rosen::Drawing::scalar penWidth = 1;
pen.SetColor(Drawing::Color::COLOR_BLUE);
Drawing::scalar penWidth = 1;
pen.SetWidth(penWidth);
canvas.AttachPen(pen);
canvas.DrawBitmap(*pixelmap, 0, 0);
@@ -163,13 +194,13 @@ void SurfaceDraw::DrawPixelmap(OHOS::Rosen::Drawing::Canvas &canvas, const std::
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath)
{
OHOS::Rosen::Drawing::Bitmap bitmap;
OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888,
OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE };
Drawing::Bitmap bitmap;
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
Drawing::AlphaType::ALPHATYPE_OPAQUE };
bitmap.Build(width, height, format);
OHOS::Rosen::Drawing::Canvas canvas;
Drawing::Canvas canvas;
canvas.Bind(bitmap);
canvas.Clear(OHOS::Rosen::Drawing::Color::COLOR_TRANSPARENT);
canvas.Clear(Drawing::Color::COLOR_TRANSPARENT);
DrawPixelmap(canvas, imagePath);
static constexpr uint32_t stride = 4;
uint32_t addrSize = width * height * stride;
@@ -181,13 +212,44 @@ bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const s
return true;
}
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap)
{
Drawing::Bitmap bitmap;
Drawing::Canvas canvas;
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_OPAQUE };
bitmap.Build(width, height, format);
canvas.Bind(bitmap);
canvas.Clear(Drawing::Color::COLOR_TRANSPARENT);
Drawing::Image image;
Drawing::Bitmap imageBitmap;
Drawing::SamplingOptions sampling = Drawing::SamplingOptions(Drawing::FilterMode::NEAREST,
Drawing::MipmapMode::NEAREST);
imageBitmap.Build(pixelMap->GetWidth(), pixelMap->GetHeight(), format);
imageBitmap.SetPixels(const_cast<uint8_t*>(pixelMap->GetPixels()));
image.BuildFromBitmap(imageBitmap);
Drawing::Rect dst(0, 0, width, height);
Drawing::Rect src(0, 0, pixelMap->GetWidth(), pixelMap->GetHeight());
canvas.DrawImageRect(image, src, dst, sampling);
static constexpr uint32_t stride = 4;
uint32_t addrSize = width * height * stride;
errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
if (ret != EOK) {
WLOGFE("draw failed");
return false;
}
return true;
}
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color)
{
OHOS::Rosen::Drawing::Bitmap bitmap;
OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888,
OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE };
Drawing::Bitmap bitmap;
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
Drawing::AlphaType::ALPHATYPE_OPAQUE };
bitmap.Build(width, height, format);
OHOS::Rosen::Drawing::Canvas canvas;
Drawing::Canvas canvas;
canvas.Bind(bitmap);
canvas.Clear(color);
@@ -237,11 +299,11 @@ bool SurfaceDraw::DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect
bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight,
sptr<Media::PixelMap> pixelMap, uint32_t color)
{
OHOS::Rosen::Drawing::Bitmap bitmap;
OHOS::Rosen::Drawing::BitmapFormat format { OHOS::Rosen::Drawing::ColorType::COLORTYPE_RGBA_8888,
OHOS::Rosen::Drawing::AlphaType::ALPHATYPE_OPAQUE };
Drawing::Bitmap bitmap;
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
Drawing::AlphaType::ALPHATYPE_OPAQUE };
bitmap.Build(winWidth, winHeight, format);
OHOS::Rosen::Drawing::Canvas canvas;
Drawing::Canvas canvas;
canvas.Bind(bitmap);
canvas.Clear(color);
if (pixelMap == nullptr) {
@@ -251,7 +313,7 @@ bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHe
uint32_t iconHeight = pixelMap->GetHeight();
uint32_t iconWidth = pixelMap->GetWidth();
Drawing::Image image;
OHOS::Rosen::Drawing::Bitmap iconBitmap;
Drawing::Bitmap iconBitmap;
iconBitmap.Build(iconWidth, iconHeight, format);
iconBitmap.SetPixels(const_cast<uint8_t*>(pixelMap->GetPixels()));
image.BuildFromBitmap(iconBitmap);
-8
View File
@@ -12,9 +12,6 @@
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
## Build libwms.so
config("libwms_config") {
visibility = [ ":*" ]
@@ -29,10 +26,6 @@ config("libwms_config") {
"//foundation/windowmanager/dm/include",
"//foundation/windowmanager/dmserver/include",
]
defines = []
# Get gpu defines
defines += gpu_defines
}
ohos_shared_library("libwms") {
@@ -80,7 +73,6 @@ ohos_shared_library("libwms") {
"//foundation/windowmanager/dmserver:libdms",
"//foundation/windowmanager/utils:libwmutil",
"//foundation/windowmanager/wm:libwm",
"//third_party/flutter/build/skia:ace_skia_ohos",
"//third_party/libxml2:xml2",
]
+2 -16
View File
@@ -17,14 +17,7 @@
#define OHOS_ROSEN_FREEZE_CONTROLLER_H
#include <refbase.h>
#include <include/core/SkBitmap.h>
#include <pixel_map.h>
#ifdef ACE_ENABLE_GL
#include <render_context/render_context.h>
#endif
#include <transaction/rs_transaction.h>
#include <ui/rs_surface_extractor.h>
#include <map>
#include "display.h"
#include "window.h"
@@ -33,7 +26,7 @@ namespace OHOS {
namespace Rosen {
class FreezeController : public RefBase {
public:
FreezeController() {};
FreezeController() = default;
~FreezeController() = default;
bool FreezeDisplay(DisplayId displayId);
@@ -41,14 +34,7 @@ public:
private:
sptr<Window> CreateCoverWindow(DisplayId displayId);
SkImageInfo MakeSkImageInfoFromPixelMap(std::shared_ptr<Media::PixelMap>& pixmap);
bool DrawSkImage(std::shared_ptr<RSSurface>& rsSurface,
uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap);
std::map<DisplayId, sptr<Window>> coverWindowMap_;
#ifdef ACE_ENABLE_GL
std::unique_ptr<RenderContext> renderContext_;
#endif
};
}
}
+6 -88
View File
@@ -17,11 +17,9 @@
#include <securec.h>
#include <include/codec/SkCodec.h>
#include <include/core/SkCanvas.h>
#include <include/core/SkImage.h>
#include "display_manager_service_inner.h"
#include "pixel_map.h"
#include "surface_draw.h"
#include "window_manager_hilog.h"
#include "window_option.h"
#include "wm_common.h"
@@ -44,39 +42,13 @@ bool FreezeController::FreezeDisplay(DisplayId displayId)
WLOGFE("Show window failed");
return false;
}
#ifdef ACE_ENABLE_GL
if (renderContext_ == nullptr) {
renderContext_ = std::make_unique<RenderContext>();
renderContext_->InitializeEglContext();
}
#endif
std::shared_ptr<RSSurfaceNode> surfaceNode = window->GetSurfaceNode();
if (surfaceNode == nullptr) {
WLOGFE("RSSurfaceNode is null");
return false;
}
Rect winRect = window->GetRect();
WLOGFI("freeze window rect, x : %{public}d, y : %{public}d, width: %{public}u, height: %{public}u",
winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
std::shared_ptr<RSSurface> rsSurface = RSSurfaceExtractor::ExtractRSSurface(surfaceNode);
if (rsSurface == nullptr) {
WLOGFE("RSSurface is null");
return false;
}
#ifdef ACE_ENABLE_GL
rsSurface->SetRenderContext(renderContext_.get());
#endif
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManagerServiceInner::GetInstance().GetDisplaySnapshot(displayId);
if (pixelMap == nullptr) {
WLOGE("freeze display fail, pixel map is null. display %{public}" PRIu64"", displayId);
return false;
}
return DrawSkImage(rsSurface, winRect.width_, winRect.height_, pixelMap);
return SurfaceDraw::DrawImage(window->GetSurfaceNode(), window->GetRect().width_,
window->GetRect().height_, pixelMap);
}
bool FreezeController::UnfreezeDisplay(DisplayId displayId)
@@ -113,59 +85,5 @@ sptr<Window> FreezeController::CreateCoverWindow(DisplayId displayId)
coverWindowMap_[displayId] = window;
return window;
}
bool FreezeController::DrawSkImage(std::shared_ptr<RSSurface>& rsSurface,
uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelmap)
{
// Get canvas
WLOGFD("start to draw bitmap");
std::unique_ptr<RSSurfaceFrame> frame = rsSurface->RequestFrame(width, height);
if (frame == nullptr) {
WLOGFE("fail to request frame");
return false;
}
auto canvas = frame->GetCanvas();
if (canvas == nullptr) {
WLOGFE("fail to get canvas");
return false;
}
canvas->clear(SK_ColorTRANSPARENT);
// Create SkPixmap from PixelMap
auto imageInfo = MakeSkImageInfoFromPixelMap(pixelmap);
SkPixmap imagePixmap(imageInfo, reinterpret_cast<const void*>(pixelmap->GetPixels()), pixelmap->GetRowBytes());
// Create SkImage from SkPixmap
sk_sp<SkImage> skImage = SkImage::MakeFromRaster(imagePixmap, nullptr, nullptr);
if (!skImage) {
WLOGFE("sk image is null");
return false;
}
SkPaint paint;
sk_sp<SkColorSpace> colorSpace = skImage->refColorSpace();
#ifdef USE_SYSTEM_SKIA
paint.setColor4f(paint.getColor4f(), colorSpace.get());
#else
paint.setColor(paint.getColor4f(), colorSpace.get());
#endif
auto skSrcRect = SkRect::MakeXYWH(0, 0, pixelmap->GetWidth(), pixelmap->GetHeight());
auto skDstRect = SkRect::MakeXYWH(0, 0, width, height);
canvas->drawImageRect(skImage, skSrcRect, skDstRect, &paint);
frame->SetDamageRegion(0, 0, width, height);
if (!rsSurface->FlushFrame(frame)) {
WLOGFE("fail to flush frame");
return false;
}
return true;
}
SkImageInfo FreezeController::MakeSkImageInfoFromPixelMap(std::shared_ptr<Media::PixelMap>& pixmap)
{
SkColorType colorType = kN32_SkColorType;
SkAlphaType alphaType = SkAlphaType::kOpaque_SkAlphaType;
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
return SkImageInfo::Make(pixmap->GetWidth(), pixmap->GetHeight(), colorType, alphaType, colorSpace);
}
}
}
} // Rosen
} // OHOS
@@ -515,7 +515,7 @@ Rect WindowLayoutPolicyCascade::GetCurCascadeRect(const sptr<WindowNode>& node)
(*iter)->GetWindowId() != node->GetWindowId()) {
auto property = (*iter)->GetWindowProperty();
if (property != nullptr) {
cascadeRect = property->GetRequestRect();
cascadeRect = property->GetWindowRect();
}
WLOGFI("Get current cascadeRect: %{public}u [%{public}d, %{public}d, %{public}u, %{public}u]",
(*iter)->GetWindowId(), cascadeRect.posX_, cascadeRect.posY_,