blob: ed40996acd0a1e31e5e3a547961011382df738d9 [file] [log] [blame]
reed@google.com58b21ec2012-07-30 18:20:12 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@google.com889b09e2012-07-27 21:10:42 +00007
8#ifndef SkImagePriv_DEFINED
9#define SkImagePriv_DEFINED
10
reed@google.com889b09e2012-07-27 21:10:42 +000011#include "SkImage.h"
bsalomoneaaaf0b2015-01-23 08:08:04 -080012#include "SkSurface.h"
reed@google.com889b09e2012-07-27 21:10:42 +000013
reed@google.com97af1a62012-08-28 12:19:02 +000014// Call this if you explicitly want to use/share this pixelRef in the image
reed7fb4f8b2016-03-11 04:33:52 -080015extern sk_sp<SkImage> SkMakeImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
16 const SkIPoint& pixelRefOrigin,
17 size_t rowBytes);
reed@google.com889b09e2012-07-27 21:10:42 +000018
reed1ec04d92016-08-05 12:07:41 -070019enum SkCopyPixelsMode {
20 kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked mutable
21 kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are marked immutable)
22 kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are marked mutable)
23};
24
reed@google.com889b09e2012-07-27 21:10:42 +000025/**
26 * Examines the bitmap to decide if it can share the existing pixelRef, or
fmalita9a5d1ab2015-07-27 10:27:28 -070027 * if it needs to make a deep-copy of the pixels.
28 *
29 * The bitmap's pixelref will be shared if either the bitmap is marked as
reed1ec04d92016-08-05 12:07:41 -070030 * immutable, or CopyPixelsMode allows it. Shared pixel refs are also
fmalita9a5d1ab2015-07-27 10:27:28 -070031 * locked when kLocked_SharedPixelRefMode is specified.
32 *
33 * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method
34 * to succeed, but it will force any lazy decodes/generators to execute if
35 * they exist on the pixelref.
reed@google.com97af1a62012-08-28 12:19:02 +000036 *
reed56179002015-07-07 06:11:19 -070037 * It is illegal to call this with a texture-backed bitmap.
38 *
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000039 * If the bitmap's colortype cannot be converted into a corresponding
reed@google.com2bd8b812013-11-01 13:46:54 +000040 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
halcanary96fcdcc2015-08-27 07:41:13 -070041 * nullptr.
reed@google.com889b09e2012-07-27 21:10:42 +000042 */
reed1ec04d92016-08-05 12:07:41 -070043extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode);
reed@google.com889b09e2012-07-27 21:10:42 +000044
reed@google.com97af1a62012-08-28 12:19:02 +000045// Given an image created from SkNewImageFromBitmap, return its pixelref. This
46// may be called to see if the surface and the image share the same pixelref,
47// in which case the surface may need to perform a copy-on-write.
piotaixr65151752014-10-16 11:58:39 -070048extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
reed@google.com97af1a62012-08-28 12:19:02 +000049
bsalomoneaaaf0b2015-01-23 08:08:04 -080050// When a texture is shared by a surface and an image its budgeted status is that of the
51// surface. This function is used when the surface makes a new texture for itself in order
52// for the orphaned image to determine whether the original texture counts against the
53// budget or not.
54extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage);
55
robertphillips@google.com97b6b072012-10-31 14:48:39 +000056// Update the texture wrapped by an image created with NewTexture. This
57// is called when a surface and image share the same GrTexture and the
58// surface needs to perform a copy-on-write
59extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
60
bsalomon5ec26ae2016-02-25 08:33:02 -080061GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted);
reed56179002015-07-07 06:11:19 -070062
reed@google.com889b09e2012-07-27 21:10:42 +000063#endif