chromium/ui/wm/core/cursor_util.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "ui/wm/core/cursor_util.h"

#include <cfloat>
#include <memory>
#include <optional>

#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "cc/paint/skottie_wrapper.h"
#include "skia/ext/image_operations.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/cursor_size.h"
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/resource/resource_scale_factor.h"
#include "ui/display/display_transform.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/geometry/transform.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_rep.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/lottie/animation.h"
#include "ui/resources/grit/ui_resources.h"

namespace wm {

namespace {

CursorType;

AnimationCache;

// Get a cache for lottie animations.
AnimationCache& GetAnimationCache() {}

// Converts the SkBitmap to use a different alpha type. Returns true if bitmap
// was modified, otherwise returns false.
bool ConvertSkBitmapAlphaType(SkBitmap* bitmap, SkAlphaType alpha_type) {}

// Only rotate the cursor's hotpoint. |hotpoint_in_out| is used as
// both input and output. |cursor_bitmap_width| and |cursor_bitmap_height|
// should be the width and height of the cursor before bitmap rotation.
void RotateCursorHotpoint(display::Display::Rotation rotation,
                          int cursor_bitmap_width,
                          int cursor_bitmap_height,
                          gfx::Point* hotpoint_in_out) {}

// Rotate the cursor's bitmap and hotpoint.
// |bitmap_in_out| and |hotpoint_in_out| are used as
// both input and output.
void RotateCursorBitmapAndHotpoint(display::Display::Rotation rotation,
                                   SkBitmap* bitmap_in_out,
                                   gfx::Point* hotpoint_in_out) {}

// Create bitmaps from bitmap pixels. |image_rep| has a scale and holds
// bitmap pixels for that scale.
void CreateBitmapsFromPixels(const gfx::ImageSkiaRep& image_rep,
                             float scale,
                             display::Display::Rotation rotation,
                             bool is_animated,
                             std::vector<SkBitmap>* bitmaps_out,
                             gfx::Point* hotspot_in_out) {}

// Create bitmaps from static lottie. |image_rep| is unscaled and contains
// a paint record for the lottie animation.
void CreateBitmapsFromStaticLottie(const gfx::ImageSkiaRep& image_rep,
                                   const gfx::Size& scaled_size,
                                   float scale,
                                   const gfx::Transform& rotation_transform,
                                   std::vector<SkBitmap>* bitmaps_out) {}

// Create bitmaps from animated lottie.
void CreateBitmapsFromAnimatedLottie(int resource_id,
                                     const gfx::Size& scaled_size,
                                     float scale,
                                     const gfx::Transform& rotation_transform,
                                     CursorType type,
                                     std::vector<SkBitmap>* bitmaps_out) {}

struct CursorResourceData {};

// Cursor resource data indexed by CursorType. Make sure to respect the order
// defined at ui/base/cursor/mojom/cursor_type.mojom.
constexpr std::optional<CursorResourceData> kNormalCursorResourceData[] =;

static_assert;

constexpr std::optional<CursorResourceData> kLargeCursorResourceData[] =;

static_assert;

}  // namespace

std::optional<ui::CursorData> GetCursorData(
    CursorType type,
    ui::CursorSize size,
    float scale,
    std::optional<int> target_cursor_size_in_px,
    display::Display::Rotation rotation) {}

void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
                                           display::Display::Rotation rotation,
                                           SkBitmap* bitmap,
                                           gfx::Point* hotpoint) {}

bool GetCursorDataFor(ui::CursorSize cursor_size,
                      CursorType type,
                      float scale_factor,
                      int* resource_id,
                      gfx::Point* point,
                      bool* is_animated) {}

}  // namespace wm