Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: src/image/SkImage.cpp

Issue 1166993002: Towards removing getTexture() from SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
11 #include "SkImagePriv.h" 11 #include "SkImagePriv.h"
12 #include "SkImage_Base.h" 12 #include "SkImage_Base.h"
13 #include "SkReadPixelsRec.h" 13 #include "SkReadPixelsRec.h"
14 #include "SkString.h" 14 #include "SkString.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 #if SK_SUPPORT_GPU
17 #include "GrTexture.h"
18 #include "GrContext.h"
19 #endif
16 20
17 uint32_t SkImage::NextUniqueID() { 21 uint32_t SkImage::NextUniqueID() {
18 static int32_t gUniqueID; 22 static int32_t gUniqueID;
19 23
20 // never return 0; 24 // never return 0;
21 uint32_t id; 25 uint32_t id;
22 do { 26 do {
23 id = sk_atomic_inc(&gUniqueID) + 1; 27 id = sk_atomic_inc(&gUniqueID) + 1;
24 } while (0 == id); 28 } while (0 == id);
25 return id; 29 return id;
(...skipping 13 matching lines...) Expand all
39 43
40 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes, 44 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes,
41 int srcX, int srcY) const { 45 int srcX, int srcY) const {
42 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY); 46 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
43 if (!rec.trim(this->width(), this->height())) { 47 if (!rec.trim(this->width(), this->height())) {
44 return false; 48 return false;
45 } 49 }
46 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec. fX, rec.fY); 50 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec. fX, rec.fY);
47 } 51 }
48 52
49 GrTexture* SkImage::getTexture() const {
50 return as_IB(this)->onGetTexture();
51 }
52
53 SkShader* SkImage::newShader(SkShader::TileMode tileX, 53 SkShader* SkImage::newShader(SkShader::TileMode tileX,
54 SkShader::TileMode tileY, 54 SkShader::TileMode tileY,
55 const SkMatrix* localMatrix) const { 55 const SkMatrix* localMatrix) const {
56 return as_IB(this)->onNewShader(tileX, tileY, localMatrix); 56 return as_IB(this)->onNewShader(tileX, tileY, localMatrix);
57 } 57 }
58 58
59 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 59 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
60 SkBitmap bm; 60 SkBitmap bm;
61 if (as_IB(this)->getROPixels(&bm)) { 61 if (as_IB(this)->getROPixels(&bm)) {
62 return SkImageEncoder::EncodeData(bm, type, quality); 62 return SkImageEncoder::EncodeData(bm, type, quality);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 } 102 }
103 } 103 }
104 104
105 if (NULL == subset && this->width() == newWidth && this->height() == newHeig ht) { 105 if (NULL == subset && this->width() == newWidth && this->height() == newHeig ht) {
106 return SkRef(const_cast<SkImage*>(this)); 106 return SkRef(const_cast<SkImage*>(this));
107 } 107 }
108 108
109 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); 109 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
110 } 110 }
111 111
112 #if SK_SUPPORT_GPU
113
114 GrTexture* SkImage::getTexture() const {
115 return as_IB(this)->getTexture();
116 }
117
118 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->getTexture( )); }
119
120 GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const {
121 GrTexture* texture = as_IB(this)->getTexture();
122 if (texture) {
123 GrContext* context = texture->getContext();
124 if (context) {
125 if (flushPendingGrContextReads) {
126 context->prepareSurfaceForExternalRead(texture);
127 }
128 }
129 return texture->getTextureHandle();
130 }
131 return 0;
132 }
133
134 #else
135
136 GrTexture* SkImage::getTexture() const { return NULL; }
137
138 bool SkImage::isTextureBacked() const { return false; }
139
140 GrBackendObject SkImage::getTextureHandle(bool flushPendingGrContextReads) const { return 0; }
141
142 #endif
143
112 /////////////////////////////////////////////////////////////////////////////// 144 ///////////////////////////////////////////////////////////////////////////////
113 145
114 static bool raster_canvas_supports(const SkImageInfo& info) { 146 static bool raster_canvas_supports(const SkImageInfo& info) {
115 switch (info.colorType()) { 147 switch (info.colorType()) {
116 case kN32_SkColorType: 148 case kN32_SkColorType:
117 return kUnpremul_SkAlphaType != info.alphaType(); 149 return kUnpremul_SkAlphaType != info.alphaType();
118 case kRGB_565_SkColorType: 150 case kRGB_565_SkColorType:
119 return true; 151 return true;
120 case kAlpha_8_SkColorType: 152 case kAlpha_8_SkColorType:
121 return true; 153 return true;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 207
176 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph aType) { 208 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph aType) {
177 return NULL; 209 return NULL;
178 } 210 }
179 211
180 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 212 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
181 return NULL; 213 return NULL;
182 } 214 }
183 215
184 #endif 216 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698