• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
7 
8 #ifndef SkImagePriv_DEFINED
9 #define SkImagePriv_DEFINED
10 
11 #include "SkImage.h"
12 #include "SkSurface.h"
13 
14 // Call this if you explicitly want to use/share this pixelRef in the image
15 extern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*,
16                                        const SkIPoint& pixelRefOrigin,
17                                        size_t rowBytes);
18 
19 /**
20  *  Examines the bitmap to decide if it can share the existing pixelRef, or
21  *  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.
30  *
31  *  It is illegal to call this with a texture-backed bitmap.
32  *
33  *  If the bitmap's colortype cannot be converted into a corresponding
34  *  SkImageInfo, or the bitmap's pixels cannot be accessed, this will return
35  *  nullptr.
36  */
37 enum ForceCopyMode {
38     kNo_ForceCopyMode,
39     kYes_ForceCopyMode, // must copy the pixels even if the bitmap is immutable
40 };
41 extern SkImage* SkNewImageFromRasterBitmap(const SkBitmap&, ForceCopyMode = kNo_ForceCopyMode);
42 
43 // 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.
46 extern const SkPixelRef* SkBitmapImageGetPixelRef(const SkImage* rasterImage);
47 
48 // 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.
52 extern void SkTextureImageApplyBudgetedDecision(SkImage* textureImage);
53 
54 // 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
57 extern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture);
58 
59 GrTexture* GrDeepCopyTexture(GrTexture* src, SkBudgeted);
60 
61 #endif
62