skia2/src/core/SkPixmapPriv.h
Mike Klein 334a642b20 remove unused sk_sp comparison operators
These unused comparison operators are the only users of
<functional> in SkRefCnt.h, for std::less.  <functional>
is an expensive header to compile, and SkRefCnt.h is popular,
so it helps to cut dependencies like this.

Mostly we just need to add #include <functional> in a few
places that were picking it up via SkRefCnt.h.

In SkPixmapPriv.h, it looked simpler to template the argument,
since everything was inline anyway.

Change-Id: I7c125bb26a04199847357c729a1b178256c6ef8d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/236942
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
2019-08-27 14:52:01 +00:00

66 lines
1.9 KiB
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkPixmapPriv_DEFINED
#define SkPixmapPriv_DEFINED
#include "include/codec/SkEncodedOrigin.h"
#include "include/core/SkPixmap.h"
#include "src/core/SkAutoPixmapStorage.h"
class SkPixmapPriv {
public:
/**
* Copy the pixels in this pixmap into dst, applying the orientation transformations specified
* by the flags. If the inputs are invalid, this returns false and no copy is made.
*/
static bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin);
static bool ShouldSwapWidthHeight(SkEncodedOrigin o);
static SkImageInfo SwapWidthHeight(const SkImageInfo& info);
/**
* Decode an image and then copy into dst, applying origin.
*
* @param dst SkPixmap to write the final image, after
* applying the origin.
* @param origin SkEncodedOrigin to apply to the raw pixels.
* @param decode Function for decoding into a pixmap without
* applying the origin.
*/
template <typename Fn>
static bool Orient(const SkPixmap& dst, SkEncodedOrigin origin, Fn&& decode) {
SkAutoPixmapStorage storage;
const SkPixmap* tmp = &dst;
if (origin != kTopLeft_SkEncodedOrigin) {
auto info = dst.info();
if (ShouldSwapWidthHeight(origin)) {
info = SwapWidthHeight(info);
}
if (!storage.tryAlloc(info)) {
return false;
}
tmp = &storage;
}
if (!decode(*tmp)) {
return false;
}
if (tmp != &dst) {
return Orient(dst, *tmp, origin);
}
return true;
}
static void ResetPixmapKeepInfo(SkPixmap* pm, const void* address, size_t rowBytes) {
pm->fRowBytes = rowBytes;
pm->fPixels = address;
}
};
#endif