SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : INHERITED(bitmap.info(), SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) , fBitmap(bitmap) { SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr)); fBitmap.lockPixels(); }
static SkSurfaceProps make_props(SkSurface::TextRenderMode trm) { uint32_t propsFlags = 0; if (SkSurface::kDistanceField_TextRenderMode == trm) { propsFlags |= SkSurfaceProps::kUseDistanceFieldFonts_Flag; } return SkSurfaceProps(propsFlags, SkSurfaceProps::kLegacyFontHost_InitType); }
void SkWindow::setColorType(SkColorType ct, SkColorProfileType pt) { const SkImageInfo& info = fBitmap.info(); this->resize(SkImageInfo::Make(info.width(), info.height(), ct, kPremul_SkAlphaType, pt)); // Set the global flag that enables or disables "legacy" mode, depending on our format. // With sRGB 32-bit or linear FP 16, we turn on gamma-correct handling of inputs: SkSurfaceProps props = this->getSurfaceProps(); uint32_t flags = (props.flags() & ~SkSurfaceProps::kAllowSRGBInputs_Flag) | (SkColorAndProfileAreGammaCorrect(ct, pt) ? SkSurfaceProps::kAllowSRGBInputs_Flag : 0); this->setSurfaceProps(SkSurfaceProps(flags, props.pixelGeometry())); }
bool SkPictureImageGenerator::onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) { if (ctable || ctableCount) { return false; } SkBitmap bitmap; if (!bitmap.installPixels(info, pixels, rowBytes)) { return false; } bitmap.eraseColor(SK_ColorTRANSPARENT); SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); canvas.drawPicture(fPicture.get(), &fMatrix, fPaint.getMaybeNull()); return true; }
SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer) : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry)) , fWriter(writer) , fResourceBucket(SkNEW(ResourceBucket)) { SkASSERT(writer); fLegacyBitmap.setInfo(SkImageInfo::MakeUnknown(size.width(), size.height())); fWriter->writeHeader(); // The root <svg> tag gets closed by the destructor. fRootElement.reset(SkNEW_ARGS(AutoElement, ("svg", fWriter))); fRootElement->addAttribute("xmlns", "http://www.w3.org/2000/svg"); fRootElement->addAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); fRootElement->addAttribute("width", size.width()); fRootElement->addAttribute("height", size.height()); }
bool SkPictureImageGenerator::onGenerateScaledPixels(const SkISize& scaledSize, const SkIPoint& scaledOrigin, const SkPixmap& scaledPixels) { int w = scaledSize.width(); int h = scaledSize.height(); const SkScalar scaleX = SkIntToScalar(w) / this->getInfo().width(); const SkScalar scaleY = SkIntToScalar(h) / this->getInfo().height(); SkMatrix matrix = SkMatrix::MakeScale(scaleX, scaleY); matrix.postTranslate(-SkIntToScalar(scaledOrigin.x()), -SkIntToScalar(scaledOrigin.y())); SkBitmap bitmap; if (!bitmap.installPixels(scaledPixels)) { return false; } bitmap.eraseColor(SK_ColorTRANSPARENT); SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); matrix.preConcat(fMatrix); canvas.drawPicture(fPicture, &matrix, fPaint.getMaybeNull()); return true; }
SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& info) { return Create(info, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)); }
SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap) : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)) , fBitmap(bitmap) { SkASSERT(valid_for_bitmap_device(bitmap.info(), NULL)); }
DEF_GPUTEST(ReadWriteAlpha, reporter, factory) { for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { GrContextFactory::GLContextType glType = static_cast<GrContextFactory::GLContextType>(type); if (!GrContextFactory::IsRenderingGLContext(glType)) { continue; } GrContext* context = factory->get(glType); if (NULL == context) { continue; } unsigned char textureData[X_SIZE][Y_SIZE]; memset(textureData, 0, X_SIZE * Y_SIZE); GrTextureDesc desc; // let Skia know we will be using this texture as a render target desc.fFlags = kRenderTarget_GrTextureFlagBit; // it is a single channel texture desc.fConfig = kAlpha_8_GrPixelConfig; desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; // We are initializing the texture with zeros here GrTexture* texture = context->createUncachedTexture(desc, textureData, 0); if (!texture) { return; } SkAutoTUnref<GrTexture> au(texture); // create a distinctive texture for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { textureData[x][y] = x*Y_SIZE+y; } } // upload the texture texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, textureData, 0); unsigned char readback[X_SIZE][Y_SIZE]; // clear readback to something non-zero so we can detect readback failures memset(readback, 0x1, X_SIZE * Y_SIZE); // read the texture back texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback, 0); // make sure the original & read back versions match bool match = true; for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { if (textureData[x][y] != readback[x][y]) { match = false; } } } REPORTER_ASSERT(reporter, match); // Now try writing on the single channel texture SkAutoTUnref<SkBaseDevice> device(SkGpuDevice::Create(texture->asRenderTarget(), SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))); SkCanvas canvas(device); SkPaint paint; const SkRect rect = SkRect::MakeLTRB(-10, -10, X_SIZE + 10, Y_SIZE + 10); paint.setColor(SK_ColorWHITE); canvas.drawRect(rect, paint); texture->readPixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig, readback, 0); match = true; for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { if (0xFF != readback[x][y]) { match = false; } } } REPORTER_ASSERT(reporter, match); } }
static SkSurfaceProps copy_or_safe_defaults(const SkSurfaceProps* props) { return props ? *props : SkSurfaceProps(0, kUnknown_SkPixelGeometry); }
FakeDevice() : INHERITED(make_bm(100, 100), SkSurfaceProps(0, kUnknown_SkPixelGeometry)) { }