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

Unified Diff: src/image/SkSurface.cpp

Issue 551463004: introduce Props to surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add new file Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkSurface_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkSurface.cpp
diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp
index 3a28e421a880df9ff6ae9962aa504c6bd63bb040..2d0ce7062fc0445bdd86820f57d2a243a55e1a35 100644
--- a/src/image/SkSurface.cpp
+++ b/src/image/SkSurface.cpp
@@ -9,14 +9,56 @@
#include "SkImagePriv.h"
#include "SkCanvas.h"
+#include "SkFontLCDConfig.h"
+static SkPixelGeometry compute_default_geometry() {
+ SkFontLCDConfig::LCDOrder order = SkFontLCDConfig::GetSubpixelOrder();
+ if (SkFontLCDConfig::kNONE_LCDOrder == order) {
+ return kUnknown_SkPixelGeometry;
+ } else {
+ // Bit0 is RGB(0), BGR(1)
+ // Bit1 is H(0), V(1)
+ const SkPixelGeometry gGeo[] = {
+ kRGB_H_SkPixelGeometry,
+ kBGR_H_SkPixelGeometry,
+ kRGB_V_SkPixelGeometry,
+ kBGR_V_SkPixelGeometry,
+ };
+ int index = 0;
+ if (SkFontLCDConfig::kBGR_LCDOrder == order) {
+ index |= 1;
+ }
+ if (SkFontLCDConfig::kVertical_LCDOrientation == SkFontLCDConfig::GetSubpixelOrientation()){
+ index |= 2;
+ }
+ return gGeo[index];
+ }
+}
+
+SkSurfaceProps::SkSurfaceProps() : fFlags(0), fPixelGeometry(kUnknown_SkPixelGeometry) {}
+
+SkSurfaceProps::SkSurfaceProps(InitType) : fFlags(0), fPixelGeometry(compute_default_geometry()) {}
+
+SkSurfaceProps::SkSurfaceProps(uint32_t flags, InitType)
+ : fFlags(flags)
+ , fPixelGeometry(compute_default_geometry())
+{}
+
+SkSurfaceProps::SkSurfaceProps(uint32_t flags, SkPixelGeometry pg)
+ : fFlags(flags), fPixelGeometry(pg)
+{}
+
///////////////////////////////////////////////////////////////////////////////
-SkSurface_Base::SkSurface_Base(int width, int height) : INHERITED(width, height) {
+SkSurface_Base::SkSurface_Base(int width, int height, const SkSurfaceProps* props)
+ : INHERITED(width, height, props)
+{
fCachedCanvas = NULL;
fCachedImage = NULL;
}
-SkSurface_Base::SkSurface_Base(const SkImageInfo& info) : INHERITED(info) {
+SkSurface_Base::SkSurface_Base(const SkImageInfo& info, const SkSurfaceProps* props)
+ : INHERITED(info, props)
+{
fCachedCanvas = NULL;
fCachedImage = NULL;
}
@@ -31,8 +73,7 @@ SkSurface_Base::~SkSurface_Base() {
SkSafeUnref(fCachedCanvas);
}
-void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y,
- const SkPaint* paint) {
+void SkSurface_Base::onDraw(SkCanvas* canvas, SkScalar x, SkScalar y, const SkPaint* paint) {
SkImage* image = this->newImageSnapshot();
if (image) {
image->draw(canvas, x, y, paint);
@@ -74,13 +115,17 @@ static SkSurface_Base* asSB(SkSurface* surface) {
///////////////////////////////////////////////////////////////////////////////
-SkSurface::SkSurface(int width, int height) : fWidth(width), fHeight(height) {
+SkSurface::SkSurface(int width, int height, const SkSurfaceProps* props)
+ : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(width), fHeight(height)
+{
SkASSERT(fWidth >= 0);
SkASSERT(fHeight >= 0);
fGenerationID = 0;
}
-SkSurface::SkSurface(const SkImageInfo& info) : fWidth(info.width()), fHeight(info.height()) {
+SkSurface::SkSurface(const SkImageInfo& info, const SkSurfaceProps* props)
+ : fProps(SkSurfacePropsCopyOrDefault(props)), fWidth(info.width()), fHeight(info.height())
+{
SkASSERT(fWidth >= 0);
SkASSERT(fHeight >= 0);
fGenerationID = 0;
@@ -119,3 +164,51 @@ void SkSurface::draw(SkCanvas* canvas, SkScalar x, SkScalar y,
const void* SkSurface::peekPixels(SkImageInfo* info, size_t* rowBytes) {
return this->getCanvas()->peekPixels(info, rowBytes);
}
+
+//////////////////////////////////////////////////////////////////////////////////////
+#ifdef SK_SUPPORT_LEGACY_TEXTRENDERMODE
+
+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);
+}
+
+SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget* target, TextRenderMode trm,
+ RenderTargetFlags flags) {
+ SkSurfaceProps props = make_props(trm);
+ return NewRenderTargetDirect(target, &props, flags);
+}
+
+SkSurface* SkSurface::NewRenderTarget(GrContext* gr, const SkImageInfo& info, int sampleCount,
+ TextRenderMode trm, RenderTargetFlags flags) {
+ SkSurfaceProps props = make_props(trm);
+ return NewRenderTarget(gr, info, sampleCount, &props, flags);
+}
+
+SkSurface* SkSurface::NewScratchRenderTarget(GrContext* gr, const SkImageInfo& info, int sampleCount,
+ TextRenderMode trm, RenderTargetFlags flags) {
+ SkSurfaceProps props = make_props(trm);
+ return NewScratchRenderTarget(gr, info, sampleCount, &props, flags);
+}
+
+#endif
+
+#if !SK_SUPPORT_GPU
+
+SkSurface* SkSurface::NewRenderTargetDirect(GrRenderTarget*, const SkSurfaceProps*) {
+ return NULL;
+}
+
+SkSurface* SkSurface::NewRenderTarget(GrContext*, const SkImageInfo&, int, const SkSurfaceProps*) {
+ return NULL;
+}
+
+SkSurface* SkSurface::NewScratchRenderTarget(GrContext*, const SkImageInfo&, int sampleCount,
+ const SkSurfaceProps*) {
+ return NULL;
+}
+
+#endif
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/image/SkSurface_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698