blob: 525223cf7773470025de2981d4f43d57cd4d3202 [file] [log] [blame]
bsalomonc55271f2015-11-09 11:55:57 -08001/*
2 * Copyright 2015 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#include "GrImageIDTextureAdjuster.h"
9
10#include "SkBitmap.h"
11#include "SkGrPriv.h"
12#include "SkImage_Base.h"
13
14
15GrBitmapTextureAdjuster::GrBitmapTextureAdjuster(const SkBitmap* bmp)
16 : INHERITED(bmp->getTexture(), SkIRect::MakeWH(bmp->width(), bmp->height()))
17 , fBmp(bmp) {}
18
19void GrBitmapTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
20 if (fBmp->isVolatile()) {
21 return;
22 }
23 // The content area must represent the whole bitmap. Texture-backed bitmaps don't support
24 // extractSubset(). Therefore, either the bitmap and the texture are the same size or the
25 // content's dimensions are the bitmap's dimensions which is pinned to the upper left
26 // of the texture.
27 GrUniqueKey baseKey;
28 GrMakeKeyFromImageID(&baseKey, fBmp->getGenerationID(),
29 SkIRect::MakeWH(fBmp->width(), fBmp->height()));
30 MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
31}
32
33void GrBitmapTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) {
34 GrInstallBitmapUniqueKeyInvalidator(copyKey, fBmp->pixelRef());
35}
36
37//////////////////////////////////////////////////////////////////////////////
38
39GrImageTextureAdjuster::GrImageTextureAdjuster(const SkImage_Base* img)
40 : INHERITED(img->peekTexture(), SkIRect::MakeWH(img->width(), img->height()))
41 , fImageBase(img) {}
42
43void GrImageTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
44 // By construction this texture adjuster always represents an entire SkImage, so use the
45 // image's width and height for the key's rectangle.
46 GrUniqueKey baseKey;
47 GrMakeKeyFromImageID(&baseKey, fImageBase->uniqueID(),
48 SkIRect::MakeWH(fImageBase->width(), fImageBase->height()));
49 MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
50}
51
52void GrImageTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) {
53 // We don't currently have a mechanism for notifications on Images!
54}