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