| 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 #include "GrSurfacePriv.h" |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkGr.h" | 12 #include "SkGr.h" |
| 13 #include "SkImageEncoder.h" | |
| 14 #include <stdio.h> | |
| 15 | 13 |
| 16 bool GrSurface::writePixels(int left, int top, int width, int height, | 14 bool GrSurface::writePixels(int left, int top, int width, int height, |
| 17 GrPixelConfig config, const void* buffer, size_t row
Bytes, | 15 GrPixelConfig config, const void* buffer, size_t row
Bytes, |
| 18 uint32_t pixelOpsFlags) { | 16 uint32_t pixelOpsFlags) { |
| 19 // go through context so that all necessary flushing occurs | 17 // go through context so that all necessary flushing occurs |
| 20 GrContext* context = this->getContext(); | 18 GrContext* context = this->getContext(); |
| 21 if (NULL == context) { | 19 if (NULL == context) { |
| 22 return false; | 20 return false; |
| 23 } | 21 } |
| 24 return context->writeSurfacePixels(this, left, top, width, height, config, b
uffer, rowBytes, | 22 return context->writeSurfacePixels(this, left, top, width, height, config, b
uffer, rowBytes, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 42 } | 40 } |
| 43 | 41 |
| 44 SkImageInfo GrSurface::info() const { | 42 SkImageInfo GrSurface::info() const { |
| 45 SkColorType colorType; | 43 SkColorType colorType; |
| 46 if (!GrPixelConfig2ColorType(this->config(), &colorType)) { | 44 if (!GrPixelConfig2ColorType(this->config(), &colorType)) { |
| 47 sk_throw(); | 45 sk_throw(); |
| 48 } | 46 } |
| 49 return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_S
kAlphaType); | 47 return SkImageInfo::Make(this->width(), this->height(), colorType, kPremul_S
kAlphaType); |
| 50 } | 48 } |
| 51 | 49 |
| 52 // TODO: This should probably be a non-member helper function. It might only be
needed in | |
| 53 // debug or developer builds. | |
| 54 bool GrSurface::savePixels(const char* filename) { | |
| 55 SkBitmap bm; | |
| 56 if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(this->width(), this->heigh
t()))) { | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 bool result = this->readPixels(0, 0, this->width(), this->height(), kSkia888
8_GrPixelConfig, | |
| 61 bm.getPixels()); | |
| 62 if (!result) { | |
| 63 SkDebugf("------ failed to read pixels for %s\n", filename); | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 67 // remove any previous version of this file | |
| 68 remove(filename); | |
| 69 | |
| 70 if (!SkImageEncoder::EncodeFile(filename, bm, SkImageEncoder::kPNG_Type, 100
)) { | |
| 71 SkDebugf("------ failed to encode %s\n", filename); | |
| 72 remove(filename); // remove any partial file | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 return true; | |
| 77 } | |
| 78 | 50 |
| 79 void GrSurface::flushWrites() { | 51 void GrSurface::flushWrites() { |
| 80 if (!this->wasDestroyed()) { | 52 if (!this->wasDestroyed()) { |
| 81 this->getContext()->flushSurfaceWrites(this); | 53 this->getContext()->flushSurfaceWrites(this); |
| 82 } | 54 } |
| 83 } | 55 } |
| 84 | 56 |
| 85 bool GrSurface::hasPendingRead() const { | 57 bool GrSurface::hasPendingRead() const { |
| 86 const GrTexture* thisTex = this->asTexture(); | 58 const GrTexture* thisTex = this->asTexture(); |
| 87 if (thisTex && thisTex->internalHasPendingRead()) { | 59 if (thisTex && thisTex->internalHasPendingRead()) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 bool GrSurface::isSameAs(const GrSurface* other) const { | 93 bool GrSurface::isSameAs(const GrSurface* other) const { |
| 122 const GrRenderTarget* thisRT = this->asRenderTarget(); | 94 const GrRenderTarget* thisRT = this->asRenderTarget(); |
| 123 if (thisRT) { | 95 if (thisRT) { |
| 124 return thisRT == other->asRenderTarget(); | 96 return thisRT == other->asRenderTarget(); |
| 125 } else { | 97 } else { |
| 126 const GrTexture* thisTex = this->asTexture(); | 98 const GrTexture* thisTex = this->asTexture(); |
| 127 SkASSERT(thisTex); // We must be one or the other | 99 SkASSERT(thisTex); // We must be one or the other |
| 128 return thisTex == other->asTexture(); | 100 return thisTex == other->asTexture(); |
| 129 } | 101 } |
| 130 } | 102 } |
| OLD | NEW |