blob: acd0beb475bdd679b3257f8d5dcfd350d7f93e38 [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
kkinnunen73953e72015-02-23 22:12:12 -080015extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
16 const SkIPoint& pixelRefOrigin,
reedaf3fbfc2015-10-04 11:28:36 -070017 size_t rowBytes);
reed@google.com889b09e2012-07-27 21:10:42 +000018
19/**
20 * Examines the bitmap to decide if it can share the existing pixelRef, or
fmalita9a5d1ab2015-07-27 10:27:28 -070021 * if it needs to make a deep-copy of the pixels.
22 *
23 * The bitmap's pixelref will be shared if either the bitmap is marked as
24 * immutable, or forceSharePixelRef is true. Shared pixel refs are also
25 * locked when kLocked_SharedPixelRefMode is specified.
26 *
27 * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method
28 * to succeed, but it will force any lazy decodes/generators to execute if
29 * they exist on the pixelref.
reed@google.com97af1a62012-08-28 12:19:02 +000030 *
reed56179002015-07-07 06:11:19 -070031 * It is illegal to call this with a texture-backed bitmap.
32 *
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000033 * If the bitmap's colortype cannot be converted into a corresponding
reed@google.com2bd8b812013-11-01 13:46:54 +000034 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
halcanary96fcdcc2015-08-27 07:41:13 -070035 * nullptr.
reed@google.com889b09e2012-07-27 21:10:42 +000036 */
reed26e0e582015-07-29 11:44:52 -070037enum ForceCopyMode {
38 kNo_ForceCopyMode,
39 kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable
40};
reedaf3fbfc2015-10-04 11:28:36 -070041extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, ForceCopyMode = kNo_ForceCopyMode);
reed@google.com889b09e2012-07-27 21:10:42 +000042
reed@google.com97af1a62012-08-28 12:19:02 +000043// Given an image created from SkNewImageFromBitmap, return its pixelref. This
44// may be called to see if the surface and the image share the same pixelref,
45// in which case the surface may need to perform a copy-on-write.
piotaixr65151752014-10-16 11:58:39 -070046extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
reed@google.com97af1a62012-08-28 12:19:02 +000047
bsalomoneaaaf0b2015-01-23 08:08:04 -080048// When a texture is shared by a surface and an image its budgeted status is that of the
49// surface. This function is used when the surface makes a new texture for itself in order
50// for the orphaned image to determine whether the original texture counts against the
51// budget or not.
52extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage);
53
robertphillips@google.com97b6b072012-10-31 14:48:39 +000054// Update the texture wrapped by an image created with NewTexture. This
55// is called when a surface and image share the same GrTexture and the
56// surface needs to perform a copy-on-write
57extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
58
bsalomon5ec26ae2016-02-25 08:33:02 -080059GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted);
reed56179002015-07-07 06:11:19 -070060
reed@google.com889b09e2012-07-27 21:10:42 +000061#endif