OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const SkIRect* subset) { | 57 const SkIRect* subset) { |
58 if (NULL == texture || kUnknown_SkColorType == dstCT) { | 58 if (NULL == texture || kUnknown_SkColorType == dstCT) { |
59 return NULL; | 59 return NULL; |
60 } | 60 } |
61 GrContext* context = texture->getContext(); | 61 GrContext* context = texture->getContext(); |
62 if (NULL == context) { | 62 if (NULL == context) { |
63 return NULL; | 63 return NULL; |
64 } | 64 } |
65 GrTextureDesc desc; | 65 GrTextureDesc desc; |
66 | 66 |
67 SkIPoint pointStorage; | 67 SkIRect srcRect; |
68 SkIPoint* topLeft; | 68 |
69 if (subset != NULL) { | 69 if (!subset) { |
| 70 desc.fWidth = texture->width(); |
| 71 desc.fHeight = texture->height(); |
| 72 srcRect = SkIRect::MakeWH(texture->width(), texture->height()); |
| 73 } else { |
70 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); | 74 SkASSERT(SkIRect::MakeWH(texture->width(), texture->height()).contains(*
subset)); |
71 // Create a new texture that is the size of subset. | 75 // Create a new texture that is the size of subset. |
72 desc.fWidth = subset->width(); | 76 desc.fWidth = subset->width(); |
73 desc.fHeight = subset->height(); | 77 desc.fHeight = subset->height(); |
74 pointStorage.set(subset->x(), subset->y()); | 78 srcRect = *subset; |
75 topLeft = &pointStorage; | |
76 } else { | |
77 desc.fWidth = texture->width(); | |
78 desc.fHeight = texture->height(); | |
79 topLeft = NULL; | |
80 } | 79 } |
81 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 80 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
82 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); | 81 desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType); |
83 | 82 |
84 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); | 83 GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); |
85 if (NULL == dst) { | 84 if (NULL == dst) { |
86 return NULL; | 85 return NULL; |
87 } | 86 } |
88 | 87 |
89 context->copyTexture(texture, dst->asRenderTarget(), topLeft); | |
90 | |
91 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source | 88 // Blink is relying on the above copy being sent to GL immediately in the ca
se when the source |
92 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h, but we have a | 89 // is a WebGL canvas backing store. We could have a TODO to remove this flus
h flag, but we have |
93 // larger TODO to remove SkGrPixelRef entirely. | 90 // a larger TODO to remove SkGrPixelRef entirely. |
94 context->flush(); | 91 context->copySurface(dst->asRenderTarget(), texture, srcRect, SkIPoint::Make
(0,0), |
95 | 92 GrContext::kFlushWrites_PixelOp); |
| 93 |
96 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); | 94 SkImageInfo info = SkImageInfo::Make(desc.fWidth, desc.fHeight, dstCT, kPrem
ul_SkAlphaType); |
97 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); | 95 SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (info, dst)); |
98 SkSafeUnref(dst); | 96 SkSafeUnref(dst); |
99 return pixelRef; | 97 return pixelRef; |
100 } | 98 } |
101 | 99 |
102 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
103 | 101 |
104 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, | 102 SkGrPixelRef::SkGrPixelRef(const SkImageInfo& info, GrSurface* surface, |
105 bool transferCacheLock) : INHERITED(info) { | 103 bool transferCacheLock) : INHERITED(info) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 cachedBitmap.setImmutable(); | 197 cachedBitmap.setImmutable(); |
200 //Add to the cache | 198 //Add to the cache |
201 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); | 199 SkBitmapCache::Add(this->getGenerationID(), bounds, cachedBitmap); |
202 | 200 |
203 dst->swap(cachedBitmap); | 201 dst->swap(cachedBitmap); |
204 } | 202 } |
205 | 203 |
206 return true; | 204 return true; |
207 | 205 |
208 } | 206 } |
OLD | NEW |