| OLD | NEW |
| 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 "GrSurface.h" | 8 #include "GrSurface.h" |
| 9 #include "GrSurfacePriv.h" | |
| 10 | 9 |
| 11 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 12 #include "SkGr.h" | 11 #include "SkGr.h" |
| 13 #include "SkImageEncoder.h" | 12 #include "SkImageEncoder.h" |
| 14 #include <stdio.h> | 13 #include <stdio.h> |
| 15 | 14 |
| 16 SkImageInfo GrSurface::info() const { | 15 SkImageInfo GrSurface::info() const { |
| 17 SkColorType colorType; | 16 SkColorType colorType; |
| 18 if (!GrPixelConfig2ColorType(this->config(), &colorType)) { | 17 if (!GrPixelConfig2ColorType(this->config(), &colorType)) { |
| 19 sk_throw(); | 18 sk_throw(); |
| 20 } | 19 } |
| 21 return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_S
kAlphaType); | 20 return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_S
kAlphaType); |
| 22 } | 21 } |
| 23 | 22 |
| 24 // TODO: This should probably be a non-member helper function. It might only be
needed in | |
| 25 // debug or developer builds. | |
| 26 bool GrSurface::savePixels(const char* filename) { | 23 bool GrSurface::savePixels(const char* filename) { |
| 27 SkBitmap bm; | 24 SkBitmap bm; |
| 28 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()))) { | 25 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()))) { |
| 29 return false; | 26 return false; |
| 30 } | 27 } |
| 31 | 28 |
| 32 bool result = this->readPixels(0, 0, this->width(), this->height(), kSkia888
8_GrPixelConfig, | 29 bool result = readPixels(0, 0, this->width(), this->height(), kSkia8888_GrPi
xelConfig, |
| 33 bm.getPixels()); | 30 bm.getPixels()); |
| 34 if (!result) { | 31 if (!result) { |
| 35 SkDebugf("------ failed to read pixels for %s\n", filename); | 32 SkDebugf("------ failed to read pixels for %s\n", filename); |
| 36 return false; | 33 return false; |
| 37 } | 34 } |
| 38 | 35 |
| 39 // remove any previous version of this file | 36 // remove any previous version of this file |
| 40 remove(filename); | 37 remove(filename); |
| 41 | 38 |
| 42 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { | 39 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { |
| 43 SkDebugf("------ failed to encode %s\n", filename); | 40 SkDebugf("------ failed to encode %s\n", filename); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 const GrTexture* thisTex = this->asTexture(); | 73 const GrTexture* thisTex = this->asTexture(); |
| 77 if (thisTex && thisTex->internalHasPendingIO()) { | 74 if (thisTex && thisTex->internalHasPendingIO()) { |
| 78 return true; | 75 return true; |
| 79 } | 76 } |
| 80 const GrRenderTarget* thisRT = this->asRenderTarget(); | 77 const GrRenderTarget* thisRT = this->asRenderTarget(); |
| 81 if (thisRT && thisRT->internalHasPendingIO()) { | 78 if (thisRT && thisRT->internalHasPendingIO()) { |
| 82 return true; | 79 return true; |
| 83 } | 80 } |
| 84 return false; | 81 return false; |
| 85 } | 82 } |
| 86 | |
| 87 bool GrSurface::isSameAs(const GrSurface* other) const { | |
| 88 const GrRenderTarget* thisRT = this->asRenderTarget(); | |
| 89 if (thisRT) { | |
| 90 return thisRT == other->asRenderTarget(); | |
| 91 } else { | |
| 92 const GrTexture* thisTex = this->asTexture(); | |
| 93 SkASSERT(thisTex); // We must be one or the other | |
| 94 return thisTex == other->asTexture(); | |
| 95 } | |
| 96 } | |
| OLD | NEW |