1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2008 The Android Open Source Project
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#ifndef SkMallocPixelRef_DEFINED
9cb93a386Sopenharmony_ci#define SkMallocPixelRef_DEFINED
10cb93a386Sopenharmony_ci
11cb93a386Sopenharmony_ci#include "include/core/SkPixelRef.h"
12cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h"
13cb93a386Sopenharmony_ci#include "include/core/SkTypes.h"
14cb93a386Sopenharmony_ciclass SkData;
15cb93a386Sopenharmony_cistruct SkImageInfo;
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ci/** We explicitly use the same allocator for our pixels that SkMask does,
18cb93a386Sopenharmony_ci    so that we can freely assign memory allocated by one class to the other.
19cb93a386Sopenharmony_ci*/
20cb93a386Sopenharmony_cinamespace SkMallocPixelRef {
21cb93a386Sopenharmony_ci    /**
22cb93a386Sopenharmony_ci     *  Return a new SkMallocPixelRef, automatically allocating storage for the
23cb93a386Sopenharmony_ci     *  pixels. If rowBytes are 0, an optimal value will be chosen automatically.
24cb93a386Sopenharmony_ci     *  If rowBytes is > 0, then it will be respected, or NULL will be returned
25cb93a386Sopenharmony_ci     *  if rowBytes is invalid for the specified info.
26cb93a386Sopenharmony_ci     *
27cb93a386Sopenharmony_ci     *  All pixel bytes are zeroed.
28cb93a386Sopenharmony_ci     *
29cb93a386Sopenharmony_ci     *  Returns NULL on failure.
30cb93a386Sopenharmony_ci     */
31cb93a386Sopenharmony_ci    SK_API sk_sp<SkPixelRef> MakeAllocate(const SkImageInfo&, size_t rowBytes);
32cb93a386Sopenharmony_ci
33cb93a386Sopenharmony_ci    /**
34cb93a386Sopenharmony_ci     *  Return a new SkMallocPixelRef that will use the provided SkData and
35cb93a386Sopenharmony_ci     *  rowBytes as pixel storage.  The SkData will be ref()ed and on
36cb93a386Sopenharmony_ci     *  destruction of the PixelRef, the SkData will be unref()ed.
37cb93a386Sopenharmony_ci     *
38cb93a386Sopenharmony_ci     *  Returns NULL on failure.
39cb93a386Sopenharmony_ci     */
40cb93a386Sopenharmony_ci    SK_API sk_sp<SkPixelRef> MakeWithData(const SkImageInfo&, size_t rowBytes, sk_sp<SkData> data);
41cb93a386Sopenharmony_ci}  // namespace SkMallocPixelRef
42cb93a386Sopenharmony_ci#endif
43