blob: 7306934b9ac647ad5fac10d6fbc4af6927847fe2 [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"
12
reed@google.com97af1a62012-08-28 12:19:02 +000013// Call this if you explicitly want to use/share this pixelRef in the image
reed4af267b2014-11-21 08:46:37 -080014extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, size_t rowBytes,
15 const SkSurfaceProps*);
reed@google.com889b09e2012-07-27 21:10:42 +000016
17/**
18 * Examines the bitmap to decide if it can share the existing pixelRef, or
reed@google.com97af1a62012-08-28 12:19:02 +000019 * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will
20 * be shared if either the bitmap is marked as immutable, or canSharePixelRef
21 * is true.
22 *
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000023 * If the bitmap's colortype cannot be converted into a corresponding
reed@google.com2bd8b812013-11-01 13:46:54 +000024 * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
reed@google.com97af1a62012-08-28 12:19:02 +000025 * NULL.
reed@google.com889b09e2012-07-27 21:10:42 +000026 */
reed4af267b2014-11-21 08:46:37 -080027extern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef, const SkSurfaceProps*);
reed@google.com889b09e2012-07-27 21:10:42 +000028
reed@google.com2bd8b812013-11-01 13:46:54 +000029static inline size_t SkImageMinRowBytes(const SkImageInfo& info) {
reed@google.com9230ea22013-12-09 22:01:03 +000030 return SkAlign4(info.minRowBytes());
reed@google.com889b09e2012-07-27 21:10:42 +000031}
32
reed@google.com97af1a62012-08-28 12:19:02 +000033// Given an image created from SkNewImageFromBitmap, return its pixelref. This
34// may be called to see if the surface and the image share the same pixelref,
35// in which case the surface may need to perform a copy-on-write.
piotaixr65151752014-10-16 11:58:39 -070036extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
reed@google.com97af1a62012-08-28 12:19:02 +000037
robertphillips@google.com97b6b072012-10-31 14:48:39 +000038// Given an image created with NewTexture, return its GrTexture. This
39// may be called to see if the surface and the image share the same GrTexture,
40// in which case the surface may need to perform a copy-on-write.
junov@chromium.org45c3db82013-04-11 17:52:05 +000041extern GrTexture* SkTextureImageGetTexture(SkImage* textureImage);
robertphillips@google.com97b6b072012-10-31 14:48:39 +000042
43// Update the texture wrapped by an image created with NewTexture. This
44// is called when a surface and image share the same GrTexture and the
45// surface needs to perform a copy-on-write
46extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
47
reed3f10b9d2014-11-21 10:27:53 -080048extern SkImage* SkNewImageFromBitmapTexture(const SkBitmap&, int sampleCountForNewSurfaces);
reed4af267b2014-11-21 08:46:37 -080049
reed@google.com889b09e2012-07-27 21:10:42 +000050#endif