158b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com/* 258b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com * Copyright 2012 Google Inc. 358b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com * 458b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com * Use of this source code is governed by a BSD-style license that can be 558b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com * found in the LICENSE file. 658b21ec7f06cfa8b7d7403a6108c0216345b3510reed@google.com */ 7889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 8889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com#ifndef SkImagePriv_DEFINED 9889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com#define SkImagePriv_DEFINED 10889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 11889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com#include "SkImage.h" 12889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 1397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com// Call this if you explicitly want to use/share this pixelRef in the image 14e13af711d4ff9031c9ed3054a4c33a56a0c62e1fcommit-bot@chromium.orgextern SkImage* SkNewImageFromPixelRef(const SkImageInfo&, SkPixelRef*, 15e13af711d4ff9031c9ed3054a4c33a56a0c62e1fcommit-bot@chromium.org size_t rowBytes); 16889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 17889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com/** 18889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com * Examines the bitmap to decide if it can share the existing pixelRef, or 1997af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com * if it needs to make a deep-copy of the pixels. The bitmap's pixelref will 2097af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com * be shared if either the bitmap is marked as immutable, or canSharePixelRef 2197af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com * is true. 2297af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com * 23a3264e53ee3f3c5d6a2c813df7e44b5b96d207f2commit-bot@chromium.org * If the bitmap's colortype cannot be converted into a corresponding 242bd8b8100529c96c81c30f749f672f4caf775b04reed@google.com * SkImageInfo, or the bitmap's pixels cannot be accessed, this will return 2597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com * NULL. 26889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com */ 2797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comextern SkImage* SkNewImageFromBitmap(const SkBitmap&, bool canSharePixelRef); 28889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 292bd8b8100529c96c81c30f749f672f4caf775b04reed@google.comstatic inline size_t SkImageMinRowBytes(const SkImageInfo& info) { 309230ea29718bcf1a92a89a1a518fb896bbbe00cfreed@google.com return SkAlign4(info.minRowBytes()); 31889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com} 32889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com 3397af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com// Given an image created from SkNewImageFromBitmap, return its pixelref. This 3497af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com// may be called to see if the surface and the image share the same pixelref, 3597af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com// in which case the surface may need to perform a copy-on-write. 3697af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.comextern SkPixelRef* SkBitmapImageGetPixelRef(SkImage* rasterImage); 3797af1a64ae6bdddd346d8babfd9f188279dd6644reed@google.com 3897b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// Given an image created with NewTexture, return its GrTexture. This 3997b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// may be called to see if the surface and the image share the same GrTexture, 4097b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// in which case the surface may need to perform a copy-on-write. 4145c3db827d5bcb7c08bf49eff035be667332ec05junov@chromium.orgextern GrTexture* SkTextureImageGetTexture(SkImage* textureImage); 4297b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com 4397b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// Update the texture wrapped by an image created with NewTexture. This 4497b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// is called when a surface and image share the same GrTexture and the 4597b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com// surface needs to perform a copy-on-write 4697b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.comextern void SkTextureImageSetTexture(SkImage* image, GrTexture* texture); 4797b6b0730dcb0feee9224ff04eb3985ca4bd0216robertphillips@google.com 48889b09edfeb5f461ca283dfd08ee6b23560a7859reed@google.com#endif 49