blob: 2e800195d7dc02020cca61cdf073bfbdcd5b1055 [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
reed1ec04d92016-08-05 12:07:41 -070014enum SkCopyPixelsMode {
15 kIfMutable_SkCopyPixelsMode, //!< only copy src pixels if they are marked mutable
16 kAlways_SkCopyPixelsMode, //!< always copy src pixels (even if they are marked immutable)
17 kNever_SkCopyPixelsMode, //!< never copy src pixels (even if they are marked mutable)
18};
19
Herb Derby78c0c4c2017-02-14 11:14:16 -050020// A good size for creating shader contexts on the stack.
caryclark8a65fc82016-08-15 08:44:46 -070021enum {kSkBlitterContextSize = 3332};
reed4c1abdc2016-08-05 14:50:19 -070022
reed4c1abdc2016-08-05 14:50:19 -070023// If alloc is non-nullptr, it will be used to allocate the returned SkShader, and MUST outlive
24// the SkShader.
25sk_sp<SkShader> SkMakeBitmapShader(const SkBitmap& src, SkShader::TileMode, SkShader::TileMode,
Herb Derbybfdc87a2017-02-14 15:06:23 +000026 const SkMatrix* localMatrix, SkCopyPixelsMode);
reed4c1abdc2016-08-05 14:50:19 -070027
reed@google.com889b09e2012-07-27 21:10:42 +000028/**
29 * Examines the bitmap to decide if it can share the existing pixelRef, or
fmalita9a5d1ab2015-07-27 10:27:28 -070030 * if it needs to make a deep-copy of the pixels.
31 *
32 * The bitmap's pixelref will be shared if either the bitmap is marked as
reed1ec04d92016-08-05 12:07:41 -070033 * immutable, or CopyPixelsMode allows it. Shared pixel refs are also
fmalita9a5d1ab2015-07-27 10:27:28 -070034 * locked when kLocked_SharedPixelRefMode is specified.
35 *
36 * Passing kLocked_SharedPixelRefMode allows the image's peekPixels() method
37 * to succeed, but it will force any lazy decodes/generators to execute if
38 * they exist on the pixelref.
reed@google.com97af1a62012-08-28 12:19:02 +000039 *
reed56179002015-07-07 06:11:19 -070040 * It is illegal to call this with a texture-backed bitmap.
41 *
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000042 * If the bitmap's colortype cannot be converted into a corresponding
reed@google.com2bd8b812013-11-01 13:46:54 +000043 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
halcanary96fcdcc2015-08-27 07:41:13 -070044 * nullptr.
reed@google.com889b09e2012-07-27 21:10:42 +000045 */
Herb Derbybfdc87a2017-02-14 15:06:23 +000046extern sk_sp<SkImage> SkMakeImageFromRasterBitmap(const SkBitmap&, SkCopyPixelsMode);
reed@google.com889b09e2012-07-27 21:10:42 +000047
reed@google.com97af1a62012-08-28 12:19:02 +000048// Given an image created from SkNewImageFromBitmap, return its pixelref. This
49// may be called to see if the surface and the image share the same pixelref,
50// in which case the surface may need to perform a copy-on-write.
piotaixr65151752014-10-16 11:58:39 -070051extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
reed@google.com97af1a62012-08-28 12:19:02 +000052
reed2d5b7142016-08-17 11:12:33 -070053/**
54 * Will attempt to upload and lock the contents of the image as a texture, so that subsequent
55 * draws to a gpu-target will come from that texture (and not by looking at the original image
56 * src). In particular this is intended to use the texture even if the image's original content
57 * changes subsequent to this call (i.e. the src is mutable!).
58 *
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -050059 * All successful calls must be balanced by an equal number of calls to SkImage_unpinAsTexture().
reed2d5b7142016-08-17 11:12:33 -070060 *
61 * Once in this "pinned" state, the image has all of the same thread restrictions that exist
62 * for a natively created gpu image (e.g. SkImage::MakeFromTexture)
63 * - all drawing, pinning, unpinning must happen in the same thread as the GrContext.
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -050064 *
65 * @return true if the image was successfully uploaded and locked into a texture
reed2d5b7142016-08-17 11:12:33 -070066 */
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -050067bool SkImage_pinAsTexture(const SkImage*, GrContext*);
reed2d5b7142016-08-17 11:12:33 -070068
69/**
Derek Sollenbergerd3ea9b72016-11-09 11:25:13 -050070 * The balancing call to a successful invokation of SkImage_pinAsTexture. When a balanced number of
71 * calls have been made, then the "pinned" texture is free to be purged, etc. This also means that a
72 * subsequent "pin" call will look at the original content again, and if its uniqueID/generationID
73 * has changed, then a newer texture will be uploaded/pinned.
reed2d5b7142016-08-17 11:12:33 -070074 *
75 * The context passed to unpin must match the one passed to pin.
76 */
77void SkImage_unpinAsTexture(const SkImage*, GrContext*);
78
Brian Osman0d4ff6c2017-01-17 16:10:07 -050079/**
80 * Returns a new image containing the same pixel values as the source, but with a different color
81 * space assigned. This performs no color space conversion. Primarily used in tests, to visualize
82 * the results of rendering in wide or narrow gamuts.
83 */
84sk_sp<SkImage> SkImageMakeRasterCopyAndAssignColorSpace(const SkImage*, SkColorSpace*);
85
reed@google.com889b09e2012-07-27 21:10:42 +000086#endif