SkMallocPixelRef: remove MakeDirect and MakeWithProc from API.
Not currently used by any clients. Change-Id: I21d554fb95ffef4f317945ab22c4cfb14fbb6b2a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/234660 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
a28a6959c0
commit
bb108480ec
@ -18,15 +18,6 @@ struct SkImageInfo;
|
|||||||
so that we can freely assign memory allocated by one class to the other.
|
so that we can freely assign memory allocated by one class to the other.
|
||||||
*/
|
*/
|
||||||
namespace SkMallocPixelRef {
|
namespace SkMallocPixelRef {
|
||||||
/**
|
|
||||||
* Return a new SkMallocPixelRef with the provided pixel storage and
|
|
||||||
* rowBytes. The caller is responsible for managing the lifetime of the
|
|
||||||
* pixel storage buffer, as this pixelref will not try to delete it.
|
|
||||||
*
|
|
||||||
* Returns NULL on failure.
|
|
||||||
*/
|
|
||||||
SK_API sk_sp<SkPixelRef> MakeDirect(const SkImageInfo&, void* addr, size_t rowBytes);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new SkMallocPixelRef, automatically allocating storage for the
|
* Return a new SkMallocPixelRef, automatically allocating storage for the
|
||||||
* pixels. If rowBytes are 0, an optimal value will be chosen automatically.
|
* pixels. If rowBytes are 0, an optimal value will be chosen automatically.
|
||||||
@ -39,21 +30,6 @@ namespace SkMallocPixelRef {
|
|||||||
*/
|
*/
|
||||||
SK_API sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes);
|
SK_API sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes);
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a new SkMallocPixelRef with the provided pixel storage and
|
|
||||||
* rowBytes. On destruction, ReleaseProc will be called.
|
|
||||||
*
|
|
||||||
* If ReleaseProc is NULL, the pixels will never be released. This
|
|
||||||
* can be useful if the pixels were stack allocated. However, such an
|
|
||||||
* SkMallocPixelRef must not live beyond its pixels (e.g. by copying
|
|
||||||
* an SkBitmap pointing to it, or drawing to an SkPicture).
|
|
||||||
*
|
|
||||||
* Returns NULL on failure.
|
|
||||||
*/
|
|
||||||
using ReleaseProc = void (*)(void* addr, void* context);
|
|
||||||
SK_API sk_sp<SkPixelRef> MakeWithProc(const SkImageInfo& info, size_t rowBytes, void* addr,
|
|
||||||
ReleaseProc proc, void* context);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a new SkMallocPixelRef that will use the provided SkData and
|
* Return a new SkMallocPixelRef that will use the provided SkData and
|
||||||
* rowBytes as pixel storage. The SkData will be ref()ed and on
|
* rowBytes as pixel storage. The SkData will be ref()ed and on
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "src/core/SkConvertPixels.h"
|
#include "src/core/SkConvertPixels.h"
|
||||||
#include "src/core/SkMask.h"
|
#include "src/core/SkMask.h"
|
||||||
#include "src/core/SkMaskFilterBase.h"
|
#include "src/core/SkMaskFilterBase.h"
|
||||||
|
#include "src/core/SkPixelRefPriv.h"
|
||||||
#include "src/core/SkPixmapPriv.h"
|
#include "src/core/SkPixmapPriv.h"
|
||||||
#include "src/core/SkReadBuffer.h"
|
#include "src/core/SkReadBuffer.h"
|
||||||
#include "src/core/SkWriteBuffer.h"
|
#include "src/core/SkWriteBuffer.h"
|
||||||
@ -202,11 +203,8 @@ void SkBitmap::setPixels(void* p) {
|
|||||||
this->setPixelRef(nullptr, 0, 0);
|
this->setPixelRef(nullptr, 0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this->setPixelRef(
|
||||||
this->setPixelRef(SkMallocPixelRef::MakeDirect(this->info(), p, this->rowBytes()), 0, 0);
|
sk_make_sp<SkPixelRef>(this->width(), this->height(), p, this->rowBytes()), 0, 0);
|
||||||
if (!fPixelRef) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SkDEBUGCODE(this->validate();)
|
SkDEBUGCODE(this->validate();)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,15 +317,9 @@ bool SkBitmap::installPixels(const SkImageInfo& requestedInfo, void* pixels, siz
|
|||||||
|
|
||||||
// setInfo may have corrected info (e.g. 565 is always opaque).
|
// setInfo may have corrected info (e.g. 565 is always opaque).
|
||||||
const SkImageInfo& correctedInfo = this->info();
|
const SkImageInfo& correctedInfo = this->info();
|
||||||
|
this->setPixelRef(
|
||||||
sk_sp<SkPixelRef> pr = SkMallocPixelRef::MakeWithProc(correctedInfo, rb, pixels,
|
SkMakePixelRefWithProc(correctedInfo.width(), correctedInfo.height(),
|
||||||
releaseProc, context);
|
rb, pixels, releaseProc, context), 0, 0);
|
||||||
if (!pr) {
|
|
||||||
this->reset();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setPixelRef(std::move(pr), 0, 0);
|
|
||||||
SkDEBUGCODE(this->validate();)
|
SkDEBUGCODE(this->validate();)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -40,16 +40,6 @@ static bool is_valid(const SkImageInfo& info) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkPixelRef> SkMallocPixelRef::MakeDirect(const SkImageInfo& info,
|
|
||||||
void* addr,
|
|
||||||
size_t rowBytes) {
|
|
||||||
if (!is_valid(info)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return sk_make_sp<SkPixelRef>(info.width(), info.height(), addr, rowBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sk_sp<SkPixelRef> SkMallocPixelRef::MakeAllocate(const SkImageInfo& info, size_t rowBytes) {
|
sk_sp<SkPixelRef> SkMallocPixelRef::MakeAllocate(const SkImageInfo& info, size_t rowBytes) {
|
||||||
if (rowBytes == 0) {
|
if (rowBytes == 0) {
|
||||||
rowBytes = info.minRowBytes();
|
rowBytes = info.minRowBytes();
|
||||||
@ -78,33 +68,6 @@ sk_sp<SkPixelRef> SkMallocPixelRef::MakeAllocate(const SkImageInfo& info, size_t
|
|||||||
return sk_sp<SkPixelRef>(new PixelRef(info.width(), info.height(), addr, rowBytes));
|
return sk_sp<SkPixelRef>(new PixelRef(info.width(), info.height(), addr, rowBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithProc(const SkImageInfo& info,
|
|
||||||
size_t rowBytes,
|
|
||||||
void* addr,
|
|
||||||
SkMallocPixelRef::ReleaseProc proc,
|
|
||||||
void* context) {
|
|
||||||
if (!is_valid(info)) {
|
|
||||||
if (proc) {
|
|
||||||
proc(addr, context);
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct PixelRef final : public SkPixelRef {
|
|
||||||
SkMallocPixelRef::ReleaseProc fReleaseProc;
|
|
||||||
void* fReleaseProcContext;
|
|
||||||
PixelRef(int w, int h, void* s, size_t r, SkMallocPixelRef::ReleaseProc proc, void* ctx)
|
|
||||||
: SkPixelRef(w, h, s, r), fReleaseProc(proc), fReleaseProcContext(ctx) {}
|
|
||||||
~PixelRef() override {
|
|
||||||
if (fReleaseProc) {
|
|
||||||
fReleaseProc(this->pixels(), fReleaseProcContext);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return sk_sp<SkPixelRef>(new PixelRef(info.width(), info.height(), addr, rowBytes,
|
|
||||||
proc, context));
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
|
sk_sp<SkPixelRef> SkMallocPixelRef::MakeWithData(const SkImageInfo& info,
|
||||||
size_t rowBytes,
|
size_t rowBytes,
|
||||||
sk_sp<SkData> data) {
|
sk_sp<SkData> data) {
|
||||||
|
@ -9,7 +9,9 @@
|
|||||||
#include "include/private/SkMutex.h"
|
#include "include/private/SkMutex.h"
|
||||||
#include "src/core/SkBitmapCache.h"
|
#include "src/core/SkBitmapCache.h"
|
||||||
#include "src/core/SkNextID.h"
|
#include "src/core/SkNextID.h"
|
||||||
|
#include "src/core/SkPixelRefPriv.h"
|
||||||
#include "src/core/SkTraceEvent.h"
|
#include "src/core/SkTraceEvent.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
uint32_t SkNextID::ImageID() {
|
uint32_t SkNextID::ImageID() {
|
||||||
@ -132,3 +134,19 @@ void SkPixelRef::restoreMutability() {
|
|||||||
SkASSERT(fMutability != kImmutable);
|
SkASSERT(fMutability != kImmutable);
|
||||||
fMutability = kMutable;
|
fMutability = kMutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sk_sp<SkPixelRef> SkMakePixelRefWithProc(int width, int height, size_t rowBytes, void* addr,
|
||||||
|
void (*releaseProc)(void* addr, void* ctx), void* ctx) {
|
||||||
|
SkASSERT(width >= 0 && height >= 0);
|
||||||
|
if (nullptr == releaseProc) {
|
||||||
|
return sk_make_sp<SkPixelRef>(width, height, addr, rowBytes);
|
||||||
|
}
|
||||||
|
struct PixelRef final : public SkPixelRef {
|
||||||
|
void (*fReleaseProc)(void*, void*);
|
||||||
|
void* fReleaseProcContext;
|
||||||
|
PixelRef(int w, int h, void* s, size_t r, void (*proc)(void*, void*), void* ctx)
|
||||||
|
: SkPixelRef(w, h, s, r), fReleaseProc(proc), fReleaseProcContext(ctx) {}
|
||||||
|
~PixelRef() override { fReleaseProc(this->pixels(), fReleaseProcContext); }
|
||||||
|
};
|
||||||
|
return sk_sp<SkPixelRef>(new PixelRef(width, height, addr, rowBytes, releaseProc, ctx));
|
||||||
|
}
|
||||||
|
20
src/core/SkPixelRefPriv.h
Normal file
20
src/core/SkPixelRefPriv.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2019 Google LLC.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef SkPixelRefPriv_DEFINED
|
||||||
|
#define SkPixelRefPriv_DEFINED
|
||||||
|
/**
|
||||||
|
* Return a new SkMallocPixelRef with the provided pixel storage and
|
||||||
|
* rowBytes. On destruction, ReleaseProc will be called.
|
||||||
|
*
|
||||||
|
* If ReleaseProc is NULL, the pixels will never be released. This
|
||||||
|
* can be useful if the pixels were stack allocated. However, such an
|
||||||
|
* SkMallocPixelRef must not live beyond its pixels (e.g. by copying
|
||||||
|
* an SkBitmap pointing to it, or drawing to an SkPicture).
|
||||||
|
*
|
||||||
|
* Returns NULL on failure.
|
||||||
|
*/
|
||||||
|
sk_sp<SkPixelRef> SkMakePixelRefWithProc(int w, int h, size_t rowBytes, void* addr,
|
||||||
|
void (*releaseProc)(void* addr, void* ctx), void* ctx);
|
||||||
|
|
||||||
|
#endif // SkPixelRefPriv_DEFINED
|
@ -8,6 +8,7 @@
|
|||||||
#include "include/core/SkData.h"
|
#include "include/core/SkData.h"
|
||||||
#include "include/core/SkMallocPixelRef.h"
|
#include "include/core/SkMallocPixelRef.h"
|
||||||
#include "src/core/SkAutoMalloc.h"
|
#include "src/core/SkAutoMalloc.h"
|
||||||
|
#include "src/core/SkPixelRefPriv.h"
|
||||||
#include "tests/Test.h"
|
#include "tests/Test.h"
|
||||||
|
|
||||||
static void delete_uint8_proc(void* ptr, void*) {
|
static void delete_uint8_proc(void* ptr, void*) {
|
||||||
@ -52,8 +53,7 @@ DEF_TEST(MallocPixelRef, reporter) {
|
|||||||
size_t size = info.computeByteSize(rowBytes) + 9;
|
size_t size = info.computeByteSize(rowBytes) + 9;
|
||||||
{
|
{
|
||||||
SkAutoMalloc memory(size);
|
SkAutoMalloc memory(size);
|
||||||
sk_sp<SkPixelRef> pr(
|
auto pr = sk_make_sp<SkPixelRef>(info.width(), info.height(), memory.get(), rowBytes);
|
||||||
SkMallocPixelRef::MakeDirect(info, memory.get(), rowBytes));
|
|
||||||
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
||||||
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
|
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
|
||||||
}
|
}
|
||||||
@ -66,7 +66,8 @@ DEF_TEST(MallocPixelRef, reporter) {
|
|||||||
{
|
{
|
||||||
void* addr = static_cast<void*>(new uint8_t[size]);
|
void* addr = static_cast<void*>(new uint8_t[size]);
|
||||||
sk_sp<SkPixelRef> pr(
|
sk_sp<SkPixelRef> pr(
|
||||||
SkMallocPixelRef::MakeWithProc(info, rowBytes, addr, delete_uint8_proc, nullptr));
|
SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, addr, delete_uint8_proc,
|
||||||
|
nullptr));
|
||||||
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
||||||
REPORTER_ASSERT(reporter, addr == pr->pixels());
|
REPORTER_ASSERT(reporter, addr == pr->pixels());
|
||||||
}
|
}
|
||||||
@ -74,9 +75,8 @@ DEF_TEST(MallocPixelRef, reporter) {
|
|||||||
int x = 0;
|
int x = 0;
|
||||||
SkAutoMalloc memory(size);
|
SkAutoMalloc memory(size);
|
||||||
sk_sp<SkPixelRef> pr(
|
sk_sp<SkPixelRef> pr(
|
||||||
SkMallocPixelRef::MakeWithProc(info, rowBytes,
|
SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, memory.get(),
|
||||||
memory.get(), set_to_one_proc,
|
set_to_one_proc, static_cast<void*>(&x)));
|
||||||
static_cast<void*>(&x)));
|
|
||||||
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
REPORTER_ASSERT(reporter, pr.get() != nullptr);
|
||||||
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
|
REPORTER_ASSERT(reporter, memory.get() == pr->pixels());
|
||||||
REPORTER_ASSERT(reporter, 0 == x);
|
REPORTER_ASSERT(reporter, 0 == x);
|
||||||
@ -84,23 +84,12 @@ DEF_TEST(MallocPixelRef, reporter) {
|
|||||||
// make sure that set_to_one_proc was called.
|
// make sure that set_to_one_proc was called.
|
||||||
REPORTER_ASSERT(reporter, 1 == x);
|
REPORTER_ASSERT(reporter, 1 == x);
|
||||||
}
|
}
|
||||||
{
|
|
||||||
int x = 0;
|
|
||||||
SkAutoMalloc memory(size);
|
|
||||||
sk_sp<SkPixelRef> pr(
|
|
||||||
SkMallocPixelRef::MakeWithProc(SkImageInfo::MakeN32Premul(-1, -1), rowBytes,
|
|
||||||
memory.get(), set_to_one_proc,
|
|
||||||
static_cast<void*>(&x)));
|
|
||||||
REPORTER_ASSERT(reporter, pr.get() == nullptr);
|
|
||||||
// make sure that set_to_one_proc was called.
|
|
||||||
REPORTER_ASSERT(reporter, 1 == x);
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
void* addr = static_cast<void*>(new uint8_t[size]);
|
void* addr = static_cast<void*>(new uint8_t[size]);
|
||||||
REPORTER_ASSERT(reporter, addr != nullptr);
|
REPORTER_ASSERT(reporter, addr != nullptr);
|
||||||
sk_sp<SkPixelRef> pr(
|
sk_sp<SkPixelRef> pr(
|
||||||
SkMallocPixelRef::MakeWithProc(info, rowBytes, addr,
|
SkMakePixelRefWithProc(info.width(), info.height(), rowBytes, addr, delete_uint8_proc,
|
||||||
delete_uint8_proc, nullptr));
|
nullptr));
|
||||||
REPORTER_ASSERT(reporter, addr == pr->pixels());
|
REPORTER_ASSERT(reporter, addr == pr->pixels());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user